Skip to main content

img2img

2img API

Basic minimum workflow

Call Get Resource Upload Address, and upload the image to the returned address, get the resource id

请求参数

{
"request_id": "unique_key",
"stages": [
{
"type": "INPUT_INITIALIZE",
"inputInitialize": {
"image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
"count": 2
}
},
{
"type": "DIFFUSION",
"diffusion": {
"width": 512,
"height": 512,
"prompts": [
{
"text": "1girl"
}
],
"sampler": "DPM++ 2M Karras",
"sdVae": "Automatic",
"steps": 15,
"sd_model": "600423083519508503",
"clip_skip": 2,
"cfg_scale": 7
}
}
]
}

Adetailer

images after detail directly without Diffusion

caution

Do not perform the Diffusion operation, therefore inputInitialize.count can only be 1

Although not using Diffusion, image_to_adetailer still needs parameters with the original image diffusion

{
"request_id": "unique_key",
"stages": [
{
"type": "INPUT_INITIALIZE",
"inputInitialize": {
"image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
"count": 1
}
},
{
"type": "IMAGE_TO_ADETAILER",
"image_to_adetailer": {
"args": [
{
"ad_model": "face_yolov8s.pt",
"ad_confidence": 0.7,
"ad_dilate_erode": 4,
"ad_denoising_strength": 0.4,
"ad_inpaint_only_masked": true,
"ad_inpaint_only_masked_padding": 32
}
],
"diffusion": {
"width": 512,
"height": 512,
"prompts": [
{
"text": "1girl"
}
],
"sampler": "DPM++ 2M Karras",
"sdVae": "Automatic",
"steps": 15,
"sd_model": "600423083519508503",
"clip_skip": 2,
"cfg_scale": 7
}
}
}
]
}

Image To Adetailer

{
"request_id": "unique_key",
"stages": [
{
"type": "INPUT_INITIALIZE",
"inputInitialize": {
"image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
"count": 2
}
},
{
"type": "DIFFUSION",
"diffusion": {
"width": 512,
"height": 512,
"prompts": [
{
"text": "1girl"
}
],
"sampler": "DPM++ 2M Karras",
"sdVae": "Automatic",
"steps": 15,
"sd_model": "600423083519508503",
"clip_skip": 2,
"cfg_scale": 7
}
},
{
"type": "IMAGE_TO_ADETAILER",
"image_to_adetailer": {
"args": [
{
"ad_model": "face_yolov8s.pt",
"ad_confidence": 0.7,
"ad_dilate_erode": 4,
"ad_denoising_strength": 0.4,
"ad_inpaint_only_masked": true,
"ad_inpaint_only_masked_padding": 32
}
]
}
}
]
}

Upscaler

Upscale the image directly without Diffusion

caution

Do not perform the Diffusion operation, therefore inputInitialize.count can only be 1

Although not using Diffusion, image_to_upscaler still requires parameters with the original image diffusion

{
"request_id": "unique_key",
"stages": [
{
"type": "INPUT_INITIALIZE",
"inputInitialize": {
"image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
"count": 1
}
},
{
"type": "IMAGE_TO_UPSCALER",
"image_to_upscaler": {
"hr_upscaler": "Latent",
"hr_scale": 2,
"hr_second_pass_steps": 10,
"denoising_strength": 0.3,
"diffusion": {
"width": 512,
"height": 512,
"prompts": [
{
"text": "1girl"
}
],
"sampler": "DPM++ 2M Karras",
"sdVae": "Automatic",
"steps": 15,
"sd_model": "600423083519508503",
"clip_skip": 2,
"cfg_scale": 7
}
}
}
]
}

Image to Upscaler

caution

When using Image to Upscaler, image_to_upscaler.hr_upscaler prohibits the use of late, as late only takes effect during the Diffusion phase of txt2img

{
"request_id": "unique_key",
"stages": [
{
"type": "INPUT_INITIALIZE",
"inputInitialize": {
"image_resource_id": "f204c24a-52dc-4cf4-930a-9b8f73969414",
"count": 2
}
},
{
"type": "DIFFUSION",
"diffusion": {
"width": 512,
"height": 512,
"prompts": [
{
"text": "1girl"
}
],
"sampler": "DPM++ 2M Karras",
"sdVae": "Automatic",
"steps": 15,
"sd_model": "600423083519508503", //checkpoint
"clip_skip": 2,
"cfg_scale": 7
}
},
{
"type": "IMAGE_TO_UPSCALER",
"image_to_upscaler": {
"hr_upscaler": "4x-UltraSharp",
"hr_scale": 2,
"hr_second_pass_steps": 10,
"denoising_strength": 0.3
}
}
]
}

Inpaint

Perform inpainting on an image directly without diffusion

First, let's generate an image to be processed.

Request Body:

{
"requestId": "unique_key",
"stages": [
{
"type": "INPUT_INITIALIZE",
"inputInitialize": { "seed": "933011881", "count": 1 }
},
{
"type": "DIFFUSION",
"diffusion": {
"width": 512,
"height": 768,
"prompts": [
{ "text": "wide shot" },
{ "text": "(depth of field)" },
{ "text": "global illumination" },
{ "text": "soft shadows" },
{ "text": "grand scene" },
{ "text": "backlight" },
{ "text": "lens flare" },
{ "text": "((colorful refraction))" },
{ "text": "((cinematic lighting))" },
{ "text": "in the market" },
{ "text": "looking outside" },
{ "text": "with butterfly" },
{ "text": "1girl with lightblue long hair and blue aqua eyes" },
{ "text": "hair flowers" },
{ "text": "hime cut" },
{ "text": "sunlight" },
{ "text": "blurry background" },
{ "text": "blurry" },
{ "text": "White Dress" },
{ "text": "full of flowers" },
{ "text": "light bule butterfly" },
{ "text": " from side" },
{ "text": "floating hair" }
],
"negativePrompts": [
{ "text": " (worst quality" },
{ "text": " low quality:1.4)" },
{ "text": " negative_hand Negative Embedding" },
{ "text": "verybadimagenegative_v1.3" },
{}
],
"sdModel": "681693017352010007",
"sdVae": "None",
"sampler": "DPM++ 3M SDE Karras",
"steps": 25,
"cfgScale": 5,
"clipSkip": 2,
"denoisingStrength": 0.4,
"lora": {}
}
},
{
"type": "IMAGE_TO_UPSCALER",
"imageToUpscaler": {
"hrUpscaler": "4x-AnimeSharp",
"hrResizeX": 1536,
"hrResizeY": 2304,
"hrSecondPassSteps": 10,
"denoisingStrength": 0.4
}
}
]
}
tip

Please remember to replace the 'requestId' in the request with your own unique ID.

We have obtained an image

Then we need a mask image

You can use some image editing tools to draw a black background image and paint the parts that need to be redrawn in white.

tip

Remember that the mask image format should be JPEG, and the resolution of the mask image should be exactly the same as that of the original image.

Let's do a partial redraw of the face and get a masked image that has the face region selected.

Perform inpainting

Our goal is to redraw the face with a crying expression, red pupils, and eyes. The structure of inpainting is:

{
"imageToInpaint": {
"resizeMode": "JUST_RESIZE",
"maskImageResourceId": "48203af7-6b07-4f1c-8506-f3f545613653",
"maskBlur": 4,
"inpaintingFill": "ORIGINAL",
"inpaintFullRes": true,
"inpaintFullResPadding": 32,
"diffusion": {
"width": 512,
"height": 768,
"prompts": [
{
"text": "crying"
},
{
"text": " (red eyes:1.5)"
}
],
"negativePrompts": [
{
"text": " (worst quality, low quality:1.4)"
},
{
"text": " negative_hand Negative Embedding"
},
{
"text": "verybadimagenegative_v1.3"
},
{}
],
"sdModel": "681693017352010007",
"sdVae": "None",
"sampler": "DPM++ 3M SDE Karras",
"steps": 25,
"cfgScale": 5,
"clipSkip": 2,
"denoisingStrength": 0.4,
"lora": {}
}
}
}

Complete request example:

{
"requestId": "685205102316761513",
"stages": [
{
"type": "INPUT_INITIALIZE",
"inputInitialize": {
"seed": "-1",
"imageResourceId": "67f8de0b-4949-4f88-abb4-cf57b16459da",
"count": 1
}
},
{
"type": "IMAGE_TO_INPAINT",
"imageToInpaint": {
"resizeMode": "JUST_RESIZE",
"maskImageResourceId": "48203af7-6b07-4f1c-8506-f3f545613653",
"maskBlur": 4,
"inpaintingFill": "ORIGINAL",
"inpaintFullRes": true,
"inpaintFullResPadding": 32,
"diffusion": {
"width": 512,
"height": 768,
"prompts": [{ "text": "crying" }, { "text": " (red eyes:1.5)" }],
"negativePrompts": [
{ "text": " (worst quality" },
{ "text": " low quality:1.4)" },
{ "text": " negative_hand Negative Embedding" },
{ "text": "verybadimagenegative_v1.3" },
{}
],
"sdModel": "681693017352010007",
"sdVae": "None",
"sampler": "DPM++ 3M SDE Karras",
"steps": 25,
"cfgScale": 5,
"clipSkip": 2,
"denoisingStrength": 0.4,
"lora": {}
}
}
}
]
}

The final resulting image is as follows: