Download OpenAPI specification:Download
Welcome to the Stability.ai REST API!
Your DreamStudio API key will be required for authentication: How to find your API key
API operations use the following versioning scheme:
/v*
interface is stable and ready for production workloads/v*beta*
: interface is stable, preparing for production release/v*alpha*
: under development and the interface is subject to changeNOTE: The v1alpha and v1beta endpoints from the developer preview are still available, but they will disabled on May 1st, 2023. Please migrate to the v1 endpoints as soon as possible.
If you have feedback or encounter any issues with the API, please reach out:
Get information about the account associated with the provided API key
import os import requests api_host = os.getenv('API_HOST', 'https://api.stability.ai') url = f"{api_host}/v1/user/account" api_key = os.getenv("STABILITY_API_KEY") if api_key is None: raise Exception("Missing Stability API key.") response = requests.get(url, headers={ "Authorization": f"Bearer {api_key}" }) if response.status_code != 200: raise Exception("Non-200 response: " + str(response.text)) # Do something with the payload... payload = response.json()
{- "id": "user-1234",
- "organizations": [
- {
- "id": "org-5678",
- "name": "Another Organization",
- "role": "MEMBER",
- "is_default": true
}, - {
- "id": "org-1234",
- "name": "My Organization",
- "role": "MEMBER",
- "is_default": false
}
],
}
Get the credit balance of the account/organization associated with the API key
Organization | string Example: org-123456 Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used. |
import os import requests api_host = os.getenv('API_HOST', 'https://api.stability.ai') url = f"{api_host}/v1/user/balance" api_key = os.getenv("STABILITY_API_KEY") if api_key is None: raise Exception("Missing Stability API key.") response = requests.get(url, headers={ "Authorization": f"Bearer {api_key}" }) if response.status_code != 200: raise Exception("Non-200 response: " + str(response.text)) # Do something with the payload... payload = response.json()
{- "credits": 0.6336833840314097
}
List all engines available to your organization/user
Organization | string Example: org-123456 Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used. |
import os import requests api_host = os.getenv('API_HOST', 'https://api.stability.ai') url = f"{api_host}/v1/engines/list" api_key = os.getenv("STABILITY_API_KEY") if api_key is None: raise Exception("Missing Stability API key.") response = requests.get(url, headers={ "Authorization": f"Bearer {api_key}" }) if response.status_code != 200: raise Exception("Non-200 response: " + str(response.text)) # Do something with the payload... payload = response.json()
[- {
- "description": "Stability-AI Stable Diffusion v1.5",
- "id": "stable-diffusion-v1-5",
- "name": "Stable Diffusion v1.5",
- "type": "PICTURE"
}, - {
- "description": "Stability-AI Stable Diffusion v2.1",
- "id": "stable-diffusion-512-v2-1",
- "name": "Stable Diffusion v2.1",
- "type": "PICTURE"
}, - {
- "description": "Stability-AI Stable Diffusion 768 v2.1",
- "id": "stable-diffusion-768-v2-1",
- "name": "Stable Diffusion v2.1-768",
- "type": "PICTURE"
}
]
Generate a new image from a text prompt
engine_id required | string Example: stable-diffusion-v1-5 |
Accept | string Default: application/json Enum: "application/json" "image/png" The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image. |
Organization | string Example: org-123456 Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used. |
height | integer (DiffuseImageHeight) multiple of 64 >= 128 Default: 512 Height of the image in pixels. Must be in increments of 64 and pass the following validation:
|
width | integer (DiffuseImageWidth) multiple of 64 >= 128 Default: 512 Width of the image in pixels. Must be in increments of 64 and pass the following validation:
|
required | Array of objects (TextPrompts) non-empty An array of text prompts to use for generation. Given a text prompt with the text "text_prompts": [ { "text": "A lighthouse on a cliff", "weight": 0.5 } ] |
cfg_scale | number (CfgScale) [ 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 (ClipGuidancePreset) Default: "NONE" Enum: "FAST_BLUE" "FAST_GREEN" "NONE" "SIMPLE" "SLOW" "SLOWER" "SLOWEST" |
sampler | string (Sampler) 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. |
samples | integer (Samples) [ 1 .. 10 ] Default: 1 Number of images to generate |
seed | integer (Seed) [ 0 .. 4294967295 ] Default: 0 Random noise seed (omit this option or use |
steps | integer (Steps) [ 10 .. 150 ] Default: 50 Number of diffusion steps to run |
{- "cfg_scale": 7,
- "clip_guidance_preset": "FAST_BLUE",
- "height": 512,
- "width": 512,
- "sampler": "K_DPM_2_ANCESTRAL",
- "samples": 1,
- "steps": 75,
- "text_prompts": [
- {
- "text": "A lighthouse on a cliff",
- "weight": 1
}
]
}
[- [
- {
- "base64": "...very long string...",
- "finishReason": "SUCCESS",
- "seed": 1050625087
}, - {
- "base64": "...very long string...",
- "finishReason": "CONTENT_FILTERED",
- "seed": 1229191277
}
]
]
Modify an image based on a text prompt
engine_id required | string Example: stable-diffusion-v1-5 |
Accept | string Default: application/json Enum: "application/json" "image/png" The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image. |
Organization | string Example: org-123456 Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used. |
required | Array of objects (TextPrompts) non-empty An array of text prompts to use for generation. Due to how arrays are represented in Given a text prompt with the text
To add another prompt to that request simply provide the values under a new
|
init_image required | string <binary> (InitImage) Image used to initialize the diffusion process, in lieu of random noise. |
init_image_mode | string (InitImageMode) Default: "IMAGE_STRENGTH" Whether to use |
image_strength | number <float> (InitImageStrength) [ 0 .. 1 ] Default: 0.35 How much influence the |
cfg_scale | number (CfgScale) [ 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 (ClipGuidancePreset) Default: "NONE" Enum: "FAST_BLUE" "FAST_GREEN" "NONE" "SIMPLE" "SLOW" "SLOWER" "SLOWEST" |
sampler | string (Sampler) 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. |
samples | integer (Samples) [ 1 .. 10 ] Default: 1 Number of images to generate |
seed | integer (Seed) [ 0 .. 4294967295 ] Default: 0 Random noise seed (omit this option or use |
steps | integer (Steps) [ 10 .. 150 ] Default: 50 Number of diffusion steps to run |
Request using 35% image_strength
{ "image_strength": 0.35, "init_image_mode": "IMAGE_STRENGTH", "init_image": "<image binary>", "text_prompts[0][text]": "A dog space commander", "text_prompts[0][weight]": 1, "cfg_scale": 7, "clip_guidance_preset": "FAST_BLUE", "sampler": "K_DPM_2_ANCESTRAL", "samples": 3, "steps": 20 }
[- [
- {
- "base64": "...very long string...",
- "finishReason": "SUCCESS",
- "seed": 1050625087
}, - {
- "base64": "...very long string...",
- "finishReason": "CONTENT_FILTERED",
- "seed": 1229191277
}
]
]
Create a higher resolution version of an input image.
This operation outputs an image with a maximum pixel count of 4,194,304. This is equivalent to dimensions such as 2048x2048
and 4096x1024
.
By default, the input image will be upscaled by a factor of 2. For additional control over the output dimensions, a width
or height
parameter may be specified.
engine_id required | string Examples:
|
Accept | string Default: application/json Enum: "application/json" "image/png" The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image. |
Organization | string Example: org-123456 Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used. |
image required | string <binary> (InputImage) |
width | integer (UpscaleImageWidth) >= 512 Desired width of the output image. Only one of |
height | integer (UpscaleImageHeight) >= 512 Desired height of the output image. Only one of |
Upscale input image by 2x
{ "image": "<image binary>" }
[- [
- {
- "base64": "...very long string...",
- "finishReason": "SUCCESS",
- "seed": 1050625087
}, - {
- "base64": "...very long string...",
- "finishReason": "CONTENT_FILTERED",
- "seed": 1229191277
}
]
]
Selectively modify portions of an image using a mask
engine_id required | string Example: stable-inpainting-512-v2-0 |
Accept | string Default: application/json Enum: "application/json" "image/png" The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image. |
Organization | string Example: org-123456 Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used. |
required | Array of objects (TextPrompts) non-empty An array of text prompts to use for generation. Due to how arrays are represented in Given a text prompt with the text
To add another prompt to that request simply provide the values under a new
|
init_image required | string <binary> (InitImage) Image used to initialize the diffusion process, in lieu of random noise. |
mask_source required | string (MaskSource) For any given pixel, the mask determines the strength of generation on a linear scale. This parameter determines where to source the mask from:
|
mask_image required | string <binary> (MaskImage) Optional grayscale mask that allows for influence over which pixels are eligible for diffusion and at what strength. Must be the same dimensions as the |
cfg_scale | number (CfgScale) [ 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 (ClipGuidancePreset) Default: "NONE" Enum: "FAST_BLUE" "FAST_GREEN" "NONE" "SIMPLE" "SLOW" "SLOWER" "SLOWEST" |
sampler | string (Sampler) 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. |
samples | integer (Samples) [ 1 .. 10 ] Default: 1 Number of images to generate |
seed | integer (Seed) [ 0 .. 4294967295 ] Default: 0 Random noise seed (omit this option or use |
steps | integer (Steps) [ 10 .. 150 ] Default: 50 Number of diffusion steps to run |
{ "mask_source": "MASK_IMAGE_BLACK", "init_image": "<image binary>", "mask_image": "<image binary>", "text_prompts[0][text]": "A dog space commander", "text_prompts[0][weight]": 1, "cfg_scale": 7, "clip_guidance_preset": "FAST_BLUE", "sampler": "K_DPM_2_ANCESTRAL", "samples": 3, "steps": 20 }
[- [
- {
- "base64": "...very long string...",
- "finishReason": "SUCCESS",
- "seed": 1050625087
}, - {
- "base64": "...very long string...",
- "finishReason": "CONTENT_FILTERED",
- "seed": 1229191277
}
]
]