Vertex AI Image Generation
Vertex AI supports two types of image generation:
- Gemini Image Generation Models (Nano Banana π) - Conversational image generation using
generateContentAPI - Imagen Models - Traditional image generation using
predictAPI
| Property | Details |
|---|---|
| Description | Vertex AI Image Generation supports both Gemini image generation models |
| Provider Route on LiteLLM | vertex_ai/ |
| Provider Doc | Google Cloud Vertex AI Image Generation β |
| Gemini Image Generation Docs | Gemini Image Generation β |
Quick Startβ
Gemini Image Generation Modelsβ
Gemini image generation models support conversational image creation with features like:
- Text-to-Image generation
- Image editing (text + image β image)
- Multi-turn image refinement
- High-fidelity text rendering
- Up to 4K resolution (Gemini 3 Pro)
import litellm
# Generate a single image
response = await litellm.aimage_generation(
prompt="A nano banana dish in a fancy restaurant with a Gemini theme",
model="vertex_ai/gemini-2.5-flash-image",
vertex_ai_project="your-project-id",
vertex_ai_location="us-central1",
n=1,
size="1024x1024",
)
print(response.data[0].b64_json) # Gemini returns base64 images
import litellm
# Generate high-resolution image
response = await litellm.aimage_generation(
prompt="Da Vinci style anatomical sketch of a dissected Monarch butterfly",
model="vertex_ai/gemini-3-pro-image-preview",
vertex_ai_project="your-project-id",
vertex_ai_location="us-central1",
n=1,
size="1024x1024",
# Optional: specify image size for Gemini 3 Pro
# imageSize="4K", # Options: "1K", "2K", "4K"
)
print(response.data[0].b64_json)
Google Search Groundingβ
Gemini image models (e.g. gemini-3.1-flash-image-preview, gemini-3-pro-image-preview) support Google Search on /v1/images/generations. LiteLLM maps web_search_options or OpenAI-style web_search tools to Gemini's googleSearch tool on the underlying generateContent request.
import litellm
response = await litellm.aimage_generation(
prompt="Generate an image of the latest iPhone design",
model="vertex_ai/gemini-3.1-flash-image-preview",
vertex_ai_project="your-project-id",
vertex_ai_location="us-central1",
web_search_options={},
)
print(response.data[0].b64_json)
import litellm
response = await litellm.aimage_generation(
prompt="Generate an image of the latest iPhone design",
model="vertex_ai/gemini-3.1-flash-image-preview",
vertex_ai_project="your-project-id",
vertex_ai_location="us-central1",
tools=[{"type": "web_search"}],
)
Via LiteLLM Proxy (/v1/images/generations):
curl -X POST 'http://localhost:4000/v1/images/generations' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"model": "gemini-3.1-flash-image-preview",
"prompt": "Generate an image of the latest iPhone design",
"web_search_options": {}
}'
Passing imageConfig (Gemini models)β
Gemini image generation models support the full ImageConfig object. Pass it as imageConfig on any /v1/images/generations request and LiteLLM will forward all fields verbatim to generationConfig.imageConfig.
| Field | Type | Description |
|---|---|---|
aspectRatio | string | "1:1", "16:9", "9:16", "4:3", "3:4", "4:5", "5:4", "2:3", "3:2", "21:9" |
imageSize | string | "1K", "2K", "4K" (supported on Gemini 3 Pro and newer) |
personGeneration | string | "DONT_ALLOW", "ALLOW_ADULT", "ALLOW_ALL" |
imageOutputOptions | object | {"mimeType": "image/jpeg"|"image/png"|"image/webp", "compressionQuality": 0β100} |
import litellm
response = await litellm.aimage_generation(
model="vertex_ai/gemini-3.1-flash-image",
prompt="A nano banana on a desk",
vertex_ai_project="your-project-id",
vertex_ai_location="us-central1",
imageConfig={
"aspectRatio": "16:9",
"imageSize": "2K",
"personGeneration": "DONT_ALLOW",
"imageOutputOptions": {
"mimeType": "image/jpeg",
"compressionQuality": 85,
},
},
)
curl -X POST 'http://localhost:4000/v1/images/generations' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"model": "gemini-3.1-flash-image",
"prompt": "A nano banana on a desk",
"imageConfig": {
"aspectRatio": "16:9",
"imageSize": "2K",
"personGeneration": "DONT_ALLOW",
"imageOutputOptions": {
"mimeType": "image/jpeg",
"compressionQuality": 85
}
}
}'
You can also use flat params as shorthand for aspectRatio and imageSize:
response = await litellm.aimage_generation(
model="vertex_ai/gemini-3.1-flash-image",
prompt="A nano banana on a desk",
aspect_ratio="16:9", # or aspectRatio="16:9"
image_size="2K", # or imageSize="2K"
vertex_ai_project="your-project-id",
vertex_ai_location="us-central1",
)
Flat params (aspect_ratio, image_size, aspectRatio, imageSize) override the same key inside imageConfig when both are present.
Imagen Modelsβ
import litellm
# Generate a single image
response = await litellm.aimage_generation(
prompt="An olympic size swimming pool with crystal clear water and modern architecture",
model="vertex_ai/imagen-4.0-generate-001",
vertex_ai_project="your-project-id",
vertex_ai_location="us-central1",
n=1,
size="1024x1024",
)
print(response.data[0].b64_json) # Imagen also returns base64 images
LiteLLM Proxyβ
1. Configure your config.yamlβ
model_list:
- model_name: vertex-imagen
litellm_params:
model: vertex_ai/imagen-4.0-generate-001
vertex_ai_project: "your-project-id"
vertex_ai_location: "us-central1"
vertex_ai_credentials: "path/to/service-account.json" # Optional if using environment auth
2. Start LiteLLM Proxy Serverβ
litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000
3. Make requests with OpenAI Python SDKβ
from openai import OpenAI
# Initialize client with your proxy URL
client = OpenAI(
base_url="http://localhost:4000", # Your proxy URL
api_key="your-proxy-api-key" # Your proxy API key
)
# Generate image
response = client.images.generate(
model="vertex-imagen",
prompt="An olympic size swimming pool with crystal clear water and modern architecture",
)
print(response.data[0].url)
Supported Modelsβ
Gemini Image Generation Modelsβ
vertex_ai/gemini-2.5-flash-image- Fast, efficient image generation (1024px resolution)vertex_ai/gemini-3.1-flash-image-preview- Fast image generation with Google Search groundingvertex_ai/gemini-3-pro-image-preview- Advanced model with 4K output, Google Search grounding, and thinking modevertex_ai/gemini-2.0-flash-preview-image- Preview modelvertex_ai/gemini-2.5-flash-image-preview- Preview model
Imagen Modelsβ
vertex_ai/imagegeneration@006- Legacy Imagen modelvertex_ai/imagen-4.0-generate-001- Latest Imagen modelvertex_ai/imagen-3.0-generate-001- Imagen 3.0 model
We support ALL Vertex AI Image Generation models, just set model=vertex_ai/<any-model-on-vertex_ai> as a prefix when sending litellm requests
For the complete and up-to-date list of supported models, visit: https://models.litellm.ai/