Claude Code API proxy Base URL setup guide
Configure Claude Code with an API proxy using ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, and ANTHROPIC_API_KEY.
Minimal setup
When connecting Claude Code to a proxy, first check whether the provider offers an Anthropic-compatible API. The most common setup is:
export ANTHROPIC_BASE_URL="https://your-proxy.example"
export ANTHROPIC_AUTH_TOKEN="your proxy API key"
claude
ANTHROPIC_BASE_URL routes requests to the proxy or gateway. ANTHROPIC_AUTH_TOKEN is sent as the Bearer token.
If you are comparing providers before configuring Claude Code, start with the Claude API Proxy Providers page. For a broader list of Anthropic-compatible, OpenAI-compatible, and multi-model providers, use the AI API Directory.
API key path
If the provider gives you an Anthropic-style API key, it may ask you to configure:
export ANTHROPIC_API_KEY="sk-..."
claude
Note: after ANTHROPIC_API_KEY is set, Claude Code uses that API key instead of the quota from a Claude Pro, Max, or Team subscription login. When testing a proxy, open a fresh terminal window and set the variables only in that window.
Common errors
- 401: wrong key, wrong header type, or the provider expects
ANTHROPIC_AUTH_TOKENinstead ofANTHROPIC_API_KEY. - 404: wrong Base URL path. Pay close attention to whether the provider requires
/v1. - model not found: the model name is not available from the provider, or you need a custom model option.
- MCP search issues: with a non-official Base URL, Claude Code may change MCP tool search behavior. Confirm whether the provider forwards the required capabilities fully.
Recommendation
Start with a clean terminal and a temporary configuration. After you confirm the setup works, move it into your shell profile, project scripts, or switching tool. Do not change global configuration first, or debugging becomes much harder: you will not know whether the problem is the account, environment variables, or provider API.