OpenAI-Compatible

An OpenAI-compatible router for every model

TheRouter.ai is an OpenAI-compatible router and AI gateway. It implements the OpenAI API format — /v1/chat/completions, /v1/responses, /v1/models, /v1/embeddings, and audio endpoints — so any client written against the OpenAI SDK can reach models from many providers by changing only base_url. One API key, automatic failover, and per-team spend controls.

Keep the OpenAI SDK you already use. Change one line — base_url — and reach models across providers behind a single API key, with automatic failover when an upstream fails.

What “OpenAI-compatible” actually means

The OpenAI Chat Completions format became the de-facto wire protocol for LLM APIs. A provider is “OpenAI-compatible” when it accepts the same JSON request body — model, messages, stream, tools — and returns the same response envelope, including the same server-sent-event chunk shape when streaming.

An OpenAI-compatible router goes one step further. Rather than fronting a single provider, it accepts that format and dispatches each request to whichever upstream serves the model you named. Your application keeps a single client, a single key, and a single error-handling path, while the provider behind any given call can change without a code change.

Two lines to connect via the OpenAI SDK

The only change from a stock OpenAI SDK call is base_url and the model name.

Python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.therouter.ai/v1",  # ← only change
    api_key="YOUR_THEROUTER_KEY",
)

response = client.chat.completions.create(
    model="deepseek/deepseek-r1",
    messages=[{"role": "user", "content": "Explain the difference between REST and GraphQL"}],
    stream=True,
)
for chunk in response:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
TypeScript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.therouter.ai/v1",   // ← only change
  apiKey: process.env.THEROUTER_API_KEY,
});

const response = await client.chat.completions.create({
  model: "qwen/qwen3-235b",
  messages: [{ role: "user", content: "Review this pull request diff…" }],
  stream: true,
});

for await (const chunk of response) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
curl
curl https://api.therouter.ai/v1/chat/completions \
  -H "Authorization: Bearer $THEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek/deepseek-r1",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

OpenAI-compatible endpoints

Every endpoint below accepts the OpenAI request format at https://api.therouter.ai/v1.

Anthropic-native clients use /v1/messages at the root domain instead — see the Claude Code router setup.

Works with any client that exposes a base URL

If a tool lets you override the OpenAI base URL, it works with TheRouter. No plugin, no proxy binary, no forked SDK.

Cursor / Cline / Continue / any OpenAI-compatible client
Base URL:  https://api.therouter.ai/v1
API Key:   <your TheRouter key>
Model:     deepseek/deepseek-r1               # reasoning
           qwen/qwen3-235b                    # frontier

Frameworks built on the OpenAI SDK — LangChain, LlamaIndex, the Vercel AI SDK — accept the same override wherever they construct their OpenAI client.

Why route through TheRouter?

Automatic failover

A provider goes down → TheRouter reroutes to a healthy equivalent. Your code sees 200 OK.

One API key

Anthropic, OpenAI, Google, DeepSeek, Qwen, xAI — all reached with a single key. No credential rotation across providers.

Spend controls

Set per-team and per-key spending limits. Every token and cost is tracked in real time.

No data stored

TheRouter passes requests through without storing prompt or response content.

See pricing for the published rate card, or how routing decisions are made.

Provider-specific compatibility guides

OpenAI-compatible router — FAQ

What is an OpenAI-compatible router?

It is a gateway that speaks the OpenAI API format — the same request and response shapes as /v1/chat/completions — while forwarding your request to whichever underlying model you name. Because the wire format is unchanged, any client already written against the OpenAI SDK works after a base_url change, with no SDK rewrite.

How do I point the OpenAI SDK at TheRouter?

Construct the OpenAI client with base_url='https://api.therouter.ai/v1' and your TheRouter API key. Model names use the provider/model format, for example deepseek/deepseek-r1 or qwen/qwen3-235b. Nothing else in your code changes.

Which OpenAI-compatible endpoints does TheRouter implement?

TheRouter exposes /v1/chat/completions, /v1/responses, /v1/models, /v1/embeddings, /v1/audio/speech, /v1/audio/transcriptions, and /v1/images/edits. It also exposes Anthropic's native /v1/messages endpoint for Anthropic-native clients such as Claude Code.

Does streaming and function calling work through the router?

Yes. Requests with stream=true and a tools array are routed transparently, and provider-specific fields such as reasoning_content are preserved end to end.

Which tools can I plug into an OpenAI-compatible base URL?

Any client that lets you override the OpenAI base URL — editors and agent tools such as Cursor, Cline, and Continue, plus frameworks like LangChain and LlamaIndex that build on the OpenAI SDK. Claude Code is the exception: it uses the Anthropic SDK, so it points at the root domain instead. See the Claude Code router page for that setup.

Why route through a gateway instead of calling each provider directly?

A direct integration ties your code to one provider's key, catalog, and availability. Routing through TheRouter gives you one API key for every routable model, automatic failover to a healthy equivalent when a provider fails, and per-team spend controls — without changing application code.

Get started — free, no card needed

Get your TheRouter API key and run your first OpenAI-compatible request in under 2 minutes.

Get free API key →
Help & contact