Stable Diffusion 3 Image To Image API Introduction
Generate an image using a Stable Diffusion 3 model.Generating with a prompt and an image.
Credits
The service uses 8 credits per successful result. You will not be charged for failed results.
Example Request and Response
API Documentation
API Endpoint | Method |
---|---|
/api/generate/sdv3/imageToImage | POST |
Request Header
Parameter | Description |
---|---|
Authentication | Use your API key to authentication requests to this App. |
Request Body
The request should include a FormData object in the body with the following parameters:
Parameter | Type | Required | Description |
---|---|---|---|
image | File | Yes | Image used to initialize the diffusion process, in lieu of random noise. |
prompt | string | Yes | The text description or prompt used to generate the image. |
width | int | Yes | The desired pixel width for the generated image should be between 320 and 1536 pixels, in an increment divisible by 64. |
height | int | Yes | The desired pixel height for the generated image should be between 320 and 1536 pixels, in an increment divisible by 64. |
strength | int | Yes | Range: [0, 1] This parameter controls how much influence the image parameter has on the generated image. A value of 0 would yield an image that is identical to the input. A value of 1 would be as if you passed in no image at all. |
model | string | No | Enum: sd3-large sd3-large-turbo sd3-medium Default: sd3-large The model to use for generation. |
seed | init | No | Random noise seed (omit this option or use 0 for a random seed). |
negative_prompt | string | No | Keywords of what you do not wish to see in the output image. This is an advanced feature.This parameter does not work with sd3-large-turbo. |
Response Body
The response should include a JSON object in the body with the following parameters:
Parameter | Type | Description |
---|---|---|
code | int | Status Code, 0 for success callback, -1 for failure callback |
message | string | Callback message, 'success' for success, failure reason for failure |
data | object | Image Details |
Image Details
Parameter | Type | Description |
---|---|---|
image | string | Return the base64 encoded image of the generated picture. |
seed | int | The seed used as random noise for this generation. |
Example Request
import requests
import base64
import os
image_path = './init_image.png'
with open(image_path, 'rb') as file:
image_data = file.read()
payload = {
'strength': 0.35,
'prompt': 'black hair',
}
files = {'image': ('init_image.png', image_data)}
url = "https://www.aithriving.com/api/generate/sdv3/imageToImage"
headers = {'Authorization': "your-auth-token"}
response = requests.post(url, data=payload, files=files, headers=headers)
response_json = response.json()
if response_json.get('code') == 0:
image_base64 = response_json['data']['image']
image_bytes = base64.b64decode(image_base64)
with open('./result.png', 'wb') as file:
file.write(image_bytes)
Example Response
{
"code": 0,
"message": "success",
"data": {
"image": "base64 encoded image data",
"seed": 1050625087
}
}