Guides
Migrate to MiniRouter
Change the base URL, the key and the model ID. Your SDK stays.
MiniRouter speaks the OpenAI Chat Completions and Responses APIs and the Anthropic Messages API. Existing SDKs work unchanged: point them at MiniRouter, pay from one balance and pick any model in the catalog.
1. Get a key
Create a key, then export it where your app runs.
export MINIROUTER_KEY=mr-live-YOUR-KEY-HEREsetx MINIROUTER_KEY mr-live-YOUR-KEY-HERE2. Change the base URL
Pass the MiniRouter URL and key to your client.
from openai import OpenAI
import os
client = OpenAI(
base_url="https://api.minirouter.sh/v1",
api_key=os.environ["MINIROUTER_KEY"],
)
completion = client.chat.completions.create(
model="openai/gpt-5.6-luna",
messages=[{"role": "user", "content": "Hello"}],
)
print(completion.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.minirouter.sh/v1",
apiKey: process.env.MINIROUTER_KEY,
});
const completion = await client.chat.completions.create({
model: "openai/gpt-5.6-luna",
messages: [{ role: "user", content: "Hello" }],
});
console.log(completion.choices[0].message.content);curl https://api.minirouter.sh/v1/chat/completions \
-H "Authorization: Bearer $MINIROUTER_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.6-luna",
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}'3. Use full model IDs
Prefix the author: gpt-5.6-luna becomes openai/gpt-5.6-luna. See Model IDs.
4. Verify
Send one request, then open Request logs. It lists the model, tokens and exact cost.
Anthropic SDK
Messages accepts the key as x-api-key or a bearer token. Only the base URL changes.
from anthropic import Anthropic
import os
client = Anthropic(
base_url="https://api.minirouter.sh",
api_key=os.environ["MINIROUTER_KEY"],
)
message = client.messages.create(
model="anthropic/claude-opus-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.minirouter.sh",
apiKey: process.env.MINIROUTER_KEY,
});
const message = await client.messages.create({
model: "anthropic/claude-opus-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }],
});
console.log(message.content);curl https://api.minirouter.sh/v1/messages \
-H "Authorization: Bearer $MINIROUTER_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "anthropic/claude-opus-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}'Vercel AI SDK
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const minirouter = createOpenAICompatible({
name: "minirouter",
baseURL: "https://api.minirouter.sh/v1",
apiKey: process.env.MINIROUTER_KEY,
includeUsage: true,
});
const { text } = await generateText({
model: minirouter("openai/gpt-5.6-luna"),
prompt: "Hello",
});
console.log(text);Any other OpenAI-compatible client takes the same base URL and key.
Environment variables
OpenAI and Anthropic SDKs read these when code passes no URL or key.
| Variable | Value |
|---|---|
| OPENAI_ | https://api.minirouter.sh/v1 |
| OPENAI_ | Your MiniRouter key. |
| ANTHROPIC_ | https://api.minirouter.sh |
| ANTHROPIC_ | Your MiniRouter key. |
export OPENAI_BASE_URL=https://api.minirouter.sh/v1
export OPENAI_API_KEY=mr-live-YOUR-KEY-HEREsetx OPENAI_BASE_URL https://api.minirouter.sh/v1
setx OPENAI_API_KEY mr-live-YOUR-KEY-HEREModel IDs
| Before | After |
|---|---|
| gpt-5.6-luna | openai/gpt-5.6-luna |
| claude-opus-5 | anthropic/claude-opus-5 |
| gemini-3.8-flash | google/gemini-3.8-flash |
Copy exact IDs from the catalog or list them. Let MiniRouter choose with minirouter/auto.
What stays, what changes
| Area | Detail |
|---|---|
| Cost | usage.cost and x-minirouter-cost-usd. See billing.Chat Completions streams carry it when stream_options.include_usage is set. |
| Balance | x-minirouter-balance-usd on every response. |
| Served by | x-minirouter-model and x-minirouter-provider. |
| Errors | error.code and x-minirouter-error-code name the cause. See errors.Messages keeps the Anthropic error shape. |
| Routing | Optional models fallbacks and provider settings. |
| Paths | Paths under /api/v1 also work. |
Roll out
FAQ
Do I need a new SDK?
No. OpenAI, Anthropic and OpenAI-compatible clients work with a new base URL and key.
Does the Responses API work?
Yes. Chat Completions and Responses both work through the OpenAI SDK.
How do I see what a request cost?
Read usage.cost or x-minirouter-cost-usd, or open Request logs.
What if a model fails?
List up to three backups in models, or fallbacks on Messages. If one cannot start a response, the next answers.