For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DashboardSign Up
  • Getting Started
    • Welcome
    • Quick Start
    • Authentication
  • Native Mode
    • Overview
    • OpenAI
    • Anthropic
    • Gemini
  • Unified Mode
    • Overview
    • Python
    • TypeScript
    • cURL
  • Platform
    • Key Management
    • Rate Limits & Budgets
    • Usage & Billing
    • Error Reference
  • API Reference
DashboardSign Up
On this page
  • Setup
  • Basic chat
  • Streaming
  • Tool calling
  • System messages
  • Switching providers
Unified Mode

TypeScript (Unified Mode)

Call any provider using the OpenAI Node.js SDK
Was this page helpful?
Edit this page
Previous

cURL (Unified Mode)

Raw HTTP examples for the unified endpoint
Next
Built with

Setup

$npm install openai
1import OpenAI from "openai";
2
3const client = new OpenAI({
4 apiKey: "sk-proxy-YOUR_KEY_HERE",
5 baseURL: "https://api.trygateway.ai/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}