examples/google-imagen/README.md
This example demonstrates Google image generation models, including both Imagen and Gemini native image generation.
You can run this example with:
npx promptfoo@latest init --example google-imagen
cd google-imagen
You can use Imagen models through either Google AI Studio or Vertex AI:
seed or addWatermark parametersgcloud auth application-default login# Set your API key (Unix/Linux/macOS)
export GOOGLE_API_KEY=your-api-key
# For Windows Command Prompt:
# set GOOGLE_API_KEY=your-api-key
# For Windows PowerShell:
# $env:GOOGLE_API_KEY="your-api-key"
# Enable Vertex AI API
gcloud services enable aiplatform.googleapis.com
# Authenticate
gcloud auth application-default login
# Set project ID (Unix/Linux/macOS)
export GOOGLE_PROJECT_ID=your-project-id
# For Windows Command Prompt:
# set GOOGLE_PROJECT_ID=your-project-id
# For Windows PowerShell:
# $env:GOOGLE_PROJECT_ID="your-project-id"
GOOGLE_API_KEY - Google AI Studio API key (Option 1)GOOGLE_PROJECT_ID - Your Google Cloud project ID (Option 2)google:image: prefix)imagen-4.0-ultra-generate-preview-06-06 - Ultra quality ($0.06/image)imagen-4.0-generate-preview-06-06 - Standard quality ($0.04/image)imagen-4.0-fast-generate-preview-06-06 - Fast generation ($0.02/image)imagen-3.0-generate-002 - Imagen 3.0 ($0.04/image)google:gemini-3.1-flash-image-preview - Gemini 3.1 Flash (Nano Banana 2) with native image generation (~$0.067/image at 1K)google:gemini-3-pro-image-preview - Gemini 3 Pro with native image generation (~$0.05/image, estimated)google:gemini-2.5-flash-image - Gemini 2.5 Flash with image generation (~$0.04/image)npx promptfoo@latest eval
seed or addWatermark parametersblock_low_and_above safety filter levelgcloud auth application-default loginblock_most, block_some, block_few, block_fewest)seed for deterministic generationaddWatermark controlGOOGLE_PROJECT_ID environment variableprojectId in the provider configSee promptfooconfig-advanced.yaml for examples of platform-specific configurations that take advantage of each platform's unique capabilities.
Gemini models can generate images natively using the generateContent API with responseModalities set to include images. This is different from Imagen which uses a dedicated image generation endpoint.
See promptfooconfig-gemini.yaml for Gemini native image generation examples.
See promptfooconfig-gemini-grounding.yaml for Google Search-grounded Gemini image generation.
Key differences from Imagen:
google: provider namespace as Gemini chat (models with -image in the name automatically enable image generation)1:4, 1:8, 2:3, 3:2, 4:1, 4:5, 5:4, 8:1, 21:9512px (Gemini 3.1), 1K, 2K, 4Ktools: [{ googleSearch: {} }]