Example
Save this as chat.mjs and run node chat.mjs.
const res = await fetch("https://api.luv13.ai/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.LUV13_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "luv13/glm-5.3-flash",
messages: [{ role: "user", content: "Name one planet." }],
}),
signal: AbortSignal.timeout(60_000),
});
if (!res.ok) {
throw new Error(`luv13 returned ${res.status}: ${await res.text()}`);
}
const data = await res.json();
console.log(data.choices[0].message.content);Notes
- Keep this on the server. Calling luv13 from browser code would expose your key to anyone who opens the page. See API Key Best Practices.
- For retries, types and streaming helpers, the OpenAI SDKs may be easier.
- For reading a streamed reply, see Server-Sent Events.
Related
For a short luv13-only version of this example, see JavaScript Example.
