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. You do not need a proxy or a patch.
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://platform.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’s value is expanded from the key variable when the profile is sourced, so if the key is still empty at that point, the token is empty too and you get 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 Platform 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> |
Credential for Anthropic’s own API |
MirAPI accepts both x-api-key and Authorization: Bearer on /v1/messages, so either works, but ANTHROPIC_AUTH_TOKEN is the variable Anthropic documents for gateways that use bearer authentication. If ANTHROPIC_API_KEY still holds a real Anthropic key from an earlier setup, Claude Code may prompt you about it 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 for the best experience, pick a model that supports tool calling.
Billing
Section titled “Billing”- Conversations are billed per token (input, output, and cache read, in USD per 1M tokens). Reasoning and thinking tokens count as output.
- Claude Code usage is drawn from a prepaid balance: no subscription, no minimum, and the balance never expires.
- When the balance runs out, requests fail with 403; after you top up, the same key works again immediately.
- Reconcile usage in the Platform billing log,
GET /api/usage/token(account-level summary), 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.