LLMsRelay/Docs
Back to dashboard

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

Claude Code uses the Anthropic Messages format. Create the key in the Basic or Pro group. The Codex group is reserved for OpenAI and Codex clients.

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

Terminalbash
curl -fsSL https://claude.ai/install.sh | bash
claude --version

Windows PowerShell

PowerShellpowershell
irm https://claude.ai/install.ps1 | iex
claude --version

Homebrew is also supported: brew install --cask claude-code. The old global npm installation is no longer the recommended setup.

Create the correct API key

  1. Open API Keys in the dashboard.
  2. Create an sk-cs4-... key and select Basic or Pro.
  3. Copy the key when it is shown. It is not displayed again.
  4. Add a one-time usage pack from Plans if the account has no available balance.
Do not use an old 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.

macOS, Linux, or WSLbash
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
Windows PowerShellpowershell
$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

claude

Base URL format

Use 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:

~/.claude/settings.jsonjson
{
  "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

Store the real key in your user-level file. If a project needs its own settings, use .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.

List modelsbash
curl https://api.llmsrelay.com/v1/models \
  -H "x-api-key: $ANTHROPIC_API_KEY"
  • Use the top-level "model" value in ~/.claude/settings.json for a persistent default.
  • Use claude --model MODEL_ID for a one-off override.
  • Use the Claude Code model picker when you want to switch interactively.

Do not configure two different defaults

Avoid setting both the top-level "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

Gateway healthbash
curl https://api.llmsrelay.com/healthz
Claude Code smoke testbash
claude -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.

Ready to start?

Create a key and configure a compatible API route in under 2 minutes.

View Plans