Skip to content

Google Cloud

Use Gemini and other supported Model Garden models through GoogleModel, or Claude through AnthropicModel. Google Cloud’s model APIs are also known as Vertex AI.

ModelsConfigurationModel selection
GeminiGoogleCloudProvidergoogle-cloud:<model-name>
Model Garden models with a generateContent APIModel GardenGoogleModel with GoogleCloudProvider
ClaudeAnthropic client for Vertex AIAnthropicModel with AnthropicProvider

For Gemini through Google AI Studio instead, see Google’s Gemini API.

Install

For Gemini and Model Garden models using GoogleModel, install the google optional group:

Terminal
pip install "pydantic-ai-slim[google]"

Authentication

Compared to the Gemini API, Gemini on Google Cloud has a number of advantages:

  1. The Google Cloud API comes with more enterprise readiness guarantees.
  2. You can purchase provisioned throughput with Google Cloud to guarantee capacity.
  3. If you’re running Pydantic AI inside Google Cloud, you don’t need to set up authentication, it should “just work”.
  4. You can decide which region to use, which might be important from a regulatory perspective, and might improve latency.

You can authenticate using application default credentials, a service account, or an API key.

Whichever way you authenticate, you’ll need to have the Vertex AI API (now branded as Google Cloud AI) enabled in your Google Cloud account.

Application Default Credentials

If you’ve set up application default credentials, for example by running gcloud auth application-default login with the gcloud CLI, or you’re running on Google Cloud, you can use the GoogleCloudProvider by name:

from pydantic_ai import Agent

agent = Agent('google-cloud:gemini-3.7-flash')
...

Or you can explicitly create the provider and model:

from pydantic_ai import Agent
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google_cloud import GoogleCloudProvider

provider = GoogleCloudProvider()
model = GoogleModel('gemini-3.7-flash', provider=provider)
agent = Agent(model)
...

Service Account

To use a service account JSON file, explicitly create the provider and model:

google_model_service_account.py
from google.oauth2 import service_account

from pydantic_ai import Agent
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google_cloud import GoogleCloudProvider

credentials = service_account.Credentials.from_service_account_file('path/to/service-account.json')
provider = GoogleCloudProvider(credentials=credentials, project='your-project-id')
model = GoogleModel('gemini-3.7-flash', provider=provider)
agent = Agent(model)
...

API Key

To use Google Cloud with an API key, create a key and set it as an environment variable:

Terminal
export GOOGLE_API_KEY=your-api-key

You can then use GoogleModel via GoogleCloudProvider by name:

from pydantic_ai import Agent

agent = Agent('google-cloud:gemini-3.7-flash')
...

Or you can explicitly create the provider and model:

from pydantic_ai import Agent
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google_cloud import GoogleCloudProvider

provider = GoogleCloudProvider(api_key='your-api-key')
model = GoogleModel('gemini-3.7-flash', provider=provider)
agent = Agent(model)
...

Customizing Location or Project

You can specify the location and/or project when using Google Cloud:

google_model_location.py
from pydantic_ai import Agent
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google_cloud import GoogleCloudProvider

provider = GoogleCloudProvider(location='global', project='your-google-cloud-project-id')
model = GoogleModel('gemini-3.7-flash', provider=provider)
agent = Agent(model)
...

In addition to the single-region values listed in GoogleCloudLocation, GoogleCloudProvider accepts the 'global' location and the 'us'/'eu' multi-regions. The multi-region values are routed to the aiplatform.{us,eu}.rep.googleapis.com data-residency endpoints — use them when an org policy blocks the global endpoint for data residency, or when a model is initially available only on global and the multi-regions rather than a single region. Model availability differs between single regions, multi-regions, and global; see the Vertex AI locations docs.

google_model_multi_region.py
from pydantic_ai import Agent
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google_cloud import GoogleCloudProvider

provider = GoogleCloudProvider(location='us', project='your-google-cloud-project-id')
model = GoogleModel('gemini-3.7-flash', provider=provider)
agent = Agent(model)
...

Model Garden

You can access models from the Model Garden that support the generateContent API and are available under your Google Cloud project, including but not limited to Gemini, using one of the following model_name patterns:

  • {model_id} for Gemini models
  • {publisher}/{model_id}
  • publishers/{publisher}/models/{model_id}
  • projects/{project}/locations/{location}/publishers/{publisher}/models/{model_id}
from pydantic_ai import Agent
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google_cloud import GoogleCloudProvider

provider = GoogleCloudProvider(
    project='your-google-cloud-project-id',
    location='us-central1',  # the region where the model is available
)
model = GoogleModel('meta/llama-3.3-70b-instruct-maas', provider=provider)
agent = Agent(model)
...

Model settings and features

Gemini on Google Cloud uses the same GoogleModelSettings as the Gemini API. See the Google model guide for thinking, safety settings, multimodal inputs, and context caching, including differences between the two services.

Google Cloud also supports service tiers and provisioned throughput and Model Armor.

Claude on Google Cloud

For Claude, install the anthropic optional group and pass an AsyncAnthropicVertex client to AnthropicProvider. See Claude on Google Cloud for the setup example. This uses Anthropic’s Messages API, so configure it with Anthropic model settings.