Unified Mode
TypeScript (Unified Mode)
Call any provider using the OpenAI Node.js SDK
Setup
$ npm install openai
1 import OpenAI from "openai"; 2 3 const client = new OpenAI({ 4 apiKey: "sk-proxy-YOUR_KEY_HERE", 5 baseURL: "https://gateway.example.com/v1", 6 });
Basic chat
1 const response = await client.chat.completions.create({ 2 model: "anthropic/claude-sonnet-4-6", 3 messages: [{ role: "user", content: "Hello!" }], 4 }); 5 6 console.log(response.choices[0].message.content);
Streaming
1 const 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 7 for await (const chunk of stream) { 8 const content = chunk.choices[0]?.delta?.content; 9 if (content) process.stdout.write(content); 10 }
Tool calling
1 const 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 23 const toolCall = response.choices[0].message.tool_calls?.[0]; 24 if (toolCall) { 25 console.log(`${toolCall.function.name}(${toolCall.function.arguments})`); 26 }
System messages
1 const 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
1 const models = [ 2 "openai/gpt-4o", 3 "anthropic/claude-sonnet-4-6", 4 "google/gemini-2.5-flash", 5 ]; 6 7 for (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 }