Integrations
OpenAI Node / TypeScript SDK
Use the official openai npm package against ToRouter from Node, Bun, Deno or the browser.
The official openai npm package (v4+) works against ToRouter unchanged — override baseURL, pass your ToRouter key, and call any model in the catalog.
Configuration
| Field | Value |
|---|---|
| Base URL | https://portal.torouter.ai/v1 |
| API key | sk-*** |
| Model | gpt-5, claude-opus-4-7, gemini-2.5-pro, ... |
The SDK also reads OPENAI_BASE_URL and OPENAI_API_KEY from process.env.
Install
npm install openai
# or: pnpm add openai / bun add openaiCode
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://portal.torouter.ai/v1',
apiKey: 'sk-***',
});
const resp = await client.chat.completions.create({
model: 'gpt-5',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(resp.choices[0].message.content);import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://portal.torouter.ai/v1',
apiKey: 'sk-***',
});
const stream = await client.chat.completions.create({
model: 'claude-opus-4-7',
messages: [{ role: 'user', content: 'Stream me a haiku' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}curl https://portal.torouter.ai/v1/chat/completions \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-5","messages":[{"role":"user","content":"Hello"}]}'Gotchas
- The option is
baseURL(camelCase), notbase_url. Passing the Python-style snake_case is silently ignored. - In browser code set
dangerouslyAllowBrowser: trueonly after you have key-scoped IP and rate limits configured in ToRouter — browser keys leak to network tabs. - Edge runtimes (Vercel Edge, Cloudflare Workers) work; use the global
fetchbuild of the SDK and avoid Node-only modules.