Skip to main content

Overview

GoogleImageGenService provides high-quality image generation capabilities using Google’s Imagen models. It supports generating multiple images from text prompts with various customization options and advanced prompt understanding for photorealistic and artistic image creation.

Installation

To use Google Imagen services, install the required dependencies:
pip install "pipecat-ai[google]"

Prerequisites

Google Cloud Setup

Before using Google Imagen services, you need:
  1. Google Cloud Account: Set up at Google Cloud Console
  2. API Key: Generate a Google API key with Vertex AI access
  3. Project Configuration: Enable Vertex AI API for your project
  4. Model Access: Ensure access to Imagen generation models

Required Environment Variables

  • GOOGLE_API_KEY: Your Google API key for authentication

Configuration

api_key
str
required
Google AI API key for authentication.
params
InputParams
default:"None"
Configuration parameters for image generation. See InputParams below.
http_options
Any
default:"None"
HTTP options for the Google AI client.

InputParams

ParameterTypeDefaultDescription
number_of_imagesint1Number of images to generate (1-8).
modelstr"imagen-3.0-generate-002"Google Imagen model to use.
negative_promptstrNoneOptional negative prompt to guide what not to include in the generated image.

Usage

Basic Setup

from pipecat.services.google import GoogleImageGenService

image_gen = GoogleImageGenService(
    api_key=os.getenv("GOOGLE_API_KEY"),
)

With Custom Parameters

image_gen = GoogleImageGenService(
    api_key=os.getenv("GOOGLE_API_KEY"),
    params=GoogleImageGenService.InputParams(
        number_of_images=2,
        model="imagen-3.0-generate-002",
        negative_prompt="blurry, low quality",
    ),
)

Notes

  • No HTTP session needed: Unlike OpenAI and fal, Google returns image data directly in the API response, so no separate HTTP session is required for downloading.
  • Negative prompts: Use the negative_prompt parameter to specify what should not appear in the generated image, giving you more control over the output.
  • Metrics support: Google Imagen supports TTFB metrics tracking.