Node.js SDK
Use the OpenAI Node.js SDK with Foza
Installation#
npm install openaiBasic Usage#
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.foza.ai/v1", apiKey: "sk-foza-xxxxx", }); const response = await client.chat.completions.create({ model: "openai/gpt-4o", messages: [ { role: "system", content: "You are a helpful assistant." }, { role: "user", content: "What is the capital of France?" }, ], }); console.log(response.choices[0].message.content);
Streaming#
const stream = await client.chat.completions.create({ model: "anthropic/claude-sonnet-4.6", messages: [{ role: "user", content: "Tell me a story" }], stream: true, }); for await (const chunk of stream) { const content = chunk.choices[0]?.delta?.content; if (content) process.stdout.write(content); }
The Foza API is fully compatible with the OpenAI Node.js SDK. Just change baseURL and apiKey.