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.

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
  • API Reference — Complete endpoint documentation
  • Streaming — Detailed guide to streaming responses