Model Recommendations
| Model | Best For | Key Strengths |
|---|---|---|
gemini-2.0-flash | Most use-cases | Balanced speed and intelligence |
gemini-2.0-flash-lite | High-volume tasks | Most cost-effective |
gemini-2.5-pro | Complex tasks | Advanced reasoning, largest context |
gemini-3-pro-preview | Latest features | Thought signatures support |
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 & 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 Generation
Generate and edit images using Gemini’s native image generation. See Google’s image generation documentation for more details.Grounding & 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
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "gemini-2.0-flash-001" | The id of the Gemini model to use |
name | str | "Gemini" | The name of the model |
provider | str | "Google" | The provider of the model |
api_key | Optional[str] | None | Google API key (defaults to GOOGLE_API_KEY env var) |
vertexai | bool | False | Use Vertex AI instead of AI Studio |
project_id | Optional[str] | None | Google Cloud project ID for Vertex AI |
location | Optional[str] | None | Google Cloud region for Vertex AI |
temperature | Optional[float] | None | Controls randomness in the model’s output |
top_p | Optional[float] | None | Controls diversity via nucleus sampling |
top_k | Optional[int] | None | Controls diversity via top-k sampling |
max_output_tokens | Optional[int] | None | Maximum number of tokens to generate |
stop_sequences | Optional[list[str]] | None | Sequences where the model should stop generating |
seed | Optional[int] | None | Random seed for reproducibility |
logprobs | Optional[bool] | None | Whether to return log probabilities of output tokens |
presence_penalty | Optional[float] | None | Penalizes new tokens based on whether they appear in the text so far |
frequency_penalty | Optional[float] | None | Penalizes new tokens based on their frequency in the text so far |
search | bool | False | Enable Google Search grounding |
grounding | bool | False | Enable legacy grounding (use search for 2.0+) |
grounding_dynamic_threshold | Optional[float] | None | Dynamic threshold for grounding |
url_context | bool | False | Enable URL context extraction |
vertexai_search | bool | False | Enable Vertex AI Search |
vertexai_search_datastore | Optional[str] | None | Vertex AI Search datastore path |
file_search_store_names | Optional[list[str]] | None | File Search store names for RAG |
file_search_metadata_filter | Optional[str] | None | Metadata filter for File Search |
response_modalities | Optional[list[str]] | None | Output types: "TEXT", "IMAGE", "AUDIO" |
speech_config | Optional[dict] | None | TTS voice configuration |
thinking_budget | Optional[int] | None | Token budget for reasoning (Gemini 2.5+) |
include_thoughts | Optional[bool] | None | Include thought summaries in response |
thinking_level | Optional[str] | None | Thinking intensity: "low" or "high" |
cached_content | Optional[Any] | None | Reference to cached context |
safety_settings | Optional[list] | None | Content safety configuration |
function_declarations | Optional[List[Any]] | None | List of function declarations for the model |
generation_config | Optional[Any] | None | Custom generation configuration |
generative_model_kwargs | Optional[Dict[str, Any]] | None | Additional keyword arguments for the generative model |
request_params | Optional[Dict[str, Any]] | None | Additional parameters for the request |
client_params | Optional[Dict[str, Any]] | None | Additional parameters for client configuration |
Gemini is a subclass of the Model class and has access to the same params.