Overview
Generate images from text prompts using any of LiteLLM’s supported image generation providers. Returns responses in OpenAI format.Function Signature
Parameters
Required Parameters
string
required
Text description of the desired image(s).
Optional Parameters
string
The model to use for image generation.Examples:
dall-e-3(OpenAI)dall-e-2(OpenAI)stability-ai/stable-diffusion-xl-base-1.0(Bedrock)imagegeneration@006(Vertex AI)
int
default:"1"
Number of images to generate.Note: dall-e-3 only supports n=1
string
Size of generated images.For DALL-E 3:
"1024x1024"(default)"1792x1024""1024x1792"
"256x256""512x512""1024x1024"
string
default:"standard"
Quality of the image (DALL-E 3 only).Options:
"standard": Standard quality"hd": Higher quality, more detailed
string
default:"vivid"
Style of generated images (DALL-E 3 only).Options:
"vivid": Hyper-real and dramatic images"natural": More natural, less hyper-real
string
default:"url"
Format of the returned image.Options:
"url": Returns a URL to the image"b64_json": Returns base64 encoded JSON
string
Unique identifier for your end-user.
float
default:"600"
Request timeout in seconds (default 10 minutes).
API Configuration
string
API key for the provider.
string
Base URL for the API endpoint.
string
API version to use.
string
Override provider detection.
Response
ImageResponse
int
Unix timestamp of when the image was created.
List[ImageObject]
List of generated image objects.
Usage Examples
Basic Image Generation
High Quality Image
Multiple Images (DALL-E 2)
Async Image Generation
Base64 Response
Provider Examples
OpenAI DALL-E
Azure OpenAI
AWS Bedrock
Vertex AI
Replicate
Saving Images
Save from URL
Save from Base64
Error Handling
Supported Providers
LiteLLM supports image generation from:- OpenAI: DALL-E 2, DALL-E 3
- Azure OpenAI: DALL-E 2, DALL-E 3
- AWS Bedrock: Stable Diffusion, Titan Image Generator
- Google Vertex AI: Imagen 2, Imagen 3
- Replicate: Stable Diffusion XL, Flux, and more
- Together AI: Various Stable Diffusion models
Related
- aimage_generation() - Async version
- Completion API
- Image Generation Guide