Claude Code can talk to an Anthropic-compatible API at a custom address. Set two environment variables — the agent then works as usual, no VPN.
You'll need Node.js 18 or newer. Claude Code itself installs with one command:
terminal
npm install -g @anthropic-ai/claude-codeVerify the version: claude --version. Grab a cai-... key from the API keys section.
Claude Code reads the base URL and token from the environment:
Add to ~/.zshrc (or ~/.bashrc / ~/.bash_profile):
~/.zshrc
export ANTHROPIC_BASE_URL="https://api.cheapai.io"
export ANTHROPIC_AUTH_TOKEN="cai-..."Restart the terminal (or source ~/.zshrc) and run:
terminal
claude # everything else as usualpowershell
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.cheapai.io", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "cai-...", "User")Close and reopen PowerShell, then run claude.
If you don't want global variables — you can pass them for a single run: ANTHROPIC_BASE_URL=https://api.cheapai.io ANTHROPIC_AUTH_TOKEN=cai-... claude.
The model name is the same as in the catalog. Pass it on the command line:
terminal
claude --model claude-3-5-sonnetOr pin the default model in ~/.claude/settings.json:
~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.cheapai.io",
"ANTHROPIC_AUTH_TOKEN": "cai-..."
},
"model": "claude-3-5-sonnet"
}This keeps the config in a single file, no env vars needed.
To give a specific repository its own settings — drop a .claude/settings.json with the same content next to it. You can commit this file (without the key — keep it in the environment), and the whole team will run through the gateway with the same model.
On the very first start Claude Code sometimes shows something like Unable to connect to Anthropic services or Failed to connect to api.anthropic.com — that's the onboarding check, which doesn't yet account for a custom BASE_URL. Open ~/.claude.json and add the field:
~/.claude.json
{
"hasCompletedOnboarding": true
}If the file already has other fields — add "hasCompletedOnboarding": true to the object, remembering the comma so the JSON stays valid. Then run claude again.
Other common errors and codes — on the Error codes page.
Next: Codex CLI · Cursor, Cline, Aider… · OpenAI-compatible API.