Skip to content

MirAPI Documentation

MirAPI is a single OpenAI-compatible API gateway in front of 200+ models from every major vendor. Point your existing SDK or agent at it and you get routing, billing, and logging in one place, with no per-provider accounts or keys to manage.

MirAPI speaks the OpenAI wire format, so most of your existing code works unchanged. Only base_url and the API key change; your prompt format, streaming, and tool-calling logic stay the same.

MirAPI also accepts the Anthropic Messages and Gemini request formats, so tooling built for Claude or Gemini works too. Every model and capability is billed against one prepaid USD balance.

Your app (OpenAI SDK / agent)
│ base_url = https://api.mirapi.ai/v1
▼
MirAPI gateway ──► Model vendor A
──► Model vendor B
──► Model vendor C …
  1. Register at https://platform.mirapi.ai and top up a prepaid USD balance.
  2. Each request goes to the primary channel you chose for that model’s vendor (or the system default) and is billed at that channel’s price. If the primary fails, the request switches to your backup channel (see Channels and failover). If both are down, the request fails; MirAPI never silently switches models.
  3. There is no subscription, no monthly minimum, and no expiry: your balance stays until you use it.

Change base_url to https://api.mirapi.ai/v1, set your key, and send a chat request with deepseek-chat:

from openai import OpenAI
client = OpenAI(
base_url="https://api.mirapi.ai/v1",
api_key="sk-...", # your MirAPI key
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello, MirAPI!"}],
)
print(response.choices[0].message.content)

The same call over plain HTTP:

Terminal window
curl https://api.mirapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-..." \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "Hello, MirAPI!"}]
}'
Protocol Base URL Authentication
OpenAI-compatible https://api.mirapi.ai/v1 Authorization: Bearer sk-...
Anthropic Messages https://api.mirapi.ai (no /v1) x-api-key or Authorization: Bearer
Gemini https://api.mirapi.ai or https://api.mirapi.ai/v1beta x-goog-api-key or ?key=

Rule of thumb: if a tool appends its own path (for example /chat/completions) to the base URL, set it to https://api.mirapi.ai/v1. Anthropic SDKs point at https://api.mirapi.ai directly.

  • Chat: /v1/chat/completions, /v1/responses, and /v1/responses/compact
  • Anthropic Messages and Gemini generateContent
  • Embeddings, rerank, and moderations
  • Image generation and edits
  • Video generation (asynchronous task flow)
  • Audio transcription, translation, and speech
  • Realtime speech over WebSocket
  • Prompt caching, tool calling, structured outputs, and reasoning

Inspect the full catalog with GET /v1/models, which returns each model’s id, name, context_length, per-token pricing, supported_parameters, and output_modalities.

Status Meaning What to do
401 Missing, invalid, or unknown key Fix your credentials
403 Key is valid but rejected (balance, whitelist, quota, IP) Resolve the cause and retry
413 Request too large Reduce the size
429 Rate limited Retry with jittered exponential backoff (no Retry-After header is sent)
500 Upstream failure Retry idempotent requests safely

The gateway does not retry for you. For 429, back off with jitter, for example 1s → 2s → 4s, capped around 30s. Every error message ends with a request ID; include it in any support ticket.

Text and multimodal chat are billed per token, priced per 1M tokens with separate input, output, and cache-read rates. Images are billed per image and video per output second. Reasoning tokens count as output; cache reads are cheaper than ordinary input.

Balances are prepaid in USD and never expire, and there is no subscription or minimum. To reconcile usage, use the Platform billing log, GET /api/usage/token (account-level summary), or GET /api/log/token (per-request detail). See Billing for details.

  • 401 on every request: check that the key is present and intact. The Bearer scheme is case-insensitive, and a bare key is also accepted.
  • 403 on a key that used to work: most often the balance is drained. Top up and retry with the same key. Whitelist, quota, and IP-allowlist restrictions also return 403.
  • 429 under load: add jittered backoff. The gateway does not throttle for you.
  • Streaming stops early: streams are standard SSE, so read data: lines until data: [DONE]. Reasoning content arrives before the answer.
Section What you’ll find
Quickstart Register, top up, create a key, and make your first request
Configuration Base URLs, auth headers, streaming, timeouts, and reconciliation
Billing Prepaid balances, the three pricing units, and usage logs
Models & pricing The catalog, model names, pricing, and discount badges
OpenAI compatibility Endpoint support and known differences from OpenAI
Capability guides Images, video, audio, realtime, vision, embeddings, reasoning, structured outputs, prompt caching, web search
Integrations Claude Code, Codex, Cursor, SDKs, and other tools
API reference Authentication, errors, and every endpoint
Tutorials Complete, runnable end-to-end examples
FAQ Billing, keys, rate limits, and privacy