Vertex AI
Authenticate Gemini against Vertex AI with environment variables or explicit `project_id` and `location` parameters on the Gemini model.
"""
To use Vertex AI, with the Gemini Model class, you need to set the following environment variables:
export GOOGLE_GENAI_USE_VERTEXAI="true"
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_LOCATION="your-location"
Or you can set the following parameters in the `Gemini` class:
gemini = Gemini(
vertexai=True,
project_id="your-google-cloud-project-id",
location="your-google-cloud-location",
)
"""
from agno.agent import Agent, RunOutput # noqa
from agno.models.google import Gemini
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(model=Gemini(id="gemini-3.7-flash"), markdown=True)
# Get the response in a variable
# run: RunOutput = agent.run("Share a 2 sentence horror story")
# print(run.content)
# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story")
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passRun the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno google-genaiExport environment variables
export GOOGLE_CLOUD_LOCATION="global"
export GOOGLE_CLOUD_PROJECT="your_google_cloud_project_here"
export GOOGLE_GENAI_USE_VERTEXAI="true"Authenticate with Google Cloud
Sign in with Application Default Credentials:
gcloud auth application-default loginRun the example
Save the code above as vertexai.py, then run:
python vertexai.pyFull source: cookbook/90_models/google/gemini/vertexai.py