SwitchRouterDocumentation
Dashboard

SDKs & App Integration

SwitchRouter is drop-in compatible with the official OpenAI SDKs, Vercel AI SDK, and LangChain. Change baseURL and your model ID to route across every model in the catalogue.

OpenAI SDK (TypeScript & Node.js)

Install the standard openai package and point baseURL at https://api.switchrouter.dev/v1:

typescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.SWITCHROUTER_API_KEY,
  baseURL: "https://api.switchrouter.dev/v1",
  defaultHeaders: {
    "X-Title": "My Production App",
    "HTTP-Referer": "https://myapp.com",
  },
});

const response = await client.chat.completions.create({
  model: "deepseek.v3.2",
  messages: [
    { role: "system", content: "You are a helpful engineering assistant." },
    { role: "user", content: "Write a fast retry helper in TypeScript." },
  ],
});

console.log(response.choices[0]?.message?.content);

Vercel AI SDK

For Next.js and TypeScript apps using the Vercel AI SDK, use @ai-sdk/openai-compatible to get full support for generateText, streamText, and tool calling:

vercel ai sdk
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";

const switchrouter = createOpenAICompatible({
  name: "switchrouter",
  baseURL: "https://api.switchrouter.dev/v1",
  apiKey: process.env.SWITCHROUTER_API_KEY,
  headers: {
    "X-Title": "My Next.js App",
  },
});

const result = streamText({
  model: switchrouter("deepseek.v3.2"),
  prompt: "Explain optimistic concurrency control in PostgreSQL.",
});

for await (const textPart of result.textStream) {
  process.stdout.write(textPart);
}

OpenAI SDK (Python)

Use the official openai Python client with base_url set to https://api.switchrouter.dev/v1:

python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SWITCHROUTER_API_KEY"],
    base_url="https://api.switchrouter.dev/v1",
    default_headers={
        "X-Title": "My Python Worker",
    },
)

completion = client.chat.completions.create(
    model="deepseek.v3.2",
    messages=[{"role": "user", "content": "Summarize this changelog."}],
)

print(completion.choices[0].message.content)

LangChain & LlamaIndex

Any framework built on OpenAI-compatible transports works out of the box:

langchain
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="deepseek.v3.2",
    api_key=os.environ["SWITCHROUTER_API_KEY"],
    base_url="https://api.switchrouter.dev/v1",
    default_headers={"X-Title": "LangChain Pipeline"},
)

response = llm.invoke("Extract the key entities from this invoice.")
print(response.content)

App attribution (Top Apps)

Pass X-Title (and optional HTTP-Referer) in your client's defaultHeaders. SwitchRouter groups usage by application name and displays your app or agent in the Top Apps breakdown on your Console Overview page.

Automatic icon matching
Known tools and SDKs (OpenCode, Cursor, Cline, Claude, Continue, Python SDK, Node.js, LangChain, cURL) automatically render with dedicated vector icons in the Console.

Configuring an autonomous coding agent? See Coding Agents & Hermes.

Start building with SwitchRouter.

Connect your app or coding agent in seconds. Route across frontier models through one endpoint — then launch your app and start building what's next.

Start building