LogoToRouter Docs
LogoToRouter Docs
HomepageWhat is ToRouter5-minute quickstartCore concepts
OpenAI Python SDKOpenAI Node / TypeScript SDKAnthropic SDK (Python & TypeScript)Google Gen AI SDK (Gemini)CursorCline (VS Code extension)Claude Code CLILangChain & LlamaIndexDify & n8n (no-code)
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

FieldValue
Base URLhttps://portal.torouter.ai/v1
API keysk-***
Modelgpt-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 openai

Code

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), not base_url. Passing the Python-style snake_case is silently ignored.
  • In browser code set dangerouslyAllowBrowser: true only 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 fetch build of the SDK and avoid Node-only modules.

Next steps

Create an API key

Base URL & auth reference

Model catalog

Troubleshoot errors

OpenAI Python SDK

Call GPT, Claude, Gemini and every other model in the catalog from the official openai Python package.

Anthropic SDK (Python & TypeScript)

Use the native Anthropic /v1/messages API and the official anthropic SDKs against ToRouter.

Table of Contents

ConfigurationInstallCodeNext steps