Skip to Content
Launching the open-source gateway

Claude Code (gateway)

Route Claude Code’s LLM calls through the Respan gateway for automatic logging, caching, and model switching. Only your RESPAN_API_KEY is needed.

Paste this into your coding agent:

Help me set up the Respan gateway with the Claude Code integration. Follow https://www.respan.ai/docs/integrations/gateway/claude-code.md

Setup

Install Claude Code

Terminal
npm install -g @anthropic-ai/claude-code

Set environment variables

Add to your shell profile (.bashrc, .zshrc, or PowerShell $PROFILE):

Terminal
unset ANTHROPIC_AUTH_TOKEN export ANTHROPIC_BASE_URL="https://api.respan.ai/api/anthropic/" export ANTHROPIC_API_KEY="YOUR_RESPAN_API_KEY"

Use ANTHROPIC_API_KEY, not ANTHROPIC_AUTH_TOKEN, for Claude Code through the Respan Anthropic gateway. Claude prefers ANTHROPIC_AUTH_TOKEN when both are set.

Or use Claude Code settings (persistent)

Add to ~/.claude/settings.json for global config, or .claude/settings.local.json in your project for repo-local config:

JSON
{ "env": { "ANTHROPIC_BASE_URL": "https://api.respan.ai/api/anthropic/", "ANTHROPIC_API_KEY": "YOUR_RESPAN_API_KEY", "ANTHROPIC_AUTH_TOKEN": "" } }

Setting ANTHROPIC_AUTH_TOKEN to an empty string clears any inherited token so Claude Code prefers ANTHROPIC_API_KEY. Run Claude Code as usual — all LLM calls will route through Respan.

The Anthropic gateway path is /api/anthropic/ (with trailing slash). For interactive Claude Code sessions, prefer shell env vars or ~/.claude/settings.json. If ANTHROPIC_AUTH_TOKEN is exported by your shell or terminal app, Claude may still prefer it, so unset or remove it first. On first interactive launch, Claude may prompt: Detected a custom API key in your environment. Choose Yes to use the Respan API key. If you skipped it earlier, run /config, search for custom, and enable Use custom API key. Non-interactive claude -p and claude --print use ANTHROPIC_API_KEY automatically.

Switch models

Once routed through the gateway, you can use any Claude model.

Terminal
# In your shell claude --model claude-sonnet-4-5-20250929 claude --model claude-haiku-4-5-20251001

See the full model list .

Pin requests to a specific provider

To route Claude Code to your Vertex AI throughput (or any other provider) without changing the model slug, set the X-Respan-Route-Provider header. Claude Code keeps using its standard slug and the gateway resolves the provider transparently:

Terminal
export ANTHROPIC_CUSTOM_HEADERS="X-Respan-Route-Provider: vertex_ai"

For a fallback across providers (e.g. primary Vertex, fall back to Anthropic on failure), use a fallback route instead.