Skip to main content

Overview

The image_generation() function provides a unified interface to generate images from text prompts across multiple providers including OpenAI DALL-E, Azure, Bedrock, Vertex AI, and more.

Basic Usage

Function Signature

Parameters

string
required
The text description of the image you want to generate.
string
The image generation model to use. If not specified, defaults to dall-e-2.Examples: dall-e-2, dall-e-3, stable-diffusion-xl, amazon.titan-image-generator-v1
int
Number of images to generate. Default: 1 (DALL-E 3 only supports n=1)
string
Image quality. Options: "standard" or "hd" (DALL-E 3 only)
string
Image dimensions. Options depend on model:
  • DALL-E 2: "256x256", "512x512", "1024x1024"
  • DALL-E 3: "1024x1024", "1024x1792", "1792x1024"
string
Image style (DALL-E 3 only). Options: "vivid" or "natural"
string
Format of the response. Options: "url" (default) or "b64_json"
float
Request timeout in seconds. Default: 600 (10 minutes)

Response Format

Examples

Basic Image Generation

Multiple Images (DALL-E 2)

High Quality Images

Base64 Response Format

Different Providers

Async Image Generation

Concurrent Image Generation

Advanced Usage

Download and Save Images

Batch Processing

Style Variations

Different Aspect Ratios (DALL-E 3)

Error Handling

Use Cases

Marketing Materials

Social Media Content

Creative Variations

Best Practices

  1. Be specific: Detailed prompts produce better results
  2. Specify style: Include artistic style, mood, lighting preferences
  3. Handle content policy: Catch ContentPolicyViolationError for rejected prompts
  4. Consider costs: DALL-E 3 HD images cost more than standard
  5. Save images: Download and store images as URLs expire
  6. Rate limits: Respect provider rate limits, especially with batch processing
  7. Aspect ratio: Choose size based on intended use case

Prompt Tips

Good Prompts

Avoid

Troubleshooting

Content Policy Violations

If your prompt is rejected:
  • Make prompts more general and less specific about people
  • Avoid trademarked characters or brands
  • Remove potentially offensive language
  • Try rephrasing sensitive topics

Image Quality Issues

  • Use DALL-E 3 with quality="hd" for best quality
  • Be more specific in prompts about desired details
  • Specify lighting, composition, and style preferences

Rate Limits