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
- Visit Google AI Studio
- Create or select a project
- Generate an API key
- 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
- 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
- Complex reasoning tasks
- Research and analysis
- Technical explanations
- When accuracy is critical
- Simple queries
- High-volume applications
- When speed is critical
- Cost-sensitive use cases
Google AI vs Vertex AI
| Feature | Google AI | Vertex AI |
|---|---|---|
| Setup | Simple API key | GCP project + IAM |
| Best for | Prototyping, small apps | Production, enterprise |
| Authentication | API key | ADC or API key |
| Pricing | Pay-per-use | Committed use discounts |
| Model access | Gemini, Imagen | Gemini, Imagen, Lyria, Model Garden |
| Features | Basic | Advanced (fine-tuning, governance, Vector Search) |
- Building prototypes or small projects
- Want quick setup with minimal configuration
- Don’t need advanced GCP integrations
- 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
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
- Use environment variables for API keys, never hardcode them
- Set appropriate safety settings for your use case
- Use gemini-2.5-flash as your default model
- Implement error handling for API failures
- Cache embeddings to avoid redundant API calls
- Use streaming for better user experience with long responses
Next Steps
- Vertex AI Provider - Enterprise features and Model Garden
- Prompt Engineering - Write better prompts
- Flows - Build AI workflows
- RAG - Retrieval-augmented generation