Guides

Claude Code

Run Anthropic's terminal coding agent on any model in the MiniRouter catalog.

Claude Code is Anthropic's coding agent for the terminal. MiniRouter serves the Anthropic Messages API, so Claude Code runs on any tool-capable model in the catalog, a preset or a router, with one balance and per-key spend limits.

1. Install Claude Code

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

2. Point Claude Code at MiniRouter

Create a key, then set these in the shell that launches Claude Code.

Terminal
export MINIROUTER_KEY=mr-live-YOUR-KEY-HERE
export ANTHROPIC_BASE_URL=https://api.minirouter.sh
export ANTHROPIC_AUTH_TOKEN="$MINIROUTER_KEY"
export ANTHROPIC_MODEL="zai/glm-5.3-flash"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=1000000

claude --model "$ANTHROPIC_MODEL"
SettingValue
ANTHROPIC_BASE_URLhttps://api.minirouter.shUse the bare host. Claude Code adds /v1/messages itself.
ANTHROPIC_AUTH_TOKEN$MINIROUTER_KEYShell only. Settings files keep env values literal, so use apiKeyHelper there.
ANTHROPIC_MODELzai/glm-5.3-flashUse the full ID of a tool-capable model from the live catalog, or a preset such as @preset/your-preset.
CLAUDE_CODE_MAX_CONTEXT_TOKENS1000000Optional. Claude Code assumes a 200K window for any model it does not know and compacts early; set the model's real window.

3. Check the connection

Run /status inside the session. It names the base URL and ANTHROPIC_AUTH_TOKEN as the credential.

4. Send a prompt

Ask for anything, then open Request logs. The request lists its model, tokens and exact cost.

Switch models

Behind a custom ANTHROPIC_BASE_URL, Claude Code passes any model ID through unchecked.

WhereScope
/model zai/glm-5.3-flashInside a session. Saved as your default.
claude --model zai/glm-5.3-flashOne run.
ANTHROPIC_MODELEvery run from that shell.
Model IDAnswers with
@preset/your-slugYour saved preset. Change it in Presets without touching the shell.
minirouter/auto:codeA tool-capable model Auto picks.
minirouter/fusionThe model Fusion picks per request.

Map every model slot

Background work and subagents use their own slots. Point each at a MiniRouter model.

VariableUsed for
ANTHROPIC_DEFAULT_OPUS_MODEL/model opus.
ANTHROPIC_DEFAULT_SONNET_MODEL/model sonnet.
ANTHROPIC_DEFAULT_HAIKU_MODEL/model haiku and background tasks such as session titles.
CLAUDE_CODE_SUBAGENT_MODELSubagents.
Terminal
export ANTHROPIC_DEFAULT_OPUS_MODEL="openai/gpt-6-sol"
export ANTHROPIC_DEFAULT_SONNET_MODEL="zai/glm-5.3-flash"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="openai/gpt-6-luna"
export CLAUDE_CODE_SUBAGENT_MODEL="zai/glm-5.3-flash"

Save it in settings

Settings files keep the setup across shells. env values are literal, so apiKeyHelper reads the key from your shell instead.

~/.claude/settings.json
{
  "apiKeyHelper": "echo $MINIROUTER_KEY",
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.minirouter.sh",
    "ANTHROPIC_MODEL": "zai/glm-5.3-flash"
  }
}
FileApplies to
~/.claude/settings.jsonYou, every project.
.claude/settings.jsonEveryone in the project. Commit it.
.claude/settings.local.jsonYou, this project only.
  • A settings-file env value wins over the same shell export.
  • An exported ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY wins over apiKeyHelper. Unset them.

Run headless

claude -p runs one task without the interactive session. Use it in scripts and CI, or see Automatic code review for a pull request workflow.

Terminal
claude -p "Run the tests and fix failures" \
  --model zai/glm-5.3-flash \
  --allowedTools "Bash,Read,Edit" \
  --output-format json
FlagDoes
--modelAny MiniRouter model ID.
--allowedToolsTools that run without a prompt.
--output-format jsonPrints the result as JSON.

The cost Claude Code prints is its own estimate. Your charge is in Request logs.

Keep spend in check

Restrict models or filter content with Guardrails. Rolling out to a team? See Teams.

Troubleshooting

Claude Code calls api.anthropic.com instead of MiniRouter

ANTHROPIC_BASE_URL was not exported into the shell that launched Claude Code. Set it to the bare MiniRouter host, then start a new Claude Code process from that shell.

The selected model name is rejected

Claude aliases such as sonnet and opus are not MiniRouter model IDs. Pass a full author/name ID from the current catalog with --model.

Error: 404 unknown_model.

"is not a model this version of Claude Code recognizes" at startup

Local metadata only; requests still work. Claude Code assumes a 200K window for unknown models, so set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the model's real window to stop early compaction.

401 on every request

Wrong or rotated key. Keys start with mr-live-; after a rotation the old key keeps working for 24 hours, then dies.

Error: 401 invalid_api_key.

402 before any tokens arrive

Balance below the estimated cost of the request. Top up (from $0.50 with direct Solana payments) — and watch the x-minirouter-balance-usd header, the low-balance signal every response carries.

Error: 402 insufficient_credits.

Every error code, with its fix: Errors.

Next steps