Node.js SDK
Use the OpenAI JavaScript SDK with a custom baseURL. Prepare Node.js 20 LTS or a newer supported version, and set your environment variables. These examples run on a server.
1. Install
Run in your own project directory:
npm install openai2. Connect and list models
Base URL: https://api.xuo.cc/v1.
Put this code in xuo-models.mjs:
import OpenAI from 'openai';
if (!process.env.XUO_API_KEY) {
throw new Error('Set XUO_API_KEY in your terminal first.');
}
const client = new OpenAI({
apiKey: process.env.XUO_API_KEY,
baseURL: 'https://api.xuo.cc/v1',
timeout: 60_000,
maxRetries: 0,
});
for await (const model of client.models.list()) {
console.log(model.id);
}node xuo-models.mjsChoose an available model supporting Chat Completions and set its full ID as XUO_MODEL.
3. Send a request
Put this code in xuo-chat.mjs:
import OpenAI from 'openai';
if (!process.env.XUO_API_KEY || !process.env.XUO_MODEL) {
throw new Error('Set XUO_API_KEY and XUO_MODEL in your terminal first.');
}
const client = new OpenAI({
apiKey: process.env.XUO_API_KEY,
baseURL: 'https://api.xuo.cc/v1',
timeout: 60_000,
maxRetries: 0,
});
const response = await client.chat.completions.create({
model: process.env.XUO_MODEL,
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(response.choices[0].message.content ?? '');node xuo-chat.mjsAutomatic retries are disabled during setup. For production retries, limit attempts and use backoff. After a timeout, check Usage Logs before resending to avoid additional consumption.
Connecting a web application
Have the browser call your own backend, which holds the key and calls Xuo. Do not bundle the key into browser code or enable a browser SDK to expose a server-side key.
Streaming & troubleshooting · Existing API examples · Official SDK documentation
