What you’ll need
- Claude Code installed.
- An access key from app.ngrok.ai.
Point the CLI at the gateway
Set two environment variables in your shell:ANTHROPIC_BASE_URLis the gateway URL without/v1, since Claude Code appends/v1/messagesitselfANTHROPIC_AUTH_TOKENis your access key, which Claude Code sends as anAuthorization: Bearerheader
ANTHROPIC_AUTH_TOKEN takes precedence over a saved claude.ai login, so Claude Code uses your access key as soon as you start it.
If ANTHROPIC_API_KEY is also set in your environment, unset it to avoid an auth conflict warning.
To keep the configuration across terminals and for background agents, move the same values into the env block of ~/.claude/settings.json:
Test the connection
Before you start Claude Code, send a short request straight to the gateway from the same shell:{"id":"msg_ means the URL and access key work.
A 401 means the gateway rejected the access key.
Then start claude, run /status, and check two lines:
Anthropic base URLshowshttps://gateway.ngrok.aiAuth tokennamesANTHROPIC_AUTH_TOKEN
Choose a model
Claude Code’s built-in model aliases, such asopus, sonnet, and haiku, resolve to Anthropic model IDs like claude-sonnet-5-5.
The gateway finds those IDs in the model catalog, so /model and --model work without extra setup.
To pin the model behind each alias, set these variables alongside the base URL:
claude-haiku-4-5-20251001, which the gateway doesn’t match.
To add the gateway’s Claude models to the /model picker, turn on Claude Code’s gateway model discovery:
anthropic/claude-sonnet-5-5.
The gateway doesn’t serve Anthropic’s token counting endpoint, so /context shows estimated token counts.
Claude Code only works with Claude models through the gateway.
/v1/messages only reaches providers that support the Anthropic Messages API, and Anthropic doesn’t support routing Claude Code to other models.Use other surfaces
The CLI reads the shell variables and~/.claude/settings.json.
Other surfaces need the same two values in a different place:
- VS Code extension: set them in
claudeCode.environmentVariablesin your VS Code user settings - Claude Agent SDK: pass them in the SDK’s
envoption, which sets the environment of the Claude Code process it spawns - Claude desktop app: turn on Developer Mode, then enter the gateway details under Developer > Configure Third-Party Inference
Troubleshooting
For gateway-side errors, see Debug failed requests.
Next steps
- Restrict providers and models: Scope what an access key can call
- Configure fallback models: Try another model when the first one fails
- Observability: See which model served each request