Blank white background with no objects or features visible.

We’re sharing complimentary access to the full Gartner Hype Cycle for AI Governance 2026. Get your copy →

Vercel AI Gateway With Claude Code: Setup Guide

By Sahajmeet Kaur

Published: October 21, 2026

Claude Code lets developers write, debug, and refactor code using AI directly from the terminal. But when you want to monitor usage, switch between model providers, or manage AI traffic through a shared endpoint, connecting Claude Code to an AI gateway can make that workflow easier to manage.

Vercel AI Gateway provides an Anthropic-compatible endpoint that lets you route Claude Code requests through its gateway without changing your usual terminal workflow. Once configured, you can monitor token usage and spending, inspect request traces, and use supported model-routing and provider-fallback capabilities from the Vercel dashboard.

For individual developers, this provides a convenient way to centralize model access and usage visibility. For engineering teams, it also raises a broader question: when do gateway-level monitoring and routing need to extend into organization-wide access controls, governance, and deployment requirements?

This guide walks through connecting Claude Code to Vercel AI Gateway, configuring authentication, verifying requests, troubleshooting common errors, and evaluating when an enterprise AI Gateway such as TrueFoundry may be a better fit.

What Is AI Gateway for Claude Code?

AI Gateway is a unified interface for accessing models from different providers through a common API. It provides model routing, usage and spend monitoring, request observability, and supported provider-fallback options.

Claude Code normally connects to Anthropic's API. AI Gateway allows you to redirect those requests through its Anthropic-compatible endpoint instead, so you can continue using Claude Code from your terminal while Vercel handles the gateway-side routing and monitoring.

The connection uses three environment variables:

  • ANTHROPIC_BASE_URL specifies the AI Gateway endpoint.
  • ANTHROPIC_AUTH_TOKEN supplies your AI Gateway API key.
  • ANTHROPIC_API_KEY is set to an empty string to prevent a non-empty Anthropic API key from taking precedence over the gateway token.

Once configured, Claude Code sends supported requests through Vercel AI Gateway rather than directly to Anthropic.

Why Use AI Gateway With Claude Code?

Unified model access: Route supported requests through a common gateway instead of configuring a separate endpoint for every provider.

Usage and spend monitoring: View model usage and spending through Vercel AI Gateway's dashboard, helping you understand how coding-agent sessions consume tokens.

Request observability: Inspect detailed traces and metrics to investigate request behavior and troubleshoot problems.

Provider fallback: Use supported fallback configurations to improve resilience when a provider or model endpoint encounters an error.

A familiar developer workflow: Continue launching Claude Code from the terminal without integrating a separate SDK into your project.

These capabilities make AI Gateway useful when you want a more centralized view of model traffic without changing how you interact with Claude Code.

However, routing and observability are only part of the picture for organizations deploying coding agents across multiple teams. Requirements such as centralized identity policies, team-level cost attribution, guardrails, and infrastructure control may call for a broader enterprise gateway strategy.

Govern Claude Code at Scale With TrueFoundry AI Gateway

Connect Claude Code and other AI applications through TrueFoundry AI Gateway. Centralize model access, track usage and costs, apply guardrails, and manage AI traffic across your organization.

  • ✓ Centralized access and RBAC
  • ✓ Cost visibility and budgets
  • ✓ Observability and guardrails

Prerequisites

Before connecting Claude Code to Vercel AI Gateway, make sure you have:

  • Claude Code installed: Follow the official installation guide.
  • A Vercel account: Sign in to Vercel.
  • An AI Gateway API key: Create or obtain a key through Vercel AI Gateway.
  • Terminal access: You'll configure environment variables in your shell.

How to Connect Claude Code to Vercel AI Gateway

Step 1: Configure the environment variables

Open your terminal and set the gateway endpoint and authentication token. Replace the placeholder with your actual Vercel AI Gateway API key.

export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh"
export ANTHROPIC_AUTH_TOKEN="your-vercel-ai-gateway-api-key"
export ANTHROPIC_API_KEY=""

These variables direct Claude Code requests to Vercel AI Gateway and use your gateway key for authentication.

Step 2: Start Claude Code

Navigate to your project directory and launch Claude Code:

cd /path/to/your/project
claude

Replace /path/to/your/project with the path to your actual project.

Step 3: Verify the connection

Inside Claude Code, run:

/status

Check that the session reflects your gateway configuration. You can also inspect Vercel AI Gateway's dashboard after sending a test prompt to confirm that requests are appearing.

For persistent configuration, you can add the environment variables to your shell configuration file, such as ~/.zshrc or ~/.bashrc, and reload it with source ~/.zshrc or source ~/.bashrc.

How to Monitor Usage and Switch Models

Once Claude Code is routing requests through Vercel AI Gateway, you can use the Vercel dashboard to inspect model usage, track spending, and investigate individual requests.

Monitor token usage and costs

Open your Vercel dashboard and navigate to AI Gateway. The Overview and Observability sections let you review usage metrics and inspect request traces.

Switch models in Claude Code

Vercel AI Gateway supports access to different models through a common endpoint. With Claude Code configured to use the gateway, you can use the model picker to switch between supported Claude models.

Inside Claude Code, run:

/model

Choose an available model from the picker. Model availability depends on the gateway catalog and your configuration.

If you want to use a different provider's model, check its compatibility with Claude Code before relying on it for tool-heavy coding workflows. A model being available through the gateway doesn't guarantee that every Claude Code feature will work with it.

Keep gateway credentials secure

For a quick test, environment variables in your current terminal are sufficient. For repeated use, store the configuration in your shell profile or use a dedicated key with appropriate spending limits.

Avoid putting API keys in source-controlled project files. If you use Claude Code Max with Vercel AI Gateway, follow Vercel's separate subscription configuration instead of mixing it with the API-key setup above.

Where Teams Hit Limits With Vercel AI Gateway

For individual developers and teams already on Vercel, this setup is genuinely good: fast to configure, list-price tokens, and more spend control than most hosted gateways. The limits show up when Claude Code becomes an organization-wide rollout.

1. It Runs Only on Vercel's Infrastructure

Vercel states plainly that AI Gateway isn't self-hostable. If the gateway must run inside your VPC, on-prem, or air-gapped, this isn't the option. Regional inference controls where the provider runs a request (US, EU, Australia, or Japan), but it's opt-in, and Claude Code can only use it through a virtual model.

2. It Governs Model Calls, Not Tool Calls

Claude Code connects to MCP servers for GitHub, databases, and internal tools. Asked whether AI Gateway can be your MCP gateway, Vercel's own FAQ says no: tool-level access control belongs in a separate layer. If security wants to control which MCP servers developers reach from their laptops, you'll need another layer. We cover the options in our guide to the best MCP gateway for Claude Code.

3. Guardrails Sit Outside the Gateway

Vercel's security and compliance controls focus on data handling: zero data retention, no prompt training, and provider and model allowlists. Inspecting or blocking prompts, PII, and Claude Code's tool calls is something you'd add separately.

4. Identity Runs Through API Keys

Per-user budgets work through key attribution: a key counts toward the member who created it. At hundreds of engineers, that likely means distributing and rotating individual keys rather than authenticating developers through the SSO your company already runs

Vercel AI Gateway handles model access and spend visibility well. But once Claude Code is part of how your engineering organization works, platform teams need control over who can use which models, which tools agents can reach, and what happens to prompts and tool calls in between.

Govern Claude Code at Scale With TrueFoundry AI Gateway

TrueFoundry AI Gateway gives you a Claude Code gateway your platform team controls: one control plane for model access, MCP governance, guardrails, and cost attribution, deployed wherever your infrastructure lives.

Pointing Claude Code at TrueFoundry

Pointing Claude Code at our gateway is the same kind of change you just made. In API-key mode, swap the base URL and token in settings.json

{
  "env": {
    "ANTHROPIC_BASE_URL": "{GATEWAY_BASE_URL}",
    "ANTHROPIC_AUTH_TOKEN": "your-truefoundry-api-key",
    "ANTHROPIC_MODEL": "claude-code/claude-sonnet",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-code/claude-opus",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-code/claude-sonnet",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-code/claude-haiku",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1",
    "ANTHROPIC_CUSTOM_HEADERS": "x-tfy-anthropic-beta: context-management-2025-06-27"
  }
}

Here's what each variable does:

  • ANTHROPIC_BASE_URL is your gateway base URL, from the Playground's unified code snippet.
  • ANTHROPIC_AUTH_TOKEN is your TrueFoundry key, which identifies the user. The Anthropic, Bedrock, or Vertex credential stays on the gateway, never on the laptop.
  • ANTHROPIC_MODEL and the ANTHROPIC_DEFAULT_*_MODEL variables map Claude Code's opus, sonnet, and haiku aliases to gateway models in provider-account/model-name format.
  • CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS keeps behavior stable across providers, while ANTHROPIC_CUSTOM_HEADERS forwards specific Anthropic betas through x-tfy-anthropic-beta.

Send a prompt, and it appears in AI Gateway → Analytics under your user, with model, tokens, and cost. Full setup is in our Claude Code documentation.

What We Add for Claude Code

  • Two billing modes, one gateway: API-key mode for one org bill, or subscription passthrough so Claude Enterprise, Team, Pro, or Max seats keep paying. A virtual model can fall back from the subscription to a pay-per-token account when the seat hits its limit.
  • MCP governance in the same platform: Route Claude Code's MCP servers through the TrueFoundry MCP Gateway, with allowlists, authentication, and audit.
  • Guardrails on prompts and tool calls: Gateway guardrails cover PII, prompt injection, and moderation. Claude Code hooks extend that to shell commands, file edits, and MCP tool calls, which the gateway can block or rewrite.
  • Fleet-wide enforcement: tfy-local-ai-setup writes a locked managed-settings.json with a per-user token, distributed through MDM.
  • Enterprise identity and access: SSO and RBAC, so access follows the identity provider your company already uses, with audit logging on every request.
  • Deployment where your infrastructure lives: Run the gateway in your VPC, on-prem, hybrid, or air-gapped, with SOC 2, HIPAA, and GDPR compliance.
  • Broad model access with minimal overhead: 1,600+ models through one gateway, with sub-3 ms internal latency.

Vercel AI Gateway vs TrueFoundry AI Gateway for Claude Code

Capability Vercel AI Gateway Unified model routing TrueFoundry AI Gateway Enterprise AI control plane
Claude Code setup Dedicated /claude-code endpoint and one-command CLI setup. settings.json environment block; fleet rollout through MDM andmanaged-settings.json.
Claude subscriptions Claude Max through ANTHROPIC_CUSTOM_HEADERS. Passthrough for Enterprise, Team, Pro, and Max, with fallback to API billing.
Spend controls Budgets per team, project, API key, and user. Per-user attribution, budgets, and rate limits.
Identity API keys, attributed to a member or the team. TrueFoundry key per user, SSO, and role-based access control (RBAC).
MCP governance Not an MCP Gateway, according to Vercel's own FAQ. Built-in MCP Gateway with allowlists, authentication, and audit capabilities.
Guardrails Data-handling controls, including zero data retention (ZDR), no prompt training, and allowlists. Gateway guardrails plus Claude Code hooks for prompts and tool calls.
Deployment Managed by Vercel; regional inference available as an opt-in. SaaS, VPC, on-premises, hybrid, or air-gapped deployment options.

Conclusion

Using Vercel AI Gateway with Claude Code is one of the simplest ways to put a gateway in front of your coding agent. One CLI command configures the endpoint, key, and model picker, and budgets give you real control over what coding agents spend. Just keep ANTHROPIC_API_KEY empty, leave /v1 off the base URL, remember that BYOK traffic sits outside your budgets, and verify with /status before you trust it.

If Claude Code is a tool for you and your team, that may be all you need. If you're rolling it out across an engineering organization, with MCP servers to govern, tool calls to inspect, and infrastructure that has to stay inside your network, learn how TrueFoundry AI Gateway handles Claude Code governance.

Frequently Asked Questions

Q: Does Vercel AI Gateway charge a markup on Claude tokens?

A: No. Vercel states that AI Gateway charges no markup and no platform fee on tokens, including with BYOK. You pay provider list price from prepaid credits; add-ons like Custom Reporting and Trace Drains are billed separately.

Q: Why does Claude Code return a 404 through Vercel AI Gateway?

A: Usually because the base URL ends in /v1. The Anthropic SDK appends /v1/messages itself, so the base URL should be exactly https://ai-gateway.vercel.sh/claude-code.

Q: Can I use my Claude Max subscription with Vercel AI Gateway?

A: Yes. Keep the Vercel base URL, log in with your Claude account, and send your AI Gateway key in a custom header: ANTHROPIC_CUSTOM_HEADERS="x-ai-gateway-api-key: Bearer your-ai-gateway-api-key". The Vercel CLI doesn't write this header, so set it manually.

Q: Can I deploy TrueFoundry in my own VPC or on-prem?

A: Yes. We support SaaS, VPC, on-prem, hybrid, and air-gapped deployments, so model and tool traffic can stay inside your infrastructure.

Q: Does TrueFoundry support MCP and AI agents?

A: Yes. Our MCP Gateway sits alongside the AI Gateway, so agents like Claude Code reach approved MCP servers with allowlists, authentication, and audit, under the same access controls as model traffic.

Q: How many LLMs does TrueFoundry support?

A: TrueFoundry AI Gateway gives you access to 1,600+ models through one gateway, with sub-3 ms internal latency, so routing Claude Code through it adds minimal overhead.

Q: Does TrueFoundry integrate with my existing observability stack?

A: Yes. The gateway records model, tokens, latency, and cost for every request per user, and traces can be exported to the observability tools you already run through OpenTelemetry [VERIFY: confirm the current list of supported export destinations with product].

Related reading

Try now.

One gateway for all your models, MCP servers, and agents.
No credit card needed.

Start free
Table of Contents

One Gateway for Every LLM, Agent and MCP Server

Book a 30-min with our AI expert

Book a Demo

The fastest way to build, govern and scale your AI

Book Demo
Summarize with
ChatGPT logo by OpenAI
Perplexity AI logo
Blurry red snowflake on white background, symmetrical frosty design with soft edges and abstract shape.

Discover More

No items found.
October 21, 2026
|
5 min read

How to Use Claude Code with Amazon Bedrock

No items found.
October 21, 2026
|
5 min read

How to Use OpenRouter in Claude Code: Setup Guide

No items found.
October 21, 2026
|
5 min read

Vercel AI Gateway With Claude Code: Setup Guide

No items found.
October 19, 2026
|
5 min read

AI Agent Identity: How to Secure and Manage AI Agents

No items found.
No items found.

Recent Blogs

Black left pointing arrow symbol on white background, directional indicator.
Black left pointing arrow symbol on white background, directional indicator.
Take a quick product tour
Start Product Tour
Product Tour