Model Recommendations
Google has rate limits on their APIs. See the docs for more information.
Installation
Authentication
There are two ways to use the Gemini class: via Google AI Studio (usingGOOGLE_API_KEY) or via Vertex AI (using Google Cloud credentials).
Google AI Studio
Set theGOOGLE_API_KEY environment variable. You can get one from Google AI Studio.
Vertex AI
To use Vertex AI in Google Cloud:- Refer to the Vertex AI documentation to set up a project and development environment.
-
Install the
gcloudCLI and authenticate (refer to the quickstart for more details):
- Enable Vertex AI API and set the project ID environment variable (alternatively, you can set
project_idin theAgentconfig):
Example
UseGemini with your Agent:
View more examples here.
Capabilities
Multimodal Input
Images, video, audio, PDFs
Image Generation
Generate and edit images
Grounding and Search
Real-time web grounding
File Search
Native RAG over documents
Speech Generation
Audio output responses
Thinking Models
Advanced reasoning
Multimodal Input
Gemini natively understands images, video, audio, and documents. See Google’s vision documentation for supported formats and limits.- Image input
- Video input
- Audio input
- PDF input
- GCS file input (direct GCS access, up to 2GB)
- External URL input (up to 100MB)
- S3 pre-signed URL
Image Generation
Generate and edit images using Gemini’s native image generation. See Google’s image generation documentation for more details.Grounding and Search
Gemini models support grounding and search capabilities that enable real-time web access. See more details in Google’s documentation. Enable web search by settingsearch=True:
grounding=True instead:
Vertex AI Search
Search over your private knowledge base using Vertex AI. See Vertex AI Search documentation for setup details.URL Context
Extract and analyze content from URLs. See Google’s URL context documentation for more details.File Search
Gemini’s File Search enables RAG over your documents with automatic chunking and retrieval. See Google’s File Search documentation for more details.Speech Generation
Generate audio responses from the model. See Google’s speech generation documentation for available voices and options.Context Caching
Cache large contexts to reduce costs and latency. See Google’s context caching documentation for more details.Thinking Models
Gemini 2.5+ models support extended thinking for complex reasoning tasks. See Google’s thinking documentation for more details.thinking_level for simpler control:
Structured Outputs
Gemini supports native structured outputs using Pydantic models:Tool Use
Gemini supports function calling to interact with external tools and APIs:Params
Gemini is a subclass of the Model class and has access to the same params.