Skip to content
Stable Diffusion API

Stable Diffusion Text2Img API — Text-to-Image Documentation

Stable Diffusion text-to-image (text2img) API documentation. POST a prompt to generate images with SD 1.5, SDXL, Flux, and 1,000+ community models. cURL, Python, Node samples.

Stable Diffusion Text-to-Image (Text2Img) API

The Stable Diffusion text2img API generates an image from a text prompt. Send a POST request with your prompt and parameters; the endpoint returns a URL to the generated image. Works with Stable Diffusion 1.5, SDXL, Flux, and 1,000+ community models out of the box.

This is the official documentation for the text2img endpoint on the Stable Diffusion API by ModelsLab.


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

Make a POST request to https://stablediffusionapi.com/api/v3/text2img endpoint and pass the required parameters as request body to the endpoint. Below are description of the parameters needed.

Click HERE to watch a how to video.

key : Your API Key
prompt : Your Prompt
samples : number of images you want in response
negative_prompt : Items you don’t want in the image
width : Width of output image. Maximum size is 1024x768 or 768x1024 because of memory limits
height : Height of output image. Maximum size is 1024x768 or 768x1024 because of memory limits
prompt_strength : Prompt strength when using init image. 1.0 corresponds to full destruction of information in init image
num_inference_steps : Number of denoising steps (minimum: 1; maximum: 50)
guidance_scale : Scale for classifier-free guidance (minimum: 1; maximum: 20)
enhance_prompt : Enhance prompts for better results, default : yes, option : yes/no
seed : Random seed. Leave blank to randomize the seed
webhook : webhook to call when image generation is completed
track_id : tracking id to track this api call

Request Body and Response Example

Body Raw
{
 "key": "",
 "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",
 "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",
 "width": "512",
 "height": "512",
 "samples": "1",
 "num_inference_steps": "20",
 "seed": null,
 "guidance_scale": 7.5,
"safety_checker":"yes",
 "webhook": null,
 "track_id": null
}
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"
 }
}