Claude Code
Claude Code is Anthropic’s terminal coding agent. Because MirAPI implements the Anthropic Messages API (POST /v1/messages), you can point Claude Code at MirAPI with three environment variables — no proxy or patch required.
What you need
Section titled “What you need”| Element | Value |
|---|---|
| Base URL | https://api.mirapi.ai — the bare origin, without /v1 |
| API key | Your MirAPI key (sk-...), passed through ANTHROPIC_AUTH_TOKEN |
| Model | deepseek-chat via ANTHROPIC_MODEL (or the model setting) |
Configure
Section titled “Configure”- Create an API key in https://console.mirapi.ai → API Keys and store it:
export MIRAPI_API_KEY=sk-...- Export the connection variables. Add them to your shell profile (
~/.zshrc,~/.bashrc, or~/.config/fish/config.fish) so they persist:
export ANTHROPIC_BASE_URL="https://api.mirapi.ai"export ANTHROPIC_AUTH_TOKEN="$MIRAPI_API_KEY"export ANTHROPIC_MODEL="deepseek-chat"Define MIRAPI_API_KEY before ANTHROPIC_AUTH_TOKEN — the token variable expands when the profile is sourced, so an empty value here causes auth errors.
- Reload your shell and start Claude Code:
source ~/.zshrc # or ~/.bashrc, or open a new terminalclaudeVerify with a message
Section titled “Verify with a message”Run /status inside Claude Code and confirm the auth token and base URL point at MirAPI:
/statusThen send a quick test message:
Say "connected to MirAPI" and nothing else.The reply should contain connected to MirAPI. The first request draws a small amount from your prepaid balance; confirm it later with GET /api/usage/token or in the console billing log.
Credential variables
Section titled “Credential variables”Claude Code sends the two credential variables as different headers, so which one you set matters:
| Variable | Header sent | Use with MirAPI |
|---|---|---|
ANTHROPIC_AUTH_TOKEN |
Authorization: Bearer <token> |
Recommended for a gateway |
ANTHROPIC_API_KEY |
x-api-key: <key> |
Direct-Anthropic credential |
MirAPI accepts both x-api-key and Authorization: Bearer on /v1/messages, so either works — but ANTHROPIC_AUTH_TOKEN is the credential variable Anthropic documents for bearer-authenticated gateways. If ANTHROPIC_API_KEY still holds a real Anthropic key from an earlier setup, Claude Code may prompt or fall back to Anthropic; set it to an empty string to avoid conflicts.
Switching models
Section titled “Switching models”Change ANTHROPIC_MODEL to any model name from GET /v1/models:
export ANTHROPIC_MODEL="deepseek-chat"GET /v1/modelsreturns the exactid/nameto request, plus context length and pricing.- Your key must be whitelisted for the model you choose; otherwise the request fails with 403.
- Claude Code is optimized for Anthropic-style clients, so pick a model that supports tool calling for the best experience.
Billing
Section titled “Billing”- Conversations are billed per token (input / output / cache read, per 1M tokens USD). Reasoning and thinking tokens count as output.
- Claude Code draws from a prepaid balance: no subscription, no minimum, and the balance never expires.
- When the balance runs out, requests fail with 403; topping up restores the same key immediately.
- Reconcile usage in the console billing log,
GET /api/usage/token(account-level totals), orGET /api/log/token(per-request detail).
Troubleshooting
Section titled “Troubleshooting”- Do not append
/v1. Anthropic clients build the full path themselves;https://api.mirapi.ai/v1/messageswill not resolve. /v1/messages/count_tokensis not implemented and returns 404. Claude Code may call it during startup; the error is harmless and does not block requests.- 401 means the key is missing, invalid, or unknown. Check that
ANTHROPIC_AUTH_TOKENis set and non-empty. - 403 means the key is valid but the request was refused: balance exhausted, model not whitelisted, quota exceeded, or IP not allowed. Fix the cause and retry.
- 429 means rate limited. Retry with jittered exponential backoff (1s → 2s → 4s, capped around 30s); the gateway does not retry for you and sends no
Retry-Afterheader. - Every error message ends with a request ID — include it when you open a support ticket.