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.

Terminal
export MINIROUTER_KEY=mr-live-YOUR-KEY-HERE

2. Change the base URL

Pass the MiniRouter URL and key to your client.

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

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.

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

Vercel AI SDK

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

VariableValue
OPENAI_BASE_URLhttps://api.minirouter.sh/v1
OPENAI_API_KEYYour MiniRouter key.
ANTHROPIC_BASE_URLhttps://api.minirouter.sh
ANTHROPIC_API_KEYYour MiniRouter key.
Terminal
export OPENAI_BASE_URL=https://api.minirouter.sh/v1
export OPENAI_API_KEY=mr-live-YOUR-KEY-HERE

Model IDs

BeforeAfter
gpt-5.6-lunaopenai/gpt-5.6-luna
claude-opus-5anthropic/claude-opus-5
gemini-3.8-flashgoogle/gemini-3.8-flash

Copy exact IDs from the catalog or list them. Let MiniRouter choose with minirouter/auto.

What stays, what changes

AreaDetail
Costusage.cost and x-minirouter-cost-usd. See billing.Chat Completions streams carry it when stream_options.include_usage is set.
Balancex-minirouter-balance-usd on every response.
Served byx-minirouter-model and x-minirouter-provider.
Errorserror.code and x-minirouter-error-code name the cause. See errors.Messages keeps the Anthropic error shape.
RoutingOptional models fallbacks and provider settings.
PathsPaths under /api/v1 also work.

Roll out

1. One key per environment

Create them in Keys, each with limits.

2. Add credits

Top up in billing.

3. Switch staging

  • Swap base URL, key and model IDs.
  • Log usage.cost, or watch Usage.
  • Handle 402 and 429 by error.code.

4. Switch production

Keep the old config until traffic settles.

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.

Can I share one model setting across apps?

Call a preset as @preset/your-slug and change its model from the dashboard.