Skip to main content

Image to Image Endpoint

Overview

Stable Diffusion V3 APIs Image2Image API generates an image from an image. Pass the appropriate request parameters to the endpoint to generate image from an image.

This endpoint generates and returns an image from an image passed with its URL in the request.

Together with the image you can add your description of the desired result by passing prompt and negative prompt.

Image to image endpoint result

Request

--request POST 'https://stablediffusionapi.com/api/v3/img2img' \

Make a POST request to https://stablediffusionapi.com/api/v3/img2img endpoint and pass the required parameters as a request body to the endpoint.

Watch the how-to video to see it in action.

Body Attributes

ParameterDescription
keyYour API Key used for request authorization
promptText prompt with description of the things you want in the image to be generated
negative_promptItems you don't want in the image
init_imageLink to the Initial Image
widthMax Height: Width: 1024x1024
heightMax Height: Width: 1024x1024
samplesNumber of images to be returned in response. The maximum value is 4.
num_inference_stepsNumber of denoising steps. Available values: 21, 31, 41, 51.
safety_checkerA checker for NSFW images. If such an image is detected, it will be replaced by a blank image.
enhance_promptEnhance prompts for better results; default: yes, options: yes/no
guidance_scaleScale for classifier-free guidance (minimum: 1; maximum: 20)
strengthPrompt strength when using init image. 1.0 corresponds to full destruction of information in the init image.
seedSeed is used to reproduce results, same seed will give you same image in return again. Pass null for a random number.
base64Get response as base64 string, default: "no", options: yes/no
webhookSet an URL to get a POST API call once the image generation is complete.
track_idThis ID is returned in the response to the webhook API call. This will be used to identify the webhook request.

Example

Body

Body
{
"key": "",
"prompt": "a cat sitting on a bench",
"negative_prompt": null,
"init_image": "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.7,
"seed": null,
"base64": "no",
"webhook": null,
"track_id": null
}

Request

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
"key": "",
"prompt": "a cat sitting on a bench",
"negative_prompt": null,
"init_image": "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.7,
"base64": "no",
"seed": null,
"webhook": null,
"track_id": null
});

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};

fetch("https://stablediffusionapi.com/api/v3/img2img", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

Response

Example Response
{
"status": "success",
"generationTime": 2.920767068862915,
"id": 302455,
"output": [
"https://d1okzptojspljx.cloudfront.net/generations/05c3260d-6a2e-4aa5-82f0-e952f2a5fa10-0.png"
],
"meta": {
"H": 512,
"W": 512,
"enable_attention_slicing": "true",
"file_prefix": "05c3260d-6a2e-4aa5-82f0-e952f2a5fa10",
"guidance_scale": 7.5,
"model": "runwayml/stable-diffusion-v1-5",
"n_samples": 1,
"negative_prompt": "((out of frame)), ((extra fingers)), mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), (((tiling))), ((naked)), ((tile)), ((fleshpile)), ((ugly)), (((abstract))), blurry, ((bad anatomy)), ((bad proportions)), ((extra limbs)), cloned face, (((skinny))), glitchy, ((extra breasts)), ((double torso)), ((extra arms)), ((extra hands)), ((mangled fingers)), ((missing breasts)), (missing lips), ((ugly face)), ((fat)), ((extra legs)), anime",
"outdir": "out",
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner)), blue eyes, shaved side haircut, hyper detail, cinematic lighting, magic neon, dark red city, Canon EOS R3, nikon, f/1.4, ISO 200, 1/160s, 8K, RAW, unedited, symmetrical balance, in-frame, 8K",
"revision": "fp16",
"safety_checker": "none",
"seed": 1793745243,
"steps": 20,
"vae": "stabilityai/sd-vae-ft-mse"
}
}