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.

OpenAI SDK Compatible
TheRouter.ai works as a drop-in replacement for the OpenAI SDK. Just change the base URL and API key β€” your existing code works immediately.
API Endpoint
Use the global endpoint for all requests: 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.

Using the OpenAI SDK

The fastest way to get started. Use the official OpenAI SDK with TheRouter.ai's base URL.

TypeScript
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
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.

TypeScript
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:

Available Models
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 Mini

Browse 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