Vercel Logo

How Do I Run Claude Code Through the Gateway?

Claude Code can use AI Gateway without changing the way you work in the terminal. The connection lives in environment variables, outside the repository.

Quick Answer

Set ANTHROPIC_BASE_URL to https://ai-gateway.vercel.sh, pass a Gateway key through ANTHROPIC_AUTH_TOKEN, and leave ANTHROPIC_API_KEY empty. Start Claude Code from that environment and use a dedicated Gateway key with its own budget.

Outcome

Run a harmless Claude Code task through the Gateway configuration without exposing the credential in the project.

Fast Track

  1. Create a dedicated, budgeted Gateway key for Claude Code
  2. Configure the three environment variables below
  3. Start Claude Code and run a small read-only task

Hands-on exercise

Use a throwaway repository with a small file such as demo.ts. Configure the environment before starting Claude Code:

shell configuration
export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh"
export ANTHROPIC_AUTH_TOKEN="$AI_GATEWAY_API_KEY"
export ANTHROPIC_API_KEY=""

ANTHROPIC_AUTH_TOKEN carries the Gateway key. Leaving ANTHROPIC_API_KEY empty prevents Claude Code from selecting that credential path instead.

Keep the real token out of shell screenshots, recordings, and source control. A prepared example with [redacted] is safer than opening a live shell profile.

Try It

Start Claude Code in the throwaway repository and ask:

Explain demo.ts in three bullets. Do not modify anything.

Claude Code should answer normally. If it does not connect, confirm that the process inherited all three variables from the shell that launched it.

Using Bedrock or Vertex

When Claude Code routes through Bedrock or Vertex, set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1. This prevents Anthropic-specific beta headers from causing errors on those providers.

Done-When

  • Claude Code completes the read-only task
  • The Gateway key does not appear in the repository or terminal output
  • Claude Code uses a dedicated key with an intentional budget
  • You know where the environment configuration is applied

Solution

The complete integration is the three-variable shell configuration above. The repository stays unchanged, and the credential remains in the environment that starts Claude Code.

Was this helpful?

supported.