Skip to content

Google Vertex AI Setup

Deploy Claude Code with Google Cloud's Vertex AI for enterprise-grade AI capabilities.

Prerequisites

Before setup, ensure you have:

  • A GCP account with billing enabled
  • A GCP project with Vertex AI API enabled
  • Access to desired Claude models (e.g., Claude Sonnet 4.5)
  • Google Cloud SDK (gcloud) installed and configured
  • Quota allocated in your desired GCP region

Quick Setup

bash
# 1. Set your project
gcloud config set project YOUR-PROJECT-ID

# 2. Enable Vertex AI API
gcloud services enable aiplatform.googleapis.com

# 3. Configure Claude Code
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=YOUR-PROJECT-ID

Step-by-Step Setup

Step 1: Enable Vertex AI API

bash
# Set your project ID
gcloud config set project YOUR-PROJECT-ID

# Enable Vertex AI API
gcloud services enable aiplatform.googleapis.com

Step 2: Request Model Access

  1. Navigate to the Vertex AI Model Garden in GCP Console
  2. Search for "Claude" models
  3. Request access to desired Claude models
  4. Wait for approval (may take 24-48 hours)

Step 3: Configure GCP Credentials

Claude Code uses standard Google Cloud authentication. Set environment variables:

VariablePurpose
ANTHROPIC_VERTEX_PROJECT_IDYour GCP project ID
GCLOUD_PROJECTAlternative project ID variable
GOOGLE_CLOUD_PROJECTAlternative project ID variable
GOOGLE_APPLICATION_CREDENTIALSPath to service account JSON

Step 4: Configure Claude Code

bash
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=YOUR-PROJECT-ID
export DISABLE_PROMPT_CACHING=1

Step 5: Region Configuration

Override regions for specific models if needed:

bash
export VERTEX_REGION_CLAUDE_3_5_HAIKU=us-east5
export VERTEX_REGION_CLAUDE_3_5_SONNET=us-east5
export VERTEX_REGION_CLAUDE_3_7_SONNET=us-east5
export VERTEX_REGION_CLAUDE_4_0_OPUS=europe-west1
export VERTEX_REGION_CLAUDE_4_0_SONNET=us-east5

Model Configuration

Default Models

TypeModel ID
Primaryclaude-sonnet-4-5@20250929
Small/Fastclaude-haiku-4-5@20251001

Custom Models

bash
export ANTHROPIC_MODEL='claude-opus-4-1@20250805'
export ANTHROPIC_SMALL_FAST_MODEL='claude-haiku-4-5@20251001'

IAM Configuration

Assign the roles/aiplatform.user role which includes:

  • aiplatform.endpoints.predict - Model invocation
  • Token counting permissions

1M Token Context Window

Claude Sonnet 4 and 4.5 support 1M token context on Vertex AI (beta).

Include the context-1m-2025-08-07 beta header in requests.

Troubleshooting

Quota Issues

  • Check current quotas in Cloud Console
  • Request increases through IAM & Admin > Quotas

Model Not Found (404)

  • Confirm model is enabled in Model Garden
  • Verify access to the specified region

429 Rate Limit Errors

  • Ensure models are supported in your region
  • Switch to CLOUD_ML_REGION=global

Complete Configuration Example

bash
# ~/.bashrc or ~/.zshrc
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=my-gcp-project
export DISABLE_PROMPT_CACHING=1
export ANTHROPIC_MODEL='claude-sonnet-4-5@20250929'
export ANTHROPIC_SMALL_FAST_MODEL='claude-haiku-4-5@20251001'

Next Steps

Claude Code Documentation Hub