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}")

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.