Prompt Chain

Generate Images with Google Imagen

A promptfoo example for evaluating Google's Imagen and Gemini native image generation models side by side.

Works with google

92
Spark score
out of 100
Updated 13 days ago
Version 0.121.18
Models

Add to Favorites

Why it matters

Leverage Google's advanced AI models, including Imagen and Gemini, to generate high-quality images directly from text prompts.

Outcomes

What it gets done

01

Utilize Google Imagen for image generation.

02

Explore Gemini's native image generation capabilities.

03

Integrate powerful image creation into your projects.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-google-imagen | bash

Steps

Steps in the chain

01
Initialize google-imagen example
02
Choose authentication method
03
Set up Google AI Studio (Option 1)
04
Set up Vertex AI (Option 2)
05
Run evaluation

Overview

Google Imagen

A promptfoo example for evaluating Google's Imagen and Gemini native image generation models, supporting both Google AI Studio and Vertex AI authentication paths. Use it to compare Google image-generation models. AI Studio is quick-start but Imagen-4-only with limited parameters; Vertex AI supports all models and parameters but needs gcloud auth and a project ID.

What it does

This promptfoo example demonstrates Google's image generation models, covering both the dedicated Imagen models and Gemini's native image generation. Imagen models are addressed with a google:image: prefix - imagen-4.0-ultra-generate-001 ($0.06/image), imagen-4.0-generate-001 ($0.04/image), imagen-4.0-fast-generate-001 ($0.02/image), and imagen-3.0-generate-002 ($0.04/image). Gemini's native image generation is exposed under the same google: provider namespace used for Gemini chat, with models like google:gemini-3.1-flash-image and google:gemini-3-pro-image (Nano Banana / Nano Banana Pro) automatically enabling image generation whenever -image appears in the model name.

When to use - and when NOT to

Use this example to evaluate or compare Google's image-generation options through either Google AI Studio (quick start, API-key auth, Imagen 4 only, no seed or addWatermark parameters) or Vertex AI (full features: all Imagen models, all safety filter levels, seed, and addWatermark, but requires gcloud application-default login and a Google Cloud project ID). Google has deprecated the Imagen 4 preview-dated model IDs with an August 17, 2026 shutdown in favor of gemini-3.1-flash-image, and the older imagen-4.0--preview-06-06 and gemini--image-preview aliases are already shut down as of June 25, 2026 - point at the current GA model IDs listed above, not the retired preview aliases.

Inputs and outputs

Run the eval directly once configured:

npx promptfoo@latest init --example google-imagen
cd google-imagen
npx promptfoo@latest eval

See promptfooconfig-advanced.yaml for platform-specific configuration examples, promptfooconfig-gemini.yaml for Gemini native image generation, and promptfooconfig-gemini-grounding.yaml for Google Search-grounded Gemini image generation via tools: [{ googleSearch: {} }].

Integrations

Set GOOGLE_API_KEY for AI Studio, or GOOGLE_PROJECT_ID (or projectId in provider config) plus gcloud auth application-default login for Vertex AI. Gemini native image generation differs from Imagen in several ways: it uses the generateContent API with responseModalities including images rather than a dedicated image endpoint, supports more aspect ratios (1:4, 1:8, 2:3, 3:2, 4:1, 4:5, 5:4, 8:1, 21:9) and resolutions (512px on Gemini 3.1, 1K, 2K, 4K), can return text and images together in one response, and reuses the same authentication as Gemini chat models. Seed and watermark parameters remain mutually exclusive and Vertex-AI-only.

Who it's for

Teams evaluating Google's image-generation offerings who need to weigh Imagen's dedicated endpoint and per-image pricing against Gemini's native, more flexible image generation, and want working configs for both AI Studio and Vertex AI paths. The Gemini side also includes two lower-cost variants worth comparing directly - gemini-3.1-flash-lite-image at roughly $0.034 per 1K image (1K resolution only) and gemini-2.5-flash-image at roughly $0.039 per image - alongside the pricier gemini-3.1-flash-image and gemini-3-pro-image options.

Source README

google-imagen (Google Imagen)

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

Prerequisites

You can use Imagen models through either Google AI Studio or Vertex AI:

Option 1: Google AI Studio (Quick Start, Limited Features)

  • Get an API key from Google AI Studio
  • Supports: Imagen 4 models only
  • Limitations: No seed or addWatermark parameters

Option 2: Vertex AI (Full Features)

  • Google Cloud project with billing enabled
  • Vertex AI API enabled
  • Authentication via gcloud auth application-default login
  • Supports: All Imagen models and all parameters

Setup

For Google AI Studio:

### 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"

For Vertex AI:

### 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"

Environment Variables

  • GOOGLE_API_KEY - Google AI Studio API key (Option 1)
  • GOOGLE_PROJECT_ID - Your Google Cloud project ID (Option 2)

Available Models

Imagen Models (use google:image: prefix)

  • imagen-4.0-ultra-generate-001 - Ultra quality ($0.06/image)
  • imagen-4.0-generate-001 - Standard quality ($0.04/image)
  • imagen-4.0-fast-generate-001 - Fast generation ($0.02/image)
  • imagen-3.0-generate-002 - Imagen 3.0 ($0.04/image)

Google has deprecated the Imagen 4 models with an August 17, 2026 shutdown and recommends gemini-3.1-flash-image as the replacement. The older imagen-4.0-*-preview-06-06 ids are already shut down.

Gemini Native Image Generation

  • google:gemini-3.1-flash-lite-image - Gemini 3.1 Flash-Lite (Nano Banana 2 Lite) for the fastest, lowest-cost image generation (~$0.034/image at 1K; 1K only)
  • google:gemini-3.1-flash-image - Gemini 3.1 Flash (Nano Banana 2) with native image generation (~$0.067/image at 1K)
  • google:gemini-3-pro-image - Gemini 3 Pro (Nano Banana Pro) with native image generation (~$0.134/image at 1K/2K)
  • google:gemini-2.5-flash-image - Gemini 2.5 Flash (Nano Banana) with image generation (~$0.039/image)

Use the GA ids above; Google shut down the gemini-3.1-flash-image-preview and gemini-3-pro-image-preview aliases on June 25, 2026. Nano Banana 2 Lite never had a -preview alias.

Running the Example

npx promptfoo@latest eval

Notes

  • Imagen models are available through both Google AI Studio and Vertex AI
  • Google AI Studio:
    • Uses API key authentication (quick start)
    • Only supports Imagen 4 models (4.0 preview models)
    • Limited parameter support:
      • No seed or addWatermark parameters
      • Only block_low_and_above safety filter level
  • Vertex AI:
    • Requires authentication via gcloud auth application-default login
    • Supports all Imagen models (both 3.0 and 4.0)
    • Full parameter support:
      • All safety filter levels (block_most, block_some, block_few, block_fewest)
      • seed for deterministic generation
      • addWatermark control
    • You must provide a Google Cloud project ID either via:
      • GOOGLE_PROJECT_ID environment variable
      • projectId in the provider config
  • Seed and watermark parameters are mutually exclusive (Vertex AI only)

Advanced Configuration

See promptfooconfig-advanced.yaml for examples of platform-specific configurations that take advantage of each platform's unique capabilities.

Gemini Native Image Generation

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:

  • Uses the same google: provider namespace as Gemini chat (models with -image in the name automatically enable image generation)
  • Supports additional aspect ratios: 1:4, 1:8, 2:3, 3:2, 4:1, 4:5, 5:4, 8:1, 21:9
  • Supports image resolution: 512px (Gemini 3.1), 1K, 2K, 4K
  • Can return both text and images in the same response
  • Uses the same authentication as Gemini chat models
  • Supports Google Search grounding via tools: [{ googleSearch: {} }]

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.