Quickstart
Get started with TheRouter.ai
TheRouter.ai provides a unified, OpenAI-compatible API that gives you access to multiple AI models through a single endpoint. It automatically handles fallbacks and routes requests to the optimal provider. Get started with just a few lines of code.
https://api.therouter.ai/v1. The legacy China accelerated endpoint is retired and should not be used for new integrations.Using a coding client instead of an SDK?
If your first successful request will happen inside a coding tool instead of code, take the dedicated setup path now and come back to SDK details later.
Cursor Integration
Step-by-stepPoint Cursor at TheRouter with the correct OpenAI-compatible base URL, model aliases, and first-request validation.
Open guideClaude Code Integration
Step-by-stepUse TheRouter's Anthropic-compatible path for Claude Code with the exact env overrides and verification steps.
Open guidecc-switch Setup
New guideAdd TheRouter presets to cc-switch so Claude Code, Codex, Gemini CLI, OpenCode, and OpenClaw can share one key and one routing layer.
Open guideCoding Tools Setup
Tool hubBrowse the quick configs for Windsurf, Cline, Continue, OpenCode, OpenClaw, and cc-switch in one place.
Open guideUsing the OpenAI SDK
The fastest way to get started. Use the official OpenAI SDK with TheRouter.ai's base URL.
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://api.therouter.ai/v1',
apiKey: '<THEROUTER_API_KEY>',
});
async function main() {
const completion = await openai.chat.completions.create({
model: 'anthropic/claude-sonnet-4.5',
messages: [
{
role: 'user',
content: 'What is the meaning of life?',
},
],
});
console.log(completion.choices[0].message);
}
main();Using the API Directly
Send requests directly to the TheRouter.ai API endpoint.
Base URL: https://api.therouter.ai/v1
curl https://api.therouter.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $THEROUTER_API_KEY" \
-d '{
"model": "anthropic/claude-sonnet-4.5",
"messages": [
{
"role": "user",
"content": "What is the meaning of life?"
}
]
}'Streaming
TheRouter.ai supports streaming responses via Server-Sent Events (SSE). Add stream: true to your request to receive tokens as they're generated.
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://api.therouter.ai/v1',
apiKey: '<THEROUTER_API_KEY>',
});
const stream = await openai.chat.completions.create({
model: 'anthropic/claude-sonnet-4.5',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content || '';
process.stdout.write(content);
}Model Naming
TheRouter.ai uses a standard provider/model-name format. For example:
anthropic/claude-opus-4.6 # Claude Opus 4.6
anthropic/claude-sonnet-4.5 # Claude Sonnet 4.5
anthropic/claude-haiku-4.5 # Claude Haiku 4.5
openai/gpt-4o # GPT-4o
openai/gpt-4o-mini # GPT-4o MiniBrowse all available models on the Models page.
Next Steps
- Principles β Learn about TheRouter.ai's architecture and design decisions
- Model Fallbacks β Configure automatic failover between providers
- Coding Tools Setup β Open the hub for Cursor, Claude Code, cc-switch, OpenClaw, and other coding clients
- cc-switch Integration β Use TheRouter presets when one team switches across multiple local coding clients
- API Reference β Complete endpoint documentation
- Streaming β Detailed guide to streaming responses