Use RouterBrain as the model backend for AI coding in Claude Code.

Claude Code is Anthropic's official terminal-native coding agent powered by Claude. Point the API endpoint at RouterBrain's Anthropic-compatible surface to use console keys and the shared model catalog.

Install Claude Code

Follow the official Claude Code setup guide.

Before wiring RouterBrain, create an inference API key in the console (API keys) and pick a catalog id (List models).

Configure RouterBrain API

Important

Clear environment variables that still point at Anthropic or another proxy before applying config:

unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_API_KEY
unset ANTHROPIC_BASE_URL

If these are exported in ~/.bashrc or ~/.zshrc, remove those lines too—new shells will re-inject them otherwise.

Step 1 — Edit config files (recommended)

1. Edit settings.json

Create or edit Claude Code settings (macOS / Linux: ~/.claude/settings.json; Windows: %USERPROFILE%\.claude\settings.json).

Replace YOUR_ROUTERBRAIN_KEY and YOUR_MODEL_ID with your key and catalog id. Shell ANTHROPIC_AUTH_TOKEN and ANTHROPIC_BASE_URL override this file.

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://51kik.com/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_ROUTERBRAIN_KEY",
    "API_TIMEOUT_MS": "3000000",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    "ANTHROPIC_MODEL": "YOUR_MODEL_ID",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "YOUR_MODEL_ID",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "YOUR_MODEL_ID",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "YOUR_MODEL_ID",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}
VariablePurpose
ANTHROPIC_BASE_URLGateway Anthropic root (no /v1 suffix)
ANTHROPIC_AUTH_TOKENRouterBrain inference key (ANTHROPIC_API_KEY also works)
ANTHROPIC_MODELDefault catalog id
ANTHROPIC_DEFAULT_*_MODELSonnet / Opus / Haiku aliases—set to the same id unless you split tiers
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYPopulate /model from the gateway

2. Onboarding flag

Create or edit ~/.claude.json (Windows: %USERPROFILE%\.claude.json) so startup skips first-party login:

{
  "hasCompletedOnboarding": true
}

Step 2 — Launch Claude Code

From your project directory:

claude

Step 3 — Trust the workspace

When prompted, choose Trust This Folder so Claude Code can read and write project files.

Verify configuration

Inside the claude TUI, run:

/status
/model

Expected:

  • /status shows ANTHROPIC_BASE_URL at https://51kik.com/anthropic (rendered to your live gateway URL on this site).
  • /model shows YOUR_MODEL_ID or models returned by the gateway.

Quick CLI check:

claude -p "reply with ok only"

Tools and MCP

Third-party ANTHROPIC_BASE_URL disables MCP tool search by default. If your gateway forwards tool_reference, add to env:

"ENABLE_TOOL_SEARCH": "true"

See Claude Code docs for MCP servers; gateway tools: Messages API.

Optional curl check

curl -sS "https://51kik.com/anthropic/v1/messages" \
  -H "x-api-key: YOUR_ROUTERBRAIN_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "max_tokens": 64,
    "messages": [{ "role": "user", "content": "reply with ok only" }]
  }'

Troubleshooting

SymptomCheck
Still hits api.anthropic.comShell env overrides settings; launch VS Code from a configured terminal
401 / 403RouterBrain key, not Anthropic vendor key
Unknown modelmodel must be catalog id
Login loophasCompletedOnboarding: true in ~/.claude.json

Related