Skip to content

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:

  1. Register at https://platform.mirapi.ai and confirm your email.
  2. Top up a small prepaid balance (no subscription or minimum spend, and the balance never expires).
  3. Create an API key.
  4. Send your first request.
  1. Register at https://platform.mirapi.ai.
  2. Open Billing and top up a small amount. The cost of every request is deducted from this balance.
  3. Open API Keys, create a key, and copy it. It is shown only once.
  4. Store it in an environment variable:
Terminal window
export MIRAPI_API_KEY=sk-...

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.

Pass model names exactly as the catalog returns them, for example deepseek-chat. The authoritative list always comes from the API:

Terminal window
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.

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
Terminal window
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!"}]
}'
Terminal window
pip install openai
import os
from 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)
Terminal window
npm install openai
import 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);

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.

Terminal window
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!"}]
}'
Terminal window
pip install anthropic
import os
from 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)
Terminal window
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!"}]}]
}'
Terminal window
pip install google-genai
import os
from 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)

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)

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

The same key and base URL work in your everyday tools:

  • Claude Code: set ANTHROPIC_BASE_URL="https://api.mirapi.ai" and ANTHROPIC_AUTH_TOKEN="$MIRAPI_API_KEY". See Claude Code.
  • Codex CLI: add a [model_providers.mirapi] block to ~/.codex/config.toml with wire_api = "responses". See Codex CLI.
  • Cursor, Cline, LangChain, n8n, and more: point them at https://api.mirapi.ai/v1 with the same key. See Integrations.