Skip to navigation
Unified Mode

TypeScript (Unified Mode)

Call any provider using the OpenAI Node.js SDK

Setup

npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-proxy-YOUR_KEY_HERE",
baseURL: "https://api.enterpriserouter.com/v1",
});

Basic chat

const response = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4-6",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);

Streaming

const stream = await client.chat.completions.create({
model: "openai/gpt-4o",
messages: [{ role: "user", content: "Write a haiku about TypeScript." }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}

Tool calling

const response = await client.chat.completions.create({
model: "google/gemini-2.5-flash",
messages: [{ role: "user", content: "What's the weather in London?" }],
tools: [
{
type: "function",
function: {
name: "get_weather",
description: "Get weather for a city",
parameters: {
type: "object",
properties: {
city: { type: "string" },
},
required: ["city"],
},
},
},
],
tool_choice: "auto",
});
const toolCall = response.choices[0].message.tool_calls?.[0];
if (toolCall) {
console.log(`${toolCall.function.name}(${toolCall.function.arguments})`);
}

System messages

const response = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4-6",
messages: [
{ role: "system", content: "You are a code reviewer. Be concise." },
{ role: "user", content: "Review: const x = arr.filter(i => i > 0).length > 0" },
],
});

Switching providers

const models = [
"openai/gpt-4o",
"anthropic/claude-sonnet-4-6",
"google/gemini-2.5-flash",
];
for (const model of models) {
const response = await client.chat.completions.create({
model,
messages: [{ role: "user", content: "What is 2+2?" }],
});
console.log(`${model}: ${response.choices[0].message.content}`);
}