Basic Image To Image API Introduction
Generate images using SD1.6, Produce an image from an existing image using a text prompt.
Credits
The service uses 0.4-2 credits per successful result. You will not be charged for failed results.
Example Request and Response
API Documentation
API Endpoint | Method |
---|---|
/api/generate/basic/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 |
---|---|---|---|
init_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. |
image_strength | number | No | Range: [0, 1] Default: 0.35 How much influence the init_image has on the diffusion process. Values close to 1 will yield images very similar to the init_image while values close to 0 will yield images wildly different than the init_image. |
cfg_scale | int | No | Range: [0,35] Default: 7 How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt). |
clip_guidance_preset | string | No | Enum: FAST_BLUE FAST_GREEN NONE SIMPLE SLOW SLOWER SLOWEST |
sampler | string | No | Enum: DDIM DDPM K_DPMPP_2M K_DPMPP_2S_ANCESTRAL K_DPM_2 K_DPM_2_ANCESTRAL K_EULER K_EULER_ANCESTRAL K_HEUN K_LMS Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you. |
seed | init | No | Random noise seed (omit this option or use 0 for a random seed). |
steps | init | No | Range: [10, 50] Default: 30 Number of diffusion steps to run. |
style_preset | string | No | Enum: 3d-model analog-film anime cinematic comic-book digital-art enhance fantasy-art isometric line-art low-poly modeling-compound neon-punk origami photographic pixel-art tile-texture Pass in a style preset to guide the image model towards a particular style. This list of style presets is subject to change. |
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 os
import requests
data = {
'image_strength': 0.35,
'prompt': 'black hair',
'cfg_scale': 7,
'steps': 20,
}
with open('./init_image.png', 'rb') as f:
image_data = f.read()
files = {'init_image': ('init_image.png', image_data)}
url = "https://www.aithriving.com/api/generate/basic/imageToImage"
headers = {'Authorization': "your-auth-token"}
response = requests.post(url, data=data, files=files, headers=headers)
response_json = response.json()
if response_json.get('code') == 0:
image_base64 = response_json['data']['image']
image_data = base64.b64decode(image_base64)
with open('./result.png', 'wb') as f:
f.write(image_data)
Example Response
{
"code": 0,
"message": "success",
"data": {
"image": "base64 encoded image data",
"seed": 1050625087
}
}