Install the SDK and keep the key on your server
Use a currently supported Node.js runtime for the openai package. In a new project directory, initialize the package and install the SDK. Save the example as kearnix-demo.mjs so Node runs it as an ES module. Do not set dangerouslyAllowBrowser or expose your key through a public frontend environment variable.
npm init -y
npm install openai
# Bun alternative: bun add openaiConfigure the environment
Set KEARNIX_API_KEY to a key from your Kearnix dashboard and KEARNIX_MODEL to an exact live catalog ID, such as qwen/qwen3.8-27b-uncensored. Keep these values in your server's secret/environment settings. These shell examples use a placeholder key.
# macOS / Linux
export KEARNIX_API_KEY='your-kearnix-key'
export KEARNIX_MODEL='qwen/qwen3.8-27b-uncensored'
# PowerShell
$env:KEARNIX_API_KEY = 'your-kearnix-key'
$env:KEARNIX_MODEL = 'qwen/qwen3.8-27b-uncensored'Make a first request
Run node kearnix-demo.mjs. The base URL includes /v1 once; the SDK appends /chat/completions. To try another GLM, Qwen or DeepSeek variant, change KEARNIX_MODEL while keeping the same client configuration. The script prints the returned text and token usage when reported.
import OpenAI from "openai";
if (!process.env.KEARNIX_API_KEY || !process.env.KEARNIX_MODEL) {
throw new Error("Set KEARNIX_API_KEY and KEARNIX_MODEL first.");
}
const client = new OpenAI({
apiKey: process.env.KEARNIX_API_KEY,
baseURL: "https://kearnix.com/v1",
timeout: 60_000,
maxRetries: 0,
});
try {
const completion = await client.chat.completions.create({
model: process.env.KEARNIX_MODEL,
messages: [{ role: "user", content: "Say hello in one sentence." }],
max_tokens: 128,
});
console.log(completion.choices[0]?.message.content ?? "");
console.log("Tokens:", completion.usage?.total_tokens ?? "unreported");
} catch (error) {
if (error instanceof OpenAI.APIError) {
console.error("Request failed. HTTP status:", error.status);
process.exitCode = 1;
} else {
throw error;
}
}
Understand failures and the scope of the example
A nonzero exit code marks an API failure. Check the HTTP status and account dashboard without logging your authorization header or full request content. The first example disables SDK retries; add bounded backoff for transient errors only after deciding how your application handles duplicate attempts and usage.
The SDK request and response handling are checked against a local OpenAI-compatible fixture, including the failure path. This is not a claim that every catalog model supports streaming, tools or structured output. Inspect the exact entry and run a short funded evaluation before enabling those features. SDK reference: https://github.com/openai/openai-node.