Use Claude on Vertex AI

Su Suriya Ravichandran Updated 10 Nov 2026
5 min read ·Lesson 162 of 200

Claude Inside Google Cloud

Google Cloud offers Claude through Vertex AI, which means model calls can run inside a Google Cloud project, under its billing, its identity controls, and its network policies. An organization that already builds on Google Cloud can add Claude without introducing a second provider's account. The SDK includes a Vertex client for this purpose, and it uses the same Messages API you have learned.

This lesson covers how the Vertex client is created, what a project and a region mean for each request, how authentication works through Google's standard credentials, and how to choose between the global endpoint and regional ones. It also includes a configuration check that catches the most common setup mistakes before the first call.


Project, Region, and Credentials

Three settings identify where a Vertex request runs:

SettingMeaningWhere it comes from
project_idThe Google Cloud project that is billed and that owns the requestYour project's identifier
regionWhere the request is processedGlobal, a multi-region group, or a specific region
CredentialsWho is making the requestGoogle's Application Default Credentials

The project identifier is not the project's display name. It is the identifier Google assigns, which follows specific rules for characters and length. The region controls which endpoint receives the request, and the credentials decide which identity the request uses.


Installing the Vertex Client

As with Bedrock, the Vertex client is an extra of the SDK, because it depends on Google's authentication libraries:

python -m pip install -U "anthropic[vertex]"

Creating the Client

The client takes the project and the region. Authentication is not passed in the code, because the Google client libraries find the credentials in the environment:

from anthropic import AnthropicVertex

client = AnthropicVertex(project_id="my-project-id", region="global")

message = client.messages.create(
    model="claude-opus-5",
    max_tokens=256,
    messages=[{"role": "user", "content": "Say hello."}],
)

Application Default Credentials are found in a fixed order: credentials set in the environment, the file that gcloud writes after a developer signs in, and the identity attached to the machine when it runs on Google Cloud. A deployed application normally uses the attached identity (Lesson 164), so no key file is needed.


Global Endpoints and Regions

The region setting selects one of three kinds of endpoint, and the choice affects where the request is processed and how much capacity is available:

SettingMeaning
"global"The global endpoint, which the documentation recommends
"us" or "eu"A multi-region group, which keeps processing within that geography
A specific region, such as "us-east5"Processing in one named region

The documentation's recommendation for the global endpoint reflects that it can route requests to wherever capacity is available. A regional setting keeps processing in one place, which matters when data residency rules require it. Model availability also varies by region, so a region chosen for residency must be checked for the model it needs before the project relies on it.


Validating the Configuration

A Vertex configuration fails in predictable ways: a project identifier with uppercase letters, a region written in the wrong form, or a model identifier that the chosen region does not offer. The check below covers the first two, which are shape problems. The third requires the platform's model list, which the check cannot know.

"""vertex_config.py: check a Vertex project identifier and region before use."""

import re

PROJECT = re.compile(r"^[a-z][a-z0-9-]{4,28}[a-z0-9]$")
REGION = re.compile(r"^[a-z]+-[a-z]+\d+$")
GROUPS = {"global", "us", "eu"}


def check_vertex(project_id: str, region: str) -> list[str]:
    problems = []
    if not PROJECT.match(project_id):
        problems.append(f"project id {project_id} does not follow Google Cloud's naming rules")
    if region not in GROUPS and not REGION.match(region):
        problems.append(f"region {region} is not global, us, eu, or a region name such as us-east5")
    return problems


if __name__ == "__main__":
    cases = [
        ("my-project-id", "global"),
        ("My_Project", "us-east5"),
        ("my-project-id", "us-east"),
    ]
    for number, (project_id, region) in enumerate(cases, start=1):
        print(f"case {number}:", check_vertex(project_id, region) or "ok")

Output:

case 1: ok
case 2: ["project id My_Project does not follow Google Cloud's naming rules"]
case 3: ['region us-east is not global, us, eu, or a region name such as us-east5']

How It Works

  1. The project pattern encodes Google's rules: a lowercase letter first, then lowercase letters, digits, or hyphens, and a final letter or digit, with a total length between six and thirty characters. My_Project fails on its uppercase letters and underscore.
  2. Region groups are accepted directly. global, us, and eu are checked by membership, so they never fall through to the pattern.
  3. The region pattern expects a name with letters, a hyphen, and a number at the end. us-east5 matches, because it has the letters us, the hyphen, east, and the number 5. us-east fails, because it ends in letters rather than a number.
  4. Case two shows only the project problem. Its region is a valid name, so the check correctly reports nothing about it.
  5. The check is a shape test, not a list of real regions. Whether a project has access to a given region, or whether a model is offered there, is only known from the platform itself.

Summary

Claude on Vertex AI runs inside a Google Cloud project, identified by its project identifier, processed in a region chosen from the global endpoint, a multi-region group, or a single region, and authenticated through Application Default Credentials. The Vertex client is installed as an extra and created with the project and region. Configuration checks catch shape errors before any request is made, and they are most useful when they state exactly which rule each value broke. The next lesson covers the third platform, Microsoft Foundry.

0 Comments

Reviewed before they appear

No comments yet.

Anthropic SDK Using Python
Anthropic SDK Intro Claude API Intro SDK Requirements Install Anthropic SDK Upgrade the SDK Create an API Key Set API Keys Use Environment Variables Import Anthropic Create a Client Send Your First Message Choose a Claude Model Set Max Tokens Read a Response Print Response Text Understand Message Blocks Use System Prompts Send User Messages Set Temperature Handle Stop Reasons Messages API Intro Create Messages Use Message Roles Send Conversation History Continue a Conversation Build a Chat Loop Reset Chat History Use Multiple Turns Inspect Message IDs Read Usage Data Write Clear Prompts Set a System Prompt Add Context to Prompts Use Prompt Templates Add Examples to Prompts Request JSON Output Use XML Tags Control Response Length Improve Prompt Quality Avoid Prompt Injection Read Text Blocks Read Content Blocks Check Stop Reasons Count Input Tokens Count Output Tokens Count Tokens Before Sending Limit Output Tokens Use Stop Sequences Read Request IDs Parse API Responses Streaming Intro Stream Text Output Use Stream Events Use Stream Helpers Get Final Messages Stream Async Responses Handle Stream Errors Build a Live Chat Stream Long Responses Close Streams Safely Build a Chatbot Keep Chat History Manage Chat Sessions Add Chat Memory Build a CLI Chatbot Build a Web Chatbot Use Flask with Claude Use FastAPI with Claude Return JSON from an API Add Chat Error Messages Async SDK Intro Create an Async Client Send Async Messages Use asyncio Run Parallel Requests Stream Async Text Handle Async Errors Set Async Timeouts Close Async Clients Choose Sync or Async Tool Use Intro Define a Tool Create Tool Schemas Send Tools to Claude Read Tool Calls Run Python Tools Return Tool Results Continue After Tool Use Control Tool Choice Handle Tool Errors Use the beta_tool Decorator Create a Tool Runner Add Tool Docstrings Validate Tool Inputs Use Multiple Tools Limit Tool Calls Log Tool Activity Build a Weather Tool Build a Search Tool Build a Calculator Tool Structured Output Intro Request JSON Data Validate JSON Output Use Pydantic Models Handle Invalid JSON Extract Fields from Text Generate Typed Data Use Image URLs Send Base64 Images Read PDFs with Claude Use Output Schemas Build Data Extraction Test Structured Responses Send Image Inputs Upload Files Use File IDs Process Text Files Summarize Documents Extract Table Data Handle File Errors Read Cache Usage Reduce Repeated Input Costs Debug Cache Misses Prompt Caching Intro Enable Prompt Caching Cache System Prompts Cache Long Context Test Cache Performance Use Cache Breakpoints Cache Best Practices Message Batches Intro Create a Message Batch Set Batch IDs Check Batch Status List Message Batches Get Batch Results Process Batch Outputs Handle Failed Batch Items Use Batches for Bulk Tasks Compare Batches and Requests Handle API Errors Handle Rate Limits Retry Failed Requests Set Request Timeouts Handle Network Errors Use Exponential Backoff Build Reliable API Calls Use Extended Thinking Log API Errors Track Request IDs Paginate API Results Set Thinking Budgets Read Thinking Blocks Use Tool Search Use Web Search Tools Use Computer Tools Use Citations Use Token Counting Read Raw Responses Set Custom Headers Use Claude on AWS Bedrock Use Claude on Vertex AI Use Claude on Microsoft Foundry Configure Cloud Credentials Choose a Cloud Provider Compare API Integrations Configure Provider Clients Handle Cloud Errors Use Cloud SDK Extras Deploy Cloud Apps Protect API Keys Use a .env File Ignore Secrets in Git Validate User Input Reduce Prompt Injection Limit Tool Permissions Avoid Unsafe Tool Calls Sanitize Tool Results Set Usage Limits Review Security Logs Test SDK Functions Mock API Responses Test Error Handling Test Streaming Code Measure Token Usage Track API Costs Configure Logging Deploy with Docker Deploy a FastAPI App Monitor Production Apps Build a Claude Chatbot Build a Text Summarizer Build a Code Explainer Build a JSON Extractor Build a PDF Assistant Build a Streaming Chat App Build a Tool-Calling Agent Build a Batch Processor Build a Research Assistant Build a Claude API Dashboard
Ask about this post
AI Ask about this post

Ask questions about Use Claude on Vertex AI and get answers drawn from it.

Signed-in readers only.