Skip to main content
Generate images from text prompts using the generateImage() function with support for various AI image models.

Basic Usage

Generate an image from a text prompt:

Google image models

Google providers expose Gemini native image models through the same API:
Gemini image model IDs use native multimodal generation and return base64 image data. They do not support requesting multiple outputs with n. Model availability on Vertex AI depends on the selected project and region.

Configuration Options

Customize image generation:
Available sizes depend on the provider and model. Common sizes include: - 256x256 - 512x512 - 1024x1024 - 1792x1024 (landscape) - 1024x1792 (portrait)

Image Response Format

The generateImage() function returns:

Multiple Images

Generate multiple variations:

Handling Image Data

Revised Prompts

Some providers modify your prompt for better results:

Image Sizes

Different models support different sizes:

Prompt Engineering Tips

Write effective prompts for better results:

Error Handling

Handle image generation errors:

Provider-Specific Options

Use provider-specific features:
Provider options are namespaced by provider name and validated by each provider adapter. Check the provider docs for available options.

Practical Examples

Best Practices

Different providers return different formats:
URLs may expire - save images you need:
Smaller sizes are faster and cheaper:

Next Steps

Multi-Modal

Use images in chat conversations

Chat Completion

Generate text responses

Tool Calling

Combine image generation with tools

Embeddings

Generate vector embeddings