Skip to main content

Google AI Studio Image Generation

Google AI Studio provides powerful image generation capabilities using Google's Imagen models to create high-quality images from text descriptions.

Overview​

PropertyDetails
DescriptionGoogle AI Studio Image Generation uses Google's Imagen models to generate high-quality images from text descriptions.
Provider Route on LiteLLMgemini/
Provider DocGoogle AI Studio Image Generation ↗
Supported Operations/images/generations

Setup​

API Key​

# Set your Google AI Studio API key
import os
os.environ["GEMINI_API_KEY"] = "your-api-key-here"

Get your API key from Google AI Studio.

Image Generation​

Usage - LiteLLM Python SDK​

Basic Image Generation
import litellm
import os

# Set your API key
os.environ["GEMINI_API_KEY"] = "your-api-key-here"

# Generate a single image
response = litellm.image_generation(
model="gemini/imagen-4.0-generate-001",
prompt="A cute baby sea otter swimming in crystal clear water"
)

print(response.data[0].url)

Usage - LiteLLM Proxy Server​

1. Configure your config.yaml​

Google AI Studio Image Generation Configuration
model_list:
- model_name: google-imagen
litellm_params:
model: gemini/imagen-4.0-generate-001
api_key: os.environ/GEMINI_API_KEY
model_info:
mode: image_generation

general_settings:
master_key: sk-1234

2. Start LiteLLM Proxy Server​

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​

Google AI Studio Image Generation via Proxy - OpenAI SDK
from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
base_url="http://localhost:4000", # Your proxy URL
api_key="sk-1234" # Your proxy API key
)

# Generate image
response = client.images.generate(
model="google-imagen",
prompt="A majestic eagle soaring over snow-capped mountains",
n=1,
size="1024x1024"
)

print(response.data[0].url)

Gemini Image Models​

Gemini image models (e.g. gemini-3.1-flash-image-preview, gemini-3-pro-image-preview) use the generateContent API and return base64 images. They also support Google Search grounding on /v1/images/generations.

Gemini image generation with Google Search
import litellm
import os

os.environ["GEMINI_API_KEY"] = "your-api-key-here"

response = litellm.image_generation(
model="gemini/gemini-3.1-flash-image-preview",
prompt="Generate an image of the latest iPhone design",
web_search_options={},
)

print(response.data[0].b64_json)
Proxy request with web_search_options
curl --location 'http://localhost:4000/v1/images/generations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-1234' \
--data '{
"model": "gemini-3.1-flash-image-preview",
"prompt": "Generate an image of the latest iPhone design",
"web_search_options": {}
}'

You can also pass tools=[{"type": "web_search"}] or native tools=[{"googleSearch": {}}].

Supported Parameters​

Google AI Studio Image Generation supports the following OpenAI-compatible parameters:

ParameterTypeDescriptionDefaultExample
promptstringText description of the image to generateRequired"A sunset over the ocean"
modelstringThe model to use for generationRequired"gemini/imagen-4.0-generate-001"
nintegerNumber of images to generate (1-4)12
sizestringImage dimensions"1024x1024""512x512", "1024x1024"
web_search_optionsobjectEnable Google Search grounding (Gemini image models only)-{}
toolsarrayPass {"type": "web_search"} or {"googleSearch": {}} (Gemini image models only)-[{"type": "web_search"}]
  1. Create an account at Google AI Studio
  2. Generate an API key from API Keys section
  3. Set your GEMINI_API_KEY environment variable
  4. Start generating images using LiteLLM

Additional Resources​

🚅
LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails — built for production.
Learn more →