Node.js OpenAI SDK
Use the official Node.js SDK from server-side code. Keep the API key in an environment variable and never ship it in browser JavaScript.
Install the SDK
npm install openaiSet an environment variable
export ONEPK_API_KEY="replace-with-your-key"Create a chat completion
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.ONEPK_API_KEY,
baseURL: "https://1pkapi.com/v1",
});
const completion = await client.chat.completions.create({
model: "your-model-id",
messages: [{ role: "user", content: "Summarize this in one sentence." }],
});
console.log(completion.choices[0]?.message?.content ?? "");Next
Read the model list before configuring a model ID. Add streaming only after the short request succeeds.
