How to Run Claude Code on Vertex AI Using Your GCP Credits

Claude AI · Tygart Media
What this sets up: Claude Code running through your Google Cloud account instead of the Anthropic API. Same models, same capabilities — billed to GCP. New GCP accounts can run this for free using $300 in signup credits.

Claude Code is Anthropic’s terminal-native coding agent. By default it bills through your Anthropic account. But you can route it entirely through Google Cloud’s Vertex AI — meaning it charges your GCP account instead, and you can use existing GCP credits, startup credits, or free trial credits to run it at no incremental cost. Here’s the exact setup.

What You Need Before Starting

A Google Cloud account with a project created. Vertex AI API enabled on that project. Claude models requested and approved in Vertex AI Model Garden. Claude Code installed (npm install -g @anthropic-ai/claude-code). The gcloud CLI installed and authenticated. That’s it — no Anthropic API key required once this is configured.

Step 1: Enable Vertex AI and Request Claude Model Access

In the Google Cloud Console, go to Vertex AI > Model Garden and search for “Claude.” Request access to at least Claude Sonnet 4.6 (the primary Claude Code model) and Claude Haiku 4.5 (used for lightweight operations). Without Haiku, Claude Code will use Sonnet for everything — slower and more expensive for simple tasks. Enable Opus 4.6 as well if you need maximum capability for complex tasks.

Model access approval is typically instant for most GCP accounts.

Step 2: Authenticate with Google Cloud

Run both commands below — the first authenticates your user account, the second sets application default credentials that Claude Code will pick up automatically:

gcloud auth login
gcloud auth application-default login

Set your project: gcloud config set project YOUR-PROJECT-ID

Enable the Vertex AI API: gcloud services enable aiplatform.googleapis.com

Step 3: Configure Claude Code to Use Vertex AI

Set these environment variables. On macOS/Linux, add them to your ~/.zshrc or ~/.bashrc. On Windows, use PowerShell’s [System.Environment]::SetEnvironmentVariable at the User level so they persist across sessions.

macOS / Linux:
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=your-project-id
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5@20251001
Windows (PowerShell — run once, persists across sessions):
[System.Environment]::SetEnvironmentVariable("CLAUDE_CODE_USE_VERTEX","1","User")
[System.Environment]::SetEnvironmentVariable("CLOUD_ML_REGION","global","User")
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_VERTEX_PROJECT_ID","your-project-id","User")

Step 4: Verify the Setup

Launch Claude Code and run /status. You should see API provider: Google Vertex AI and your GCP project ID. If you see the Anthropic API provider instead, your environment variables haven’t loaded — restart your terminal and try again.

Step 5: Use the New Wizard (Claude Code v2.1.98+)

If you’re on Claude Code version 2.1.98 or later, you can skip manual environment variable setup. Run /setup-vertex inside Claude Code and the wizard walks you through project selection, region, and model pinning automatically. Run claude --version to check your version first.

Region Selection: Global vs Regional Endpoints

Use CLOUD_ML_REGION=global unless you have specific compliance reasons to pin to a region. Global endpoints get the latest models first, have better availability, and don’t incur the 10% regional pricing premium. If you need data residency in a specific geography, use us-east5, us-central1, or europe-west1 — but verify your target Claude models are available in that region first, as not all models are available in all regions.

Model Pinning for Teams

If you’re deploying Claude Code to multiple team members, pin specific model versions rather than using aliases. Model aliases like “sonnet” resolve to the latest version, which may not be enabled in your Vertex AI project when Anthropic ships an update. Pinning prevents silent failures on update day:

export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5@20251001

Common Error: 429 Resource Exhausted

If you see 429 errors after setup, your project’s Vertex AI quota for Claude models needs to be increased. Go to Cloud Console > IAM & Admin > Quotas, filter by “anthropic,” and request an increase for the models you’re using. Approvals are typically fast for standard business accounts.

Can I run Claude Code on Vertex AI for free?

Yes if you have unused GCP credits. New Google Cloud accounts receive $300 in free credits. All GCP credits — startup programs, free trial, committed use discounts — apply to Claude usage through Vertex AI.

Do I need an Anthropic API key to use Claude Code on Vertex AI?

No. When configured for Vertex AI, Claude Code authenticates through your Google Cloud credentials (gcloud). No Anthropic API key is needed or used.

Is Claude Code on Vertex AI slower than the direct Anthropic API?

In practice, latency is comparable. The global endpoint routes dynamically and generally performs well. Regional endpoints may add slight latency depending on your geographic distance from the selected region.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *