Quickstart
MirAPI gives you many models through a single API. One key, one prepaid balance, and you switch models by changing a single field — no new SDK, no new account.
The whole flow takes about five minutes:
- Register at https://console.mirapi.ai and confirm your email.
- Top up a small prepaid balance (no subscription, no minimum spend, and it 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://console.mirapi.ai.
- Open Billing and top up a small amount — 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 the three mainstream protocols, and the base URL plus auth header are the only things that 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 these three. A useful 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 catalogue returns them — for example deepseek-chat. The authoritative list always comes from the API itself:
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 console catalogue to compare context windows, capabilities (tools, vision, reasoning), and prices before you pick. The vendor/ prefix you see in the console is only for browsing and filtering — never send it in a request.
4. Send your first request
Section titled “4. Send your first request”The minimal request needs just two fields, plus an optional stream for SSE:
| Parameter | Required | Description |
|---|---|---|
model |
Yes | Model id exactly as the catalogue 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. Whether a given model is available on a given protocol depends on the model — check its capability flags in the catalogue.
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 console billing log, GET /api/usage/token (account 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:
ANTHROPIC_BASE_URL="https://api.mirapi.ai"+ANTHROPIC_AUTH_TOKEN="$MIRAPI_API_KEY"— see Claude Code. - Codex CLI: a
[model_providers.mirapi]block in~/.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 catalogue 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