Documentation/OpenAI JavaScript SDK

OpenAI JavaScript SDK

OpenAI JavaScript SDK

OpenAI JavaScript SDK

Prepare

Use a gateway root, a virtual key with model access and a public model name. Test GET /v1/models first.

Configure

Install openai and read settings from server environment variables. Do not expose the key in public browser variables.

Verify and troubleshoot

Send “Hello, introduce yourself.” and inspect the call ID in XHub request logs. Verify streaming, tool calls and images separately against deployment capabilities. For 401 check the virtual key; for 403 check model scope; for 404 check the URL and duplicated /v1. Client settings vary by version.

Request example

import OpenAI from "openai";
const client = new OpenAI({
  apiKey: process.env.XHUB_API_KEY,
  baseURL: process.env.XHUB_BASE_URL.replace(/\/$/, ""),
});
const response = await client.chat.completions.create({
  model: "YOUR_MODEL_NAME",
  messages: [{ role: "user", content: "Hello, introduce yourself." }],
});
console.log(response.choices[0].message.content);

Search full documentation: budgets, routing, Docker…