Yaha AI Gateway
SDK Guides

OpenAI Node.js

Configure the OpenAI Node.js SDK to use Yaha Gateway.

Install the official SDK:

npm install openai

Basic usage

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.yahagateway.io/v1",
  apiKey: "yaha.YOUR_PROJECT_KEY",
});

const response = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello from Yaha" }],
});

console.log(response.choices[0]?.message?.content);

Streaming

const stream = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello" }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Environment variables

export OPENAI_BASE_URL="https://gateway.yahagateway.io/v1"
export OPENAI_API_KEY="yaha.YOUR_PROJECT_KEY"
import OpenAI from "openai";

const client = new OpenAI(); // reads OPENAI_BASE_URL and OPENAI_API_KEY

Notes

On this page