Skip to main content

AWS Bedrock - Image Generation

Use Bedrock for image generation with Stable Diffusion, Amazon Titan Image Generator, and Amazon Nova Canvas models.

Supported Models​

Model NameFunction CallCost Tracking
Stable Diffusion 3 - v0image_generation(model="bedrock/stability.stability.sd3-large-v1:0", prompt=prompt)✅
Stable Diffusion - v0image_generation(model="bedrock/stability.stable-diffusion-xl-v0", prompt=prompt)✅
Stable Diffusion - v1image_generation(model="bedrock/stability.stable-diffusion-xl-v1", prompt=prompt)✅
Amazon Titan Image Generator - v1image_generation(model="bedrock/amazon.titan-image-generator-v1", prompt=prompt)✅
Amazon Titan Image Generator - v2image_generation(model="bedrock/amazon.titan-image-generator-v2:0", prompt=prompt)✅
Amazon Nova Canvas - v1image_generation(model="bedrock/amazon.nova-canvas-v1:0", prompt=prompt)✅

Usage​

Basic Usage​

import os
from litellm import image_generation

os.environ["AWS_ACCESS_KEY_ID"] = ""
os.environ["AWS_SECRET_ACCESS_KEY"] = ""
os.environ["AWS_REGION_NAME"] = ""

response = image_generation(
prompt="A cute baby sea otter",
model="bedrock/stability.stable-diffusion-xl-v0",
)
print(f"response: {response}")

Set Optional Parameters​

import os
from litellm import image_generation

os.environ["AWS_ACCESS_KEY_ID"] = ""
os.environ["AWS_SECRET_ACCESS_KEY"] = ""
os.environ["AWS_REGION_NAME"] = ""

response = image_generation(
prompt="A cute baby sea otter",
model="bedrock/stability.stable-diffusion-xl-v0",
### OPENAI-COMPATIBLE ###
size="128x512", # width=128, height=512
### PROVIDER-SPECIFIC ### see `AmazonStabilityConfig` in bedrock.py for all params
seed=30
)
print(f"response: {response}")

Amazon Nova Canvas - Image Edit​

Use OpenAI-compatible image_edit() with Bedrock Nova Canvas (amazon.nova-canvas-v1:0). Requests use the same InvokeModel API as generation; LiteLLM maps inputs to Nova Canvas task types:

ScenariotaskType sent to Bedrock
Image + prompt (no mask)IMAGE_VARIATION
Image + prompt + maskINPAINTING (inPaintingParams.image, maskImage or maskPrompt)
taskType: OUTPAINTING + mask or maskPromptOUTPAINTING (Bedrock requires one; LiteLLM raises a clear error if both are missing)
taskType: BACKGROUND_REMOVALBACKGROUND_REMOVAL
from litellm import image_edit

response = image_edit(
image=open("photo.png", "rb"),
prompt="Add soft sunset lighting",
model="bedrock/amazon.nova-canvas-v1:0",
)

For BACKGROUND_REMOVAL, the AWS request must not include imageGenerationConfig; LiteLLM omits it for that task even if you pass size, n, seed, etc. Additional Nova Canvas inference IDs for image edit should set supports_nova_canvas_image_edit: true in model_prices_and_context_window.json (see amazon.nova-canvas-v1:0).

Using Inference Profiles with Image Generation​

For AWS Bedrock Application Inference Profiles with image generation, use the model_id parameter to specify the inference profile ARN:

from litellm import image_generation

response = image_generation(
model="bedrock/amazon.nova-canvas-v1:0",
model_id="arn:aws:bedrock:eu-west-1:000000000000:application-inference-profile/a0a0a0a0a0a0",
prompt="A cute baby sea otter"
)
print(f"response: {response}")

Authentication​

All standard Bedrock authentication methods are supported for image generation. See Bedrock Authentication for details.