Unified Mode

TypeScript (Unified Mode)

Call any provider using the OpenAI Node.js SDK

Setup

$npm install openai
1import OpenAI from "openai";
2
3const client = new OpenAI({
4 apiKey: "sk-proxy-YOUR_KEY_HERE",
5 baseURL: "https://gateway.example.com/v1",
6});

Basic chat

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

Streaming

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

Tool calling

1const response = await client.chat.completions.create({
2 model: "google/gemini-2.5-flash",
3 messages: [{ role: "user", content: "What's the weather in London?" }],
4 tools: [
5 {
6 type: "function",
7 function: {
8 name: "get_weather",
9 description: "Get weather for a city",
10 parameters: {
11 type: "object",
12 properties: {
13 city: { type: "string" },
14 },
15 required: ["city"],
16 },
17 },
18 },
19 ],
20 tool_choice: "auto",
21});
22
23const toolCall = response.choices[0].message.tool_calls?.[0];
24if (toolCall) {
25 console.log(`${toolCall.function.name}(${toolCall.function.arguments})`);
26}

System messages

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

Switching providers

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