Use Google’s Gemini models through Google AI Studio - a platform providing access to large language models. Learn more here.

We recommend experimenting to find the best-suited model for your use-case. Here are some general recommendations:

  • gemini-1.5-flash is good for most use-cases.
  • gemini-1.5-flash-8b is their most cost-effective model.
  • gemini-2.0-flash-exp is their strongest multi-modal model.

Authentication

You can use Gemini models through either Google AI Studio or Google Cloud’s Vertex AI:

Google AI Studio

Set your GOOGLE_API_KEY environment variable. You can get one from Google here.

export GOOGLE_API_KEY=***

Vertex AI

To use Vertex AI:

  1. Install Google Cloud CLI and authenticate:
gcloud auth application-default login
  1. Set your project ID (optional if GOOGLE_CLOUD_PROJECT is set):
export GOOGLE_CLOUD_PROJECT=your-project-id

Example

Use Gemini with your Agent:

from agno.agent import Agent
from agno.models.google import Gemini

# Using Google AI Studio
agent = Agent(
    model=Gemini(id="gemini-1.5-flash"),
    markdown=True,
)

# Or using Vertex AI
agent = Agent(
    model=Gemini(
        id="gemini-1.5-flash",
        vertexai=True,
        project_id="your-project-id",  # Optional if GOOGLE_CLOUD_PROJECT is set
        location="us-central1",  # Optional
    ),
    markdown=True,
)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story.")
View more examples here.

Gemini models support grounding and search capabilities through optional parameters. This automatically sends tools for grounding or search to Gemini. See more details here.

To enable these features, set the corresponding parameter when initializing the Gemini model:

To use grounding:

from agno.agent import Agent
from agno.models.google import Gemini

agent = Agent(
    model=Gemini(id="gemini-2.0-flash-exp", grounding=True),
    show_tool_calls=True,
    markdown=True,
)

agent.print_response("Any news from USA?")

To use search:

from agno.agent import Agent
from agno.models.google import Gemini

agent = Agent(
    model=Gemini(id="gemini-2.0-flash-exp", search=True),
    show_tool_calls=True,
    markdown=True,
)

agent.print_response("What's happening in France?")

Set show_tool_calls=True in your Agent configuration to see the grounding or search results in the output.

Parameters

ParameterTypeDefaultDescription
idstr"gemini-2.0-flash-exp"The specific Gemini model ID to use.
namestr"Gemini"The name of this Gemini model instance.
providerstr"Google"The provider of the model.
function_declarationsOptional[List[FunctionDeclaration]]NoneList of function declarations for the model.
generation_configOptional[Any]NoneConfiguration for text generation.
safety_settingsOptional[Any]NoneSafety settings for the model.
generative_model_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for the generative model.
groundingboolFalseWhether to use grounding.
searchboolFalseWhether to use search.
grounding_dynamic_thresholdOptional[float]NoneThe dynamic threshold for grounding.
api_keyOptional[str]NoneAPI key for authentication.
vertexaiboolFalseWhether to use Vertex AI instead of Google AI Studio.
project_idOptional[str]NoneGoogle Cloud project ID for Vertex AI.
locationOptional[str]NoneGoogle Cloud region for Vertex AI.
client_paramsOptional[Dict[str, Any]]NoneAdditional parameters for the client.
clientOptional[GeminiClient]NoneThe underlying generative model client.
temperatureOptional[float]NoneControls randomness in the output. Higher values (e.g., 0.8) make the output more random, while lower values (e.g., 0.2) make it more focused and deterministic.
top_pOptional[float]NoneNucleus sampling parameter. Only consider tokens whose cumulative probability exceeds this value.
top_kOptional[int]NoneOnly consider the top k tokens for text generation.
max_output_tokensOptional[int]NoneThe maximum number of tokens to generate in the response.
stop_sequencesOptional[list[str]]NoneList of sequences where the model should stop generating further tokens.
logprobsOptional[bool]NoneWhether to return log probabilities of the output tokens.
presence_penaltyOptional[float]NonePenalizes new tokens based on whether they appear in the text so far.
frequency_penaltyOptional[float]NonePenalizes new tokens based on their frequency in the text so far.
seedOptional[int]NoneRandom seed for deterministic text generation.
request_paramsOptional[Dict[str, Any]]NoneAdditional parameters for the request.

Gemini is a subclass of the Model class and has access to the same params.