SwitchRouterDocumentation
Dashboard

Quickstart

SwitchRouter gives you one OpenAI-compatible endpoint for every frontier model in the catalogue. Connect your app or let your coding agent set it up in seconds.

Agent-ready setupPick your agent or IDE to view and copy its setup prompt
OpenCode~/.config/opencode/opencode.jsonc
Configure OpenCode (~/.config/opencode/opencode.jsonc) to add SwitchRouter as a provider using "@ai-sdk/openai-compatible":
- Base URL: https://api.switchrouter.dev/v1
- API Key: "{env:SWITCHROUTER_API_KEY}"
- Header: "X-Title": "OpenCode"
- Query GET https://api.switchrouter.dev/v1/models to register tool-calling models (such as "deepseek.v3.2" and "qwen.qwen3-coder-480b-a35b") with their exact context_window and max_output_tokens limits.

What is SwitchRouter?

SwitchRouter routes chat-completion requests across supported models and settles the cost against your workspace wallet in NGN. You keep one integration: change the base URL and model name, and keep using the OpenAI SDK you already have.

OpenAI compatibility

The chat-completions endpoint follows the OpenAI request and response shape (messages, choices[].message, usage, SSE streaming). Compatibility is enforced by the API, not implied by a badge — parameters we don’t support are rejected with 400 rather than silently ignored. See the API reference for the exact supported fields.

1. Create an API key

In the Console, open a workspace → API Keys → Create API key. Keys are workspace-scoped workload identities; the secret (sk_sr_…) is shown once, so store it immediately.

env
# .env — server-side only. Never ship this to a browser.
SWITCHROUTER_API_KEY=sk_sr_your_key_here

2. Configure the base URL

Point your client at the API base URL and authenticate with a bearer token. Production is:

base url
https://api.switchrouter.dev/v1

Running SwitchRouter locally? Use your API’s address, e.g. https://api.switchrouter.dev/v1.

3. Choose a model

List the catalogue and pick a model ID. Popular models include:

model IDs
deepseek.v3.2
qwen.qwen3-coder-480b-a35b
anthropic.claude-sonnet-4-5
qwen.qwen3-next-80b-a3b
mistral.ministral-3-14b-instruct
list models
curl https://api.switchrouter.dev/v1/models

4. Make your first request

curl
curl https://api.switchrouter.dev/v1/chat/completions \
  -H "Authorization: Bearer $SWITCHROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Title: Quickstart" \
  -d '{
    "model": "deepseek.v3.2",
    "messages": [{ "role": "user", "content": "Hello from SwitchRouter" }]
  }'
javascript
import OpenAI from "openai";

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

const completion = await client.chat.completions.create({
  model: "deepseek.v3.2",
  messages: [{ role: "user", content: "Hello from SwitchRouter" }],
});

console.log(completion.choices[0]?.message?.content);
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 App"},
)

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

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

5. Stream a response

Set stream: true to receive Server-Sent Events. Add stream_options: { include_usage: true } to get a final chunk carrying token usage.

javascript
const stream = await client.chat.completions.create({
  model: "deepseek.v3.2",
  messages: [{ role: "user", content: "Explain recursion simply." }],
  stream: true,
  stream_options: { include_usage: true },
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

6. Usage and billing

Every request is attributed to its API key and settled against your workspace wallet. Inspect spend, requests and tokens under Usage, and balance, funding and history under Billing, in the Console.

Troubleshooting

Every response carries a request ID
The x-switchrouter-request-id response header identifies a request. Include it when reporting an issue.
  • 401 invalid_api_key — missing, revoked or expired key.
  • 400 unsupported_parameter — a request field the API does not accept.
  • 400 unsupported_capability — the model cannot do what you asked (e.g. streaming, tools).
  • 402 insufficient_balance — fund the workspace wallet.
  • 429 rate_limited — slow down and honour the retry-after-* header.

See Production & troubleshooting for error handling, retries and rate limits.

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