Skip to main content

Google GenAI Plugin

The @genkit-ai/google-genai plugin provides a unified interface to connect with Google’s generative AI models, offering access through both the Gemini Developer API and Vertex AI. It replaces the previous googleAI and vertexAI plugins.

Installation

Configuration

This unified plugin exports two main initializers:
  • googleAI: Access models via the Gemini Developer API using API key authentication
  • vertexAI: Access models via Google Cloud Vertex AI

Using Gemini Developer API (googleAI)

Ideal for quick prototyping and access to models available in Google AI Studio. Authentication: Requires a Google AI API Key from Google AI Studio. Provide the key via GEMINI_API_KEY or GOOGLE_API_KEY environment variables, or pass it in the plugin configuration.

Using Vertex AI (vertexAI)

Suitable for applications leveraging Google Cloud’s AI infrastructure. Authentication Methods:
  • Application Default Credentials (ADC): Standard method for production. Uses credentials from the environment (service account on GCP, user credentials from gcloud auth application-default login locally). Requires a Google Cloud Project with billing and Vertex AI API enabled.
  • Vertex AI Express Mode: Streamlined way to try Vertex AI features using just an API key, without billing setup. Ideal for quick experimentation with generous free tier quotas. Learn more about Express Mode.
Note: When using Express Mode, don’t provide projectId and location in the plugin config.

Using Both Google AI and Vertex AI

You can configure both plugins to access models or features from both services:

Available Models

Gemini Models

  • gemini-2.5-flash - Fast, efficient model for most tasks
  • gemini-2.5-pro - Advanced reasoning and complex tasks
  • gemini-1.5-flash - Previous generation fast model
  • gemini-1.5-pro - Previous generation advanced model

Image Generation

  • imagen-3.0-generate-002 - High-quality image generation

Embeddings

  • gemini-embedding-001 - Text embeddings (Google AI)
  • text-embedding-005 - Text embeddings (Vertex AI)

Music Generation (Vertex AI Only)

  • lyria-002 - AI music generation

Usage Examples

Text Generation with Google AI

Text Generation with Vertex AI

Text Embedding

With Google AI:
With Vertex AI:

Image Generation (Imagen)

With Google AI:
With Vertex AI:

Music Generation (Lyria - Vertex AI Only)

Key Differences

Google AI (googleAI)

  • Easier setup for smaller projects
  • Great for prototyping with Google AI Studio
  • Uses API keys for authentication
  • Access to Gemini and Imagen models

Vertex AI (vertexAI)

  • Enterprise-ready with Google Cloud IAM
  • Integrates with other Vertex AI services
  • Broader range of models and features
  • Supports Lyria music generation
  • Fine-tuning capabilities
  • Robust governance and compliance
  • Express Mode for easy experimentation