Skip to main content

Stability AI

https://stability.ai/

Overview​

PropertyDetails
DescriptionStability AI creates open AI models for image, video, audio, and 3D generation. Known for Stable Diffusion.
Provider Route on LiteLLMstability/
Link to Provider DocStability AI API ↗
Supported Operations/images/generations, /images/edits

LiteLLM supports Stability AI Image Generation calls via the Stability AI REST API (not via Bedrock).

API Key​

# env variable
os.environ['STABILITY_API_KEY'] = "your-api-key"

Get your API key from the Stability AI Platform.

Image Generation​

Usage - LiteLLM Python SDK​

from litellm import image_generation
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Stability AI image generation call
response = image_generation(
model="stability/sd3.5-large",
prompt="A beautiful sunset over a calm ocean",
)
print(response)

Usage - LiteLLM Proxy Server​

1. Setup config.yaml​

model_list:
- model_name: sd3
litellm_params:
model: stability/sd3.5-large
api_key: os.environ/STABILITY_API_KEY
model_info:
mode: image_generation

general_settings:
master_key: os.environ/LITELLM_MASTER_KEY

2. Start the proxy​

litellm --config config.yaml

# RUNNING on http://0.0.0.0:4000

3. Test it​

curl --location 'http://0.0.0.0:4000/v1/images/generations' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $LITELLM_API_KEY" \
--data '{
"model": "sd3",
"prompt": "A beautiful sunset over a calm ocean"
}'

Advanced Usage - With Additional Parameters​

from litellm import image_generation
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

response = image_generation(
model="stability/sd3.5-large",
prompt="A beautiful sunset over a calm ocean",
size="1792x1024", # Maps to aspect_ratio 16:9
negative_prompt="blurry, low quality", # Stability-specific
seed=12345, # For reproducibility
)
print(response)

Supported Parameters​

Stability AI supports the following OpenAI-compatible parameters:

ParameterTypeDescriptionExample
sizestringImage dimensions (mapped to aspect_ratio)"1024x1024"
nintegerNumber of images (note: Stability returns 1 per request)1
response_formatstringFormat of response (b64_json only for Stability)"b64_json"

Size to Aspect Ratio Mapping​

The size parameter is automatically mapped to Stability's aspect_ratio:

OpenAI SizeStability Aspect Ratio
1024x10241:1
1792x102416:9
1024x17929:16
512x5121:1
256x2561:1

Using Stability-Specific Parameters​

You can pass parameters that are specific to Stability AI directly in your request:

from litellm import image_generation
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

response = image_generation(
model="stability/sd3.5-large",
prompt="A beautiful sunset over a calm ocean",
# Stability-specific parameters
negative_prompt="blurry, watermark, text",
aspect_ratio="16:9", # Use directly instead of size
seed=42,
output_format="png", # png, jpeg, or webp
)
print(response)

Supported Image Generation Models​

Model NameFunction CallDescription
sd3image_generation(model="stability/sd3", ...)Stable Diffusion 3
sd3-largeimage_generation(model="stability/sd3-large", ...)SD3 Large
sd3-large-turboimage_generation(model="stability/sd3-large-turbo", ...)SD3 Large Turbo (faster)
sd3-mediumimage_generation(model="stability/sd3-medium", ...)SD3 Medium
sd3.5-largeimage_generation(model="stability/sd3.5-large", ...)SD 3.5 Large (recommended)
sd3.5-large-turboimage_generation(model="stability/sd3.5-large-turbo", ...)SD 3.5 Large Turbo
sd3.5-mediumimage_generation(model="stability/sd3.5-medium", ...)SD 3.5 Medium
stable-image-ultraimage_generation(model="stability/stable-image-ultra", ...)Stable Image Ultra
stable-image-coreimage_generation(model="stability/stable-image-core", ...)Stable Image Core

For more details on available models and features, see: https://platform.stability.ai/docs/api-reference

Response Format​

Stability AI returns images in base64 format. The response is OpenAI-compatible:

{
"created": 1234567890,
"data": [
{
"b64_json": "iVBORw0KGgo..." # Base64 encoded image
}
]
}

Image Editing​

Stability AI supports various image editing operations including inpainting, upscaling, outpainting, background removal, and more.

Optional Parameters

Important: Different Stability models have different parameter requirements:

  • Some models don't require a prompt (e.g., upscaling, background removal)
  • The outpaint model takes numeric left and right pixel counts. LiteLLM does not forward up or down, the fields Stability uses for vertical outpainting, so only horizontal outpainting works through stability/ today
  • Style Transfer is not reachable through stability/ today: stability/style-transfer resolves to the Style Guide endpoint (/v2beta/stable-image/control/style) and the input is always sent as image, while Stability's Style Transfer endpoint requires init_image

Usage - LiteLLM Python SDK​

Inpainting (Edit with Mask)​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Inpainting - edit specific areas using a mask
response = image_edit(
model="stability/inpaint",
image=open("original_image.png", "rb"),
mask=open("mask_image.png", "rb"),
prompt="Add a beautiful sunset in the masked area",
size="1024x1024",
)
print(response)

Image Upscaling​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Conservative upscaling - preserves details
response = image_edit(
model="stability/conservative",
image=open("low_res_image.png", "rb"),
prompt="Upscale this image while preserving details",
)

# Creative upscaling - adds creative details
response = image_edit(
model="stability/creative",
image=open("low_res_image.png", "rb"),
prompt="Upscale and enhance with creative details",
creativity=0.3, # 0-0.35, higher = more creative
)

# Fast upscaling - quick upscaling (no prompt needed)
response = image_edit(
model="stability/fast",
image=open("low_res_image.png", "rb"),
# No prompt required for fast upscale
)
print(response)

Image Outpainting​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Extend image beyond its borders
response = image_edit(
model="stability/outpaint",
image=open("original_image.png", "rb"),
prompt="Extend this landscape with mountains",
left=100, # Pixels to extend on the left
right=100, # Pixels to extend on the right
)
print(response)

Background Removal​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Remove background from image
response = image_edit(
model="stability/remove-background",
image=open("portrait.png", "rb"),
# No prompt required for fast upscale
)
print(response)

Search and Replace​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Search and replace objects in image
response = image_edit(
model="stability/search-and-replace",
image=open("scene.png", "rb"),
prompt="A red sports car",
search_prompt="blue sedan", # What to replace
)

# Search and recolor
response = image_edit(
model="stability/search-and-recolor",
image=open("scene.png", "rb"),
prompt="Make it golden yellow",
select_prompt="the car", # What to recolor
)
print(response)

Image Control (Sketch/Structure)​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Control with sketch
response = image_edit(
model="stability/sketch",
image=open("sketch.png", "rb"),
prompt="Turn this sketch into a realistic photo",
control_strength=0.7, # 0-1, higher = more control
)

# Control with structure
response = image_edit(
model="stability/structure",
image=open("structure_reference.png", "rb"),
prompt="Generate image following this structure",
control_strength=0.7,
)
print(response)

Erase Objects​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Erase objects from image
response = image_edit(
model="stability/erase",
image=open("scene.png", "rb"),
mask=open("object_mask.png", "rb"), # Mask the object to erase
# No prompt needed
)
print(response)

Style Guide​

from litellm import image_edit
import os

os.environ['STABILITY_API_KEY'] = "your-api-key"

# Generate a new image in the style of a reference image
response = image_edit(
model="stability/style",
image=open("style_reference.png", "rb"), # Style reference
prompt="A lighthouse on a cliff at sunset",
)

print(response)

Supported Image Edit Models​

Model NameFunction CallDescription
inpaintimage_edit(model="stability/inpaint", ...)Inpainting with mask
conservativeimage_edit(model="stability/conservative", ...)Conservative upscaling
creativeimage_edit(model="stability/creative", ...)Creative upscaling
fastimage_edit(model="stability/fast", ...)Fast upscaling
outpaintimage_edit(model="stability/outpaint", ...)Extend image borders
remove-backgroundimage_edit(model="stability/remove-background", ...)Remove background
search-and-replaceimage_edit(model="stability/search-and-replace", ...)Search and replace objects
search-and-recolorimage_edit(model="stability/search-and-recolor", ...)Search and recolor
sketchimage_edit(model="stability/sketch", ...)Control with sketch
structureimage_edit(model="stability/structure", ...)Control with structure
eraseimage_edit(model="stability/erase", ...)Erase objects
styleimage_edit(model="stability/style", ...)Apply style guide

Usage - LiteLLM Proxy Server​

1. Setup config.yaml​

model_list:
- model_name: stability-inpaint
litellm_params:
model: stability/inpaint
api_key: os.environ/STABILITY_API_KEY
model_info:
mode: image_edit

- model_name: stability-upscale
litellm_params:
model: stability/conservative
api_key: os.environ/STABILITY_API_KEY
model_info:
mode: image_edit

general_settings:
master_key: os.environ/LITELLM_MASTER_KEY

2. Start the proxy​

litellm --config config.yaml

# RUNNING on http://0.0.0.0:4000

3. Test it​

curl -X POST "http://0.0.0.0:4000/v1/images/edits" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-F "model=stability-inpaint" \
-F "image=@original_image.png" \
-F "mask=@mask_image.png" \
-F "prompt=Add a beautiful garden in the masked area"

AWS Bedrock (Stability)​

LiteLLM also supports Stability AI models via AWS Bedrock. This is useful if you're already using AWS infrastructure.

Usage - Bedrock Stability​

from litellm import image_edit
import os

# Set AWS credentials
os.environ["AWS_ACCESS_KEY_ID"] = "your-access-key"
os.environ["AWS_SECRET_ACCESS_KEY"] = "your-secret-key"
os.environ["AWS_REGION_NAME"] = "us-east-1"

# Bedrock Stability inpainting
response = image_edit(
model="bedrock/us.stability.stable-image-inpaint-v1:0",
image=open("original_image.png", "rb"),
mask=open("mask_image.png", "rb"),
prompt="Add flowers in the masked area",
)
print(response)

# Fast upscale without prompt
response = image_edit(
model="bedrock/stability.stable-fast-upscale-v1:0",
image=open("low_res_image.png", "rb"),
)

# Outpaint with numeric parameters
response = image_edit(
model="bedrock/stability.stable-outpaint-v1:0",
image=open("original_image.png", "rb"),
left=100, # Automatically converted to int
right=100,
up=50,
down=50,
)

print(response)

Supported Bedrock Stability Models​

All Stability AI image edit models are available via Bedrock with the bedrock/ prefix:

Direct API ModelBedrock ModelDescription
stability/inpaintbedrock/us.stability.stable-image-inpaint-v1:0Inpainting
stability/conservativebedrock/stability.stable-conservative-upscale-v1:0Conservative upscaling
stability/creativebedrock/stability.stable-creative-upscale-v1:0Creative upscaling
stability/fastbedrock/stability.stable-fast-upscale-v1:0Fast upscaling
stability/outpaintbedrock/stability.stable-outpaint-v1:0Outpainting
stability/remove-backgroundbedrock/stability.stable-image-remove-background-v1:0Remove background
stability/search-and-replacebedrock/stability.stable-image-search-replace-v1:0Search and replace
stability/search-and-recolorbedrock/stability.stable-image-search-recolor-v1:0Search and recolor
stability/sketchbedrock/stability.stable-image-control-sketch-v1:0Control with sketch
stability/structurebedrock/stability.stable-image-control-structure-v1:0Control with structure
stability/erasebedrock/stability.stable-image-erase-object-v1:0Erase objects

Note: Bedrock model IDs may use us.stability.* or stability.* prefix depending on the region and model.

Comparing Routes​

LiteLLM supports Stability AI models via two routes:

RouteProviderUse CaseImage GenerationImage Editing
stability/Stability AI Direct APIDirect access, all latest models✅✅
bedrock/stability.*AWS BedrockAWS integration, enterprise features✅✅

Use stability/ for direct API access. Use bedrock/stability.* if you're already using AWS Bedrock.