Claude Code Setup with a Custom API Gateway
Install Claude Code, connect it to the LLMsRelay Anthropic-compatible endpoint, select the correct key group, and verify the configuration.
LLMsRelay is an independently operated API gateway. It is not affiliated with or endorsed by Anthropic, PBC. Product and model names are used only to describe compatibility.
Base URL: https://api.llmsrelay.com. API key: sk-cs4-*. Key group: Basic or Pro. Billing: One-time usage packs.
Install Claude Code
Anthropic recommends the native installer. It installs the CLI without requiring Node.js and keeps Claude Code updated automatically.
macOS, Linux, or WSL
curl -fsSL https://claude.ai/install.sh | bash
claude --versionWindows PowerShell
irm https://claude.ai/install.ps1 | iex
claude --versionHomebrew is also supported: brew install --cask claude-code. The old global npm installation is no longer the recommended setup.
Configure the gateway
The shortest setup is to export two variables in the same terminal where you start Claude Code.
export ANTHROPIC_BASE_URL="https://api.llmsrelay.com"
export ANTHROPIC_API_KEY="YOUR_SK_CS4_KEY"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
unset ANTHROPIC_AUTH_TOKEN
claude$env:ANTHROPIC_BASE_URL = "https://api.llmsrelay.com"
$env:ANTHROPIC_API_KEY = "YOUR_SK_CS4_KEY"
$env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY = "1"
Remove-Item Env:ANTHROPIC_AUTH_TOKEN -ErrorAction SilentlyContinue
claudeMake the configuration persistent
Put the gateway variables in your user settings file so the terminal client and the official editor extension use the same configuration:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.llmsrelay.com",
"ANTHROPIC_API_KEY": "YOUR_SK_CS4_KEY",
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
},
"model": "claude-sonnet-4.6"
}macOS / Linux / WSL: ~/.claude/settings.json
Windows: %USERPROFILE%\.claude\settings.json
Select a model without conflicts
Check the model IDs available to your key, then use one source of truth for model selection. Model discovery adds the gateway catalog to Claude Code's model picker.
curl https://api.llmsrelay.com/v1/models \
-H "x-api-key: $ANTHROPIC_API_KEY"- Use the top-level
"model"value in~/.claude/settings.jsonfor a persistent default. - Use
claude --model MODEL_IDfor a one-off override. - Use the Claude Code model picker when you want to switch interactively.
Verify the complete setup
curl https://api.llmsrelay.com/healthzclaude -p "Reply with exactly: pong"A pong response confirms that Claude Code loaded the gateway URL, authenticated the key, resolved the model, and completed a request.
In an interactive session, run /status and confirm that the displayed Anthropic base URL is https://api.llmsrelay.com and the active credential is ANTHROPIC_API_KEY.
Troubleshooting
Claude Code opens the Anthropic login flow
The variables were not loaded. Start Claude Code from the terminal where you exported them, or add them to ~/.claude/settings.json and restart the CLI or editor.
401 or 403
Confirm the key starts with sk-cs4-, belongs to Basic or Pro, and has not been revoked. Remove stale ANTHROPIC_AUTH_TOKEN and old api2 values from the shell and settings files.
The wrong model is charged
Check ~/.claude/settings.json, project .claude/settings.json, local .claude/settings.local.json, and env | grep ANTHROPIC. Remove conflicting model overrides, then restart Claude Code.
The editor extension uses different settings
Fully restart the editor after changing environment variables. Prefer the user-level settings file when the CLI and extension must share one gateway configuration.