multi-router.aidocs

Getting Started

Using an SDK

Pointing the OpenAI and Anthropic SDKs at Multi-Router.

Multi-Router speaks the OpenAI Chat Completions and Anthropic Messages formats, so the official OpenAI and Anthropic SDKs work with it by changing two settings: the base URL and the API key. The model field then names a Multi-Router router, and every other part of the application stays as it is.

OpenAI SDK

The OpenAI SDK uses the base URL https://api.multi-router.ai/v1:

Pythonpython
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.multi-router.ai/v1",
    api_key=os.environ["MR_API_KEY"],
)

response = client.chat.completions.create(
    model="multi-router/rt_9Hk3Ws7PzQ",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.choices[0].message.content)
TypeScripttypescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.multi-router.ai/v1",
  apiKey: process.env.MR_API_KEY,
});

const response = await client.chat.completions.create({
  model: "multi-router/rt_9Hk3Ws7PzQ",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(response.choices[0].message.content); // in an ES module

Anthropic SDK

The Anthropic SDK uses the base URL https://api.multi-router.ai:

Pythonpython
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.multi-router.ai",
    api_key=os.environ["MR_API_KEY"],
)

message = client.messages.create(
    model="multi-router/rt_9Hk3Ws7PzQ",
    max_tokens=200,
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(message.content[0].text)

The model field

The model field names what serves the request:

Model fieldServed by
multi-router/rt_9Hk3Ws7PzQThe router, with its model, provider, prompt and settings.
multi-router/productionThe router the alias production points to.
anthropic/claude-sonnet-4.5The model, with the organization's default Anthropic key.

Naming a router keeps the model choice out of the application, so it changes on the router. See Chat Completions.

Multi-Router fields and headers

A few optional fields and headers add Multi-Router features to SDK requests:

Field or headerPurpose
prompt_variablesValues for the router's bound prompt. In Python, sent with extra_body; in TypeScript, as a field of the request.
x-mr-session-idGroups the requests of a conversation in Traffic. Sent as an extra header.
x-mr-correlation-idMatches requests to the application's own logs, and is returned on the response. Sent as an extra header.
userThe application's end user on Chat Completions, shown in Traffic's Customer column. On Messages, metadata.user_id.
Prompt variables and a session id with the OpenAI SDKpython
response = client.chat.completions.create(
    model="multi-router/rt_9Hk3Ws7PzQ",
    messages=[{"role": "user", "content": "How do I reset my password?"}],
    user="tenant_acme",
    extra_body={"prompt_variables": {"product": "Acme Cloud", "language": "English"}},
    extra_headers={"x-mr-session-id": "conv_8812"},
)

See Prompt Variables and Request Tracing.

QuickstartKey Concepts
Was this helpful?