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.

Installation

To use GoogleImageGenService, install the required dependencies:

pip install "pipecat-ai[google]"

You’ll also need to set up your Google API key as an environment variable: GOOGLE_API_KEY

Configuration

Constructor Parameters

params
InputParams
default:"InputParams()"

Generation parameters configuration

api_key
str
required

Google API key for authentication

Input Parameters

number_of_images
int
default:"1"

Number of images to generate (1-8)

model
str
default:"imagen-3.0-generate-002"

Model identifier

negative_prompt
str
default:"None"

Elements to exclude from generation

Input

The service accepts text prompts through its image generation pipeline.

Output Frames

URLImageRawFrame

url
string

Generated image URL (null for Google implementation as it returns raw bytes)

image
bytes

Raw image data

size
tuple

Image dimensions (width, height)

format
string

Image format (e.g., ‘JPEG’)

ErrorFrame

error
string

Error information if generation fails

Usage Example

from pipecat.services.google import GoogleImageGenService

# Configure service
image_gen = GoogleImageGenService(
    api_key="your-google-api-key",
    params=GoogleImageGenService.InputParams(
        number_of_images=2,
        model="imagen-3.0-generate-002",
        negative_prompt="blurry, distorted, low quality"
    )
)

# Use in pipeline
main_pipeline = Pipeline(
    [
        transport.input(),
        context_aggregator.user(),
        llm_service,
        image_gen,
        tts_service,
        transport.output(),
        context_aggregator.assistant(),
    ]
)

Frame Flow

Metrics Support

The service supports metrics collection:

  • Time to First Byte (TTFB)
  • Processing duration
  • API response metrics

Model Support

Google’s Imagen service offers different model variants:

Model IDDescription
imagen-3.0-generate-002Latest Imagen model with high-quality outputs

See other available models in Google’s Imagen documentation.

Error Handling

try:
    async for frame in service.run_image_gen(prompt):
        if isinstance(frame, ErrorFrame):
            handle_error(frame.error)
except Exception as e:
    logger.error(f"Image generation error: {e}")