Synrouter Docs

Quickstart

Use Synrouter by changing your base URL and sending an sk-sr API key. Works with any OpenAI-compatible or Anthropic-compatible client — no SDK changes needed.

1. Choose a base URL

For OpenAI-compatible SDKs, set the base URL to https://synrouter.ai/api/v1.

For Anthropic-compatible clients, set the base URL to https://synrouter.ai/api/anthropic.

Synrouter is fully protocol-compatible — any library that works with the OpenAI or Anthropic API will work with Synrouter by changing only the base URL and API key.

2. Authenticate

Send your Synrouter API key in the Authorization header as a Bearer token. Keys use the sk-sr-* prefix.

http
1Authorization: Bearer sk-sr-...

3. Make your first request

bash
1curl https://synrouter.ai/api/v1/chat/completions \
2 -H "Authorization: Bearer sk-sr-..." \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "deepseek/deepseek-v4-flash",
6 "messages": [
7 { "role": "system", "content": "You are a concise coding assistant." },
8 { "role": "user", "content": "Explain what an API gateway does in one sentence." }
9 ]
10 }'

4. Streaming

Set stream: true to receive server-sent events (SSE) — fully compatible with OpenAI and Anthropic streaming protocols.

bash
1curl https://synrouter.ai/api/v1/chat/completions \
2 -H "Authorization: Bearer sk-sr-..." \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "deepseek/deepseek-v4-flash",
6 "stream": true,
7 "messages": [
8 { "role": "user", "content": "Write a haiku about coding." }
9 ]
10 }'

OpenAI SDK — Python

python
1from openai import OpenAI
2
3client = OpenAI(
4 base_url="https://synrouter.ai/api/v1",
5 api_key="sk-sr-...",
6)
7
8response = client.chat.completions.create(
9 model="deepseek/deepseek-v4-flash",
10 messages=[
11 {"role": "user", "content": "Write a tiny Python function that adds two numbers."}
12 ],
13)
14
15print(response.choices[0].message.content)

OpenAI SDK — TypeScript

typescript
1import OpenAI from "openai";
2
3const client = new OpenAI({
4 baseURL: "https://synrouter.ai/api/v1",
5 apiKey: process.env.SYNROUTER_API_KEY,
6});
7
8const response = await client.chat.completions.create({
9 model: "deepseek/deepseek-v4-flash",
10 messages: [
11 { role: "user", content: "Write a short TypeScript debounce function." },
12 ],
13});
14
15console.log(response.choices[0]?.message?.content);

Anthropic-compatible request

bash
1curl https://synrouter.ai/api/anthropic/v1/messages \
2 -H "Authorization: Bearer sk-sr-..." \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "anthropic/claude-sonnet-4.6",
6 "max_tokens": 256,
7 "messages": [
8 { "role": "user", "content": "Summarize prompt caching for coding agents." }
9 ]
10 }'

Error handling

Synrouter returns standard HTTP status codes:

  • 200 — Success. Check x-synrouter-* headers for savings info.
  • 401 — Missing or invalid API key. Verify your Authorization header.
  • 429 — Rate limited. Back off and retry after the Retry-After duration.
  • 500 — Upstream provider error. Synrouter retries with exponential backoff before surfacing the error.