For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
    • Overview
  • Tracing
  • Gateway
      • Claude Code
      • Codex CLI
      • Gemini CLI
      • OpenCode
  • Others
  • Migrating
    • Braintrust
    • Portkey
    • Langfuse
LogoLogo
DiscordPlatform
On this page
  • Setup
  • Switch models
  • Pin requests to a specific provider
GatewayCoding Agents

Claude Code (gateway)

Was this page helpful?
Previous

Codex CLI (gateway)

Next
Built with

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

Setup

1

Install Claude Code

$npm install -g @anthropic-ai/claude-code
2

Set environment variables

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

$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.

3

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:

1{
2 "env": {
3 "ANTHROPIC_BASE_URL": "https://api.respan.ai/api/anthropic/",
4 "ANTHROPIC_API_KEY": "YOUR_RESPAN_API_KEY",
5 "ANTHROPIC_AUTH_TOKEN": ""
6 }
7}

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.

$# In your shell
$claude --model claude-sonnet-4-5-20250929
$claude --model claude-3-5-haiku-20241022

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:

$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 fallback_models instead. See Reliability for fallback_models and load_balance_group, and Providers & models for inline router controls (models, exclude_models, exclude_providers).