Skip to main content
The Google AI provider gives you quick access to Google’s generative AI models through the Gemini Developer API. This provider is ideal for prototyping and smaller projects that don’t require the full infrastructure of Google Cloud.
This provider is part of the unified @genkit-ai/google-genai package, which also includes Vertex AI. For enterprise features, see Vertex AI.

Installation

Setup

Get an API Key

  1. Visit Google AI Studio
  2. Create or select a project
  3. Generate an API key
  4. Set it as an environment variable:

Configure the Plugin

Available Models

Text Generation (Gemini)

The Gemini 2.5 series offers the latest and most powerful models:
  • gemini-2.5-flash - Balanced speed and performance, best default choice
  • gemini-2.5-pro - Most powerful, for complex reasoning tasks
  • gemini-2.5-flash-lite - Fastest, for simple prompts
All Gemini models support:
  • Multi-turn conversations
  • Multimodal input (text, images, audio, video)
  • Function calling (tools)
  • System instructions
  • JSON output mode

Image Generation (Imagen)

  • imagen-3.0-generate-002 - High-quality image generation
  • imagen-3.0-fast-generate-001 - Faster image generation

Video Generation (Veo)

  • veo-002 - Generate videos from text prompts

Embeddings

  • gemini-embedding-001 - 768-dimensional text embeddings
  • text-embedding-004 - Latest embedding model

Usage Examples

Basic Text Generation

Multimodal Input

Gemini models can process images, audio, and video:

Streaming Responses

Function Calling

JSON Output Mode

Image Generation with Imagen

Text Embeddings

Using in a Flow

Configuration Options

Model Configuration

Safety Settings

Control content filtering:

System Instructions

Model Selection Guide

When to Use Each Model

gemini-2.5-flash (recommended default):
  • General-purpose tasks
  • Chat applications
  • Content generation
  • Code assistance
  • Balanced cost and performance
gemini-2.5-pro:
  • Complex reasoning tasks
  • Research and analysis
  • Technical explanations
  • When accuracy is critical
gemini-2.5-flash-lite:
  • Simple queries
  • High-volume applications
  • When speed is critical
  • Cost-sensitive use cases

Google AI vs Vertex AI

Choose Google AI when:
  • Building prototypes or small projects
  • Want quick setup with minimal configuration
  • Don’t need advanced GCP integrations
Choose Vertex AI when:
  • Building production applications
  • Need IAM-based access control
  • Want to use Model Garden (Anthropic, Meta, etc.)
  • Need Vector Search for RAG
  • Require enterprise features

Using Both Providers

You can configure both Google AI and Vertex AI in the same application:

Troubleshooting

API Key Not Found

Solution: Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable, or pass it explicitly:

Rate Limiting

If you hit rate limits, the API will return a 429 error. Implement exponential backoff:

Content Blocked by Safety Filters

If your content is blocked, adjust safety settings or rephrase your prompt:

Best Practices

  1. Use environment variables for API keys, never hardcode them
  2. Set appropriate safety settings for your use case
  3. Use gemini-2.5-flash as your default model
  4. Implement error handling for API failures
  5. Cache embeddings to avoid redundant API calls
  6. Use streaming for better user experience with long responses

Next Steps