OpenAI SDK
Use the official OpenAI SDK (Node.js or Python) with ApiLux. Two lines of configuration.
Step 1 — Install the SDK and set your key
npm install openaipip install openai$env:APILUX_API_KEY = "apl_YOUR_API_KEY"Step 2 — Point the SDK at ApiLux
Only two things change versus a normal OpenAI setup: baseURL and apiKey. The rest of the SDK stays the same.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.APILUX_API_KEY,
baseURL: "https://apilux.net/api/v1",
});
const r = await client.chat.completions.create({
model: "MODEL_ID",
messages: [{ role: "user", content: "Xin chao" }],
});
console.log(r.choices[0]?.message?.content);import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["APILUX_API_KEY"],
base_url="https://apilux.net/api/v1",
)
r = client.chat.completions.create(
model="MODEL_ID",
messages=[{"role": "user", "content": "Xin chao"}],
)
print(r.choices[0].message.content)Step 3 — Streaming
stream=True returns an OpenAI-compatible SSE stream whose final chunk carries usage. That is what makes Cursor, OpenCode and VS Code extensions work: they stream by default and mostly cannot turn it off.
const stream = await client.chat.completions.create({
model: "MODEL_ID",
messages: [{ role: "user", content: "Xin chao" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Disconnecting mid-stream is still billed for what was already generated — the provider already did that work.
Configuration summary
| Item | Value |
|---|---|
| Base URL | https://apilux.net/api/v1 |
| Key variable | APILUX_API_KEY |
| Model | from GET /models |
| Wire protocol | chat.completions (no streaming) |
The full error table lives in the connection test guide.