Chat API (TypeScript)
Methods, examples, and parameters for client.chat.
Module Overview
OpenAI-compatible chat APIs with TheRouter.ai routing, guardrails, and fallbacks.
Available Methods
client.chat.completions.create()- Create a chat completion.client.chat.completions.stream()- Stream chat completion chunks.client.chat.sessions.list()- List persisted chat sessions.
Examples
TypeScript
import { TheRouter.ai } from "@therouter/sdk";
const client = new TheRouter.ai({ apiKey: process.env.THEROUTER_API_KEY! });
const completion = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4.5",
messages: [{ role: "user", content: "Plan a launch checklist." }],
});
console.log(completion.choices[0].message.content);chat-response.json
{
"id": "req_01HXYZ123",
"module": "chat",
"status": "ok"
}Parameter Types
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Required | Model ID, for example anthropic/claude-sonnet-4.5. |
messages | array | Required | Conversation messages in order. |
stream | boolean | Enable SSE streaming response. |
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.