Build withModel Router.
One OpenAI-compatible endpoint. 39+ models — text, vision, image generation and video — with pay-as-you-go wallet billing and guaranteed structured output.
One endpoint. Every model.
Model Router routes your requests across 39+ state-of-the-art models with automatic failover, zero-buffering streaming and per-second video generation, speech-to-text and text-to-speech — all billed from one pay-as-you-go wallet.
curl https://api.modelrouter.in/v1/chat/completions \
-H "Authorization: Bearer $MR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "user", "content": "Hello"}
],
"max_tokens": 2000
}'Set base_url = "https://api.modelrouter.in/v1" in any OpenAI / Anthropic SDK. Auth accepts Bearer, X-Astra-Key or x-api-key.
Three ways to pass your key.
Every endpoint accepts the same key in three header styles — pick whatever your SDK prefers.
39+ models. Zero lock-in.
Live list always available at GET /v1/models.
Everything, one base URL.
Send images. Get text back.
The vision model reads screenshots, scanned documents, handwriting, tables and receipts — pass an image inline (base64 data URL) or via a public URL in image_url. OCR is the same call: ask for the text or JSON you want.
curl https://api.modelrouter.in/v1/chat/completions \
-H "Authorization: Bearer $MR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash-vision-exp",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Extract all text from this image."},
{"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
]
}],
"max_tokens": 2000
}'"content": [
{"type": "text", "text": "OCR this receipt. Return every line as JSON:
[{\"item\": string, \"qty\": number, \"price\": number}]"},
{"type": "image_url", "image_url": {"url": "https://example.com/receipt.jpg"}}
]{
"items": [
{ "item": "Milk 1L", "qty": 2, "price": 58.0 },
{ "item": "Bread", "qty": 1, "price": 35.0 }
],
"total": 151.0
}image_url the gateway can fetch works tooToken by token. SSE standard.
Add "stream": true and the response becomes text/event-stream — Server-Sent Events in the exact OpenAI wire format: data: lines with delta fields, zero buffering through the gateway. Works on /v1/chat/completions and every OpenAI SDK handles it natively.
curl https://api.modelrouter.in/v1/chat/completions \
-H "Authorization: Bearer $MR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "Count 1 to 5"}],
"max_tokens": 2000,
"stream": true
}'data: {"choices":[{"index":0,"delta":{"role":"assistant"}}]}
data: {"choices":[{"index":0,"delta":{"content":"1"}}]}
data: {"choices":[{"index":0,"delta":{"content":"2"}}]}
...
data: {"choices":[],"usage":{"prompt_tokens":9,"completion_tokens":12}}
data: [DONE]choices[].delta, not messagedata: lineLet the model call your functions.
Pass an OpenAI-format tools[] array and the model returns tool_calls with JSON arguments — it decides when to call, you execute, send the result back as a role: "tool" message and it writes the final answer. Works with streaming and on every tool-capable model in the list (deepseek, qwen, minimax, GLM).
{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "Weather in Nanded?"}],
"max_tokens": 2000,
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": { "city": {"type": "string"} },
"required": ["city"]
}
}
}]
}{
"choices": [{
"finish_reason": "tool_calls",
"message": {
"role": "assistant",
"tool_calls": [{
"id": "call_e06a27e14cbc4ffca5a413d5",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Nanded\"}"
}
}]
}
}]
}# 2 · run the function, send the result back
messages.append(response.choices[0].message)
messages.append({
"role": "tool",
"tool_call_id": response.choices[0].message.tool_calls[0].id,
"content": '{"temp_c": 29, "sky": "clear"}'
})
# 3 · model writes the final answer from your datarole: "tool" with the call idJSON Schema. Guaranteed.
Add response_format with a JSON Schema — the output is schema-valid by construction via guided decoding. No code fences, no prose, no parsing hacks.
{
"model": "/data/models/GLM-5.3-Flash",
"messages": [{"role": "user", "content": "Create person record: Ravi, 30, Mumbai"}],
"max_tokens": 2000,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "person",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
"city": {"type": "string"}
},
"required": ["name", "age", "city"],
"additionalProperties": false
}
}
}
}{ "name": "Ravi", "age": 30, "city": "Mumbai" }Text to video, $0.10/second.
Submit a job, poll the status, play the MP4 — signed URL included in the status response, valid for one hour, playable directly in any browser.
POST /v1/videos
{"model": "/data/Models/MiniMax-H3", "prompt": "...",
"seconds": "5", "aspect_ratio": "16:9"}
→ {"task_id": "task_...", "status": "queued"}GET /v1/videos/{task_id}
→ {"status": "completed", "progress": 100,
"url": "/media/video_gen_....mp4?exp=...&sig=..."}https://api.modelrouter.in{url}
→ signed link, plays in browser, no auth needed, 1-hour validityText to speech, GPU-fast.
Qwen3-TTS turns text into natural speech — 683 voices, Hindi + 8 languages, WAV 24kHz output. Generated faster than real-time playback, so a 5-minute narration finishes in about two and a half minutes.
curl https://api.modelrouter.in/v1/audio/speech \
-H "Authorization: Bearer $MR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-tts",
"input": "Your text here, up to 10,000 characters.",
"voice": "estelle"
}' \
-o speech.wavSpeech to text, 99 languages.
Whisper transcription from an audio file — upload MP3, WAV, M4A or WebM, get back plain text. Hindi, English and 97 more languages supported, with automatic language detection.
curl https://api.modelrouter.in/v1/audio/transcriptions \ -H "Authorization: Bearer $MR_KEY" \ -F [email protected] \ -F model=whisper-small
{"text": "Hello, this is what was said in the recording."}OCR + ASR. Pick the right model.
One key, every modality. Vision/OCR runs on the flagship vision model; speech-to-text has two Whisper tiers — small for quick drafts, medium for noisy audio.
hi or en — auto-detected when omittedjson (default, returns {"text": ...}) or text for plain outputFast, but not unlimited.
Limits are per key, enforced in real time. Generation endpoints cost more so heavy jobs can't starve chat traffic. Hit a limit and the response carries 429 with a Retry-After header.
{"error": "rate limit exceeded, slow down"}Every error, decoded.
Errors are JSON, always the same shape: an error object with message, type and code. Handle the status, log the code.
Authorization headerRetry-AfterGET /v1/models{
"error": {
"message": "No available channel for model gpt-99 under group default",
"type": "new_api_error",
"code": "model_not_found"
},
"system_fingerprint": "astra-v1"
}Agents & SDKs. Plug it in everywhere.
The gateway speaks OpenAI and Anthropic wire formats, so every coding agent and SDK works — point them at api.modelrouter.in and use your Model Router key.
export ANTHROPIC_BASE_URL=https://api.modelrouter.in export ANTHROPIC_AUTH_TOKEN=sk-... claude --model deepseek-v4-flash
hermes config set model.provider custom
hermes config set model.base_url https://api.modelrouter.in/v1
hermes config set model.api_key ${ASTRA_API_KEY}
# MR_KEY=sk-... → ~/.hermes/.env
hermes model # pick deepseek-v4-flash{
models: {
providers: {
modelrouter: {
baseUrl: "https://api.modelrouter.in/v1",
apiKey: "sk-...",
api: "openai-completions",
models: [{
id: "deepseek-v4-flash",
name: "DeepSeek V4 Flash",
input: ["text"],
contextWindow: 128000
}]
}
}
}
}
// openclaw models list → modelrouter/deepseek-v4-flashfrom openai import OpenAI
client = OpenAI(
base_url="https://api.modelrouter.in/v1",
api_key=os.environ["MR_KEY"],
)
resp = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.modelrouter.in/v1",
apiKey: process.env.MR_KEY,
});
const res = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [{ role: "user", content: "Hello" }],
});const res = await fetch("https://api.modelrouter.in/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.MR_KEY}`,
},
body: JSON.stringify({
model: "deepseek-v4-flash",
messages: [{ role: "user", content: "Hello" }],
}),
});
const data = await res.json();Know your balance. Always.
Every response body carries an astra block with live wallet state — never guess when to recharge.
"astra": {
"gateway": "modelrouter.in",
"balance_usd": "12.3571",
"used_usd": "26.5082",
"plan": "default/prepaid",
"models_count": "42",
"providers": "modelrouter.in",
"requests": "544"
}Pay-as-you-go. No subscriptions.
One wallet, per-use billing. Live balance in every response and at GET /v1/key/info.