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
| Property | Details |
|---|---|
| Description | Google AI Studio Image Generation uses Google's Imagen models to generate high-quality images from text descriptions. |
| Provider Route on LiteLLM | gemini/ |
| Provider Doc | Google 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 Usage
- Async Usage
- Advanced Parameters
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)
Async Image Generation
import litellm
import asyncio
import os
async def generate_image():
# Set your API key
os.environ["GEMINI_API_KEY"] = "your-api-key-here"
# Generate image asynchronously
response = await litellm.aimage_generation(
model="gemini/imagen-4.0-generate-001",
prompt="A beautiful sunset over mountains with vibrant colors",
n=1,
)
print(response.data[0].url)
return response
# Run the async function
asyncio.run(generate_image())
Advanced Image Generation with Parameters
import litellm
import os
# Set your API key
os.environ["GEMINI_API_KEY"] = "your-api-key-here"
# Generate image with additional parameters
response = litellm.image_generation(
model="gemini/imagen-4.0-generate-001",
prompt="A futuristic cityscape at night with neon lights",
n=1,
size="1024x1024"
)
for image in response.data:
print(f"Generated image URL: {image.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: os.environ/LITELLM_MASTER_KEY
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
- OpenAI SDK
- LiteLLM SDK
- cURL
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-<your-litellm-api-key>" # 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)
Google AI Studio Image Generation via Proxy - LiteLLM SDK
import litellm
# Configure LiteLLM to use your proxy
response = litellm.image_generation(
model="litellm_proxy/google-imagen",
prompt="A serene Japanese garden with cherry blossoms",
api_base="http://localhost:4000",
api_key="sk-<your-litellm-api-key>"
)
print(response.data[0].url)
Google AI Studio Image Generation via Proxy - cURL
curl --location 'http://localhost:4000/v1/images/generations' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $LITELLM_API_KEY" \
--data '{
"model": "google-imagen",
"prompt": "A cozy coffee shop interior with warm lighting",
"n": 1,
"size": "1024x1024"
}'