Use Google’s Gemini models through Google AI Studio or Google Cloud Vertex AI - platforms that provide access to large language models and other services.

We recommend experimenting to find the best-suited model for your use case. Here are some general recommendations in the Gemini 2.x family of models:

  • gemini-2.0-flash is good for most use-cases.
  • gemini-2.0-flash-lite is the most cost-effective model.
  • gemini-2.5-pro-exp-03-25 is the strongest multi-modal model.

Refer to the Google AI Studio documentation and the Vertex AI documentation for information on available model versions.

Authentication

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

Google AI Studio

Set the GOOGLE_API_KEY environment variable. You can get one from Google AI Studio.

export GOOGLE_API_KEY=***

Vertex AI

To use Vertex AI in Google Cloud:

  1. Refer to the Vertex AI documentation to set up a project and development environment.

  2. Install the gcloud CLI and authenticate (refer to the quickstart for more details):

gcloud auth application-default login
  1. Enable Vertex AI API and set the project ID environment variable (alternatively, you can set project_id in the Agent config):

Export the following variables:

export GOOGLE_GENAI_USE_VERTEXAI="true"
export GOOGLE_CLOUD_PROJECT="your-gcloud-project-id"
export GOOGLE_CLOUD_LOCATION="your-gcloud-location"

Or update your Agent configuration:

agent = Agent(
    model=Gemini(
        id="gemini-1.5-flash",
        vertexai=True,
        project_id="your-gcloud-project-id",
        location="your-gcloud-location",
    ),
)

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-2.0-flash"),
    markdown=True,
)

# Or using Vertex AI
agent = Agent(
    model=Gemini(
        id="gemini-2.0-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", 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", 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.