Skip to content

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.

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)
  1. Create an API key in https://platform.mirapi.ai → API Keys and store it:
Terminal window
export MIRAPI_API_KEY=sk-...
  1. Export the connection variables. Add them to your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish) so they persist:
Terminal window
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.

  1. Reload your shell and start Claude Code:
Terminal window
source ~/.zshrc # or ~/.bashrc, or open a new terminal
claude

Run /status inside Claude Code and confirm the auth token and base URL point at MirAPI:

/status

Then 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.

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.

Change ANTHROPIC_MODEL to any model name from GET /v1/models:

Terminal window
export ANTHROPIC_MODEL="deepseek-chat"
  • GET /v1/models returns the exact id/name to 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.
  • 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), or GET /api/log/token (per-request detail).
  • Do not append /v1. Anthropic clients build the full path themselves; https://api.mirapi.ai/v1/messages will not resolve.
  • /v1/messages/count_tokens is 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_TOKEN is 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-After header.
  • Every error message ends with a request ID; include it when you open a support ticket.