Quickstart
MirAPI gives you many models through one API, with one key and one prepaid balance. Switching models means changing a single field; you don’t need a new SDK or account.
The whole flow takes about five minutes:
- Register at https://platform.mirapi.ai and confirm your email.
- Top up a small prepaid balance (no subscription or minimum spend, and the balance never expires).
- Create an API key.
- Send your first request.
1. Create an account and a key
Section titled “1. Create an account and a key”- Register at https://platform.mirapi.ai.
- Open Billing and top up a small amount. The cost of every request is deducted from this balance.
- Open API Keys, create a key, and copy it. It is shown only once.
- Store it in an environment variable:
export MIRAPI_API_KEY=sk-...2. Choose your base URL
Section titled “2. Choose your base URL”MirAPI speaks three widely used protocols. Only the base URL and the auth header change between them:
| Protocol | Base URL | Auth header |
|---|---|---|
| OpenAI-compatible | https://api.mirapi.ai/v1 |
Authorization: Bearer $MIRAPI_API_KEY |
| Anthropic | https://api.mirapi.ai |
x-api-key or Authorization: Bearer |
| Gemini | https://api.mirapi.ai or https://api.mirapi.ai/v1beta |
x-goog-api-key or ?key= |
Most SDKs and tools already speak one of them. As a rule of thumb, if a tool appends /chat/completions (or any other path) to the base URL itself, enter https://api.mirapi.ai/v1. The same key works across all three protocols.
3. Find a model
Section titled “3. Find a model”Pass model names exactly as the catalog returns them, for example deepseek-chat. The authoritative list always comes from the API:
curl https://api.mirapi.ai/v1/models \ -H "Authorization: Bearer $MIRAPI_API_KEY" | jq '.data[].id'Each entry reports its context_length, per-token pricing (input, output, and cache read), supported_parameters, and output_modalities. Browse the Platform catalog to compare context windows, capabilities (tools, vision, reasoning), and prices before you pick. The vendor/ prefix you see in the Platform is only for browsing and filtering. Never send it in a request.
4. Send your first request
Section titled “4. Send your first request”A minimal request needs two fields, plus an optional stream for SSE:
| Parameter | Required | Description |
|---|---|---|
model |
Yes | Model ID exactly as the catalog returns it, e.g. deepseek-chat |
messages |
Yes | Ordered list of { "role", "content" } objects |
stream |
No | true returns standard SSE deltas instead of one JSON response |
curl https://api.mirapi.ai/v1/chat/completions \ -H "Authorization: Bearer $MIRAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-chat", "messages": [{"role": "user", "content": "Hello!"}] }'Python
Section titled “Python”pip install openaiimport osfrom openai import OpenAI
client = OpenAI( base_url="https://api.mirapi.ai/v1", api_key=os.environ["MIRAPI_API_KEY"],)
response = client.chat.completions.create( model="deepseek-chat", messages=[{"role": "user", "content": "Hello!"}],)
print(response.choices[0].message.content)TypeScript
Section titled “TypeScript”npm install openaiimport OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.mirapi.ai/v1", apiKey: process.env.MIRAPI_API_KEY!,});
const response = await client.chat.completions.create({ model: "deepseek-chat", messages: [{ role: "user", content: "Hello!" }],});
console.log(response.choices[0].message.content);5. Anthropic and Gemini requests
Section titled “5. Anthropic and Gemini requests”The same key and balance also work over the Anthropic and Gemini protocols. Protocol support varies by model, so check the model’s capability flags in the catalog.
Anthropic
Section titled “Anthropic”curl https://api.mirapi.ai/v1/messages \ -H "x-api-key: $MIRAPI_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{ "model": "deepseek-chat", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello!"}] }'pip install anthropicimport osfrom anthropic import Anthropic
client = Anthropic( base_url="https://api.mirapi.ai", api_key=os.environ["MIRAPI_API_KEY"],)
message = client.messages.create( model="deepseek-chat", max_tokens=1024, messages=[{"role": "user", "content": "Hello!"}],)
print(message.content[0].text)Gemini
Section titled “Gemini”curl "https://api.mirapi.ai/v1beta/models/deepseek-chat:generateContent" \ -H "x-goog-api-key: $MIRAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [{"parts": [{"text": "Hello!"}]}] }'pip install google-genaiimport osfrom google import genai
client = genai.Client( api_key=os.environ["MIRAPI_API_KEY"], http_options={"base_url": "https://api.mirapi.ai"},)
response = client.models.generate_content( model="deepseek-chat", contents="Hello!",)
print(response.text)6. Read streaming responses
Section titled “6. Read streaming responses”Set stream: true and read the deltas as they arrive. The stream is standard SSE (data: lines, ending with data: [DONE]), so every OpenAI-compatible SDK handles it without extra configuration. For reasoning models, the reasoning content arrives before the answer:
stream = client.chat.completions.create( model="deepseek-chat", messages=[{"role": "user", "content": "Hello!"}], stream=True,)
for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)7. Handle errors
Section titled “7. Handle errors”The gateway does not retry for you, so retry policy is your responsibility. Every error message ends with a request ID; include it in support tickets.
| Status | Meaning | What to do |
|---|---|---|
401 |
Key missing, invalid, or unknown | Check the Authorization: Bearer header and the key value |
403 |
Key valid but rejected: insufficient balance, model not on the whitelist, quota, or IP | Fix the cause (top up, check whitelist/quota/IP), then retry |
413 |
Request too large | Reduce the payload |
429 |
Rate limited | Retry with jittered exponential backoff (1s → 2s → 4s, cap ~30s); no Retry-After header is sent |
500 |
Upstream or other server error | Safe to retry idempotent requests |
When your balance runs out, requests return 403. Top up and the same key works again immediately. Reconcile spending from the Platform billing log, GET /api/usage/token (account-level summary), or GET /api/log/token (per-request detail).
Use it from your tools
Section titled “Use it from your tools”The same key and base URL work in your everyday tools:
- Claude Code: set
ANTHROPIC_BASE_URL="https://api.mirapi.ai"andANTHROPIC_AUTH_TOKEN="$MIRAPI_API_KEY". See Claude Code. - Codex CLI: add a
[model_providers.mirapi]block to~/.codex/config.tomlwithwire_api = "responses". See Codex CLI. - Cursor, Cline, LangChain, n8n, and more: point them at
https://api.mirapi.ai/v1with the same key. See Integrations.
Related links
Section titled “Related links”- Configuration: parameters, streaming, and timeouts
- Models and pricing: what the catalog tells you about each model
- Billing: how the prepaid balance and pricing work
- Authentication: key formats and header rules
- Errors: full error envelope reference
- Integrations: connect your tools and frameworks