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.
Base URL: https://api.llmsrelay.com. API key: sk-cs4-*. Key group: Basic or Pro. Billing: One-time usage packs.
Use an Anthropic key group
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.
Create the correct API key
- Open API Keys in the dashboard.
- Create an
sk-cs4-...key and select Basic or Pro. - Copy the key when it is shown. It is not displayed again.
- Add a one-time usage pack from Plans if the account has no available balance.
api2 endpoint or a Codex-group key. Claude Code must connect to api.llmsrelay.com with an Anthropic-compatible key.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
claudeBase URL format
https://api.llmsrelay.com exactly. Do not append /v1; Claude Code adds the API path itself.Make 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
Keep the key out of Git
.claude/settings.local.json and make sure it is ignored by Git.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.
Do not configure two different defaults
"model" field and a conflicting ANTHROPIC_MODEL environment variable. The environment override can make the UI show one model while the gateway receives another.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.