// Node.js 20+. No additional packages required. One billable completion.
const apiKey = process.env.FLONNO_API_KEY;
if (!apiKey) throw new Error("Set FLONNO_API_KEY in your server environment.");
const response = await fetch("https://www.flonno.com/v1/chat/completions", {
  method: "POST",
  headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: process.env.FLONNO_MODEL || "qwen3.8-27b",
    messages: [{ role: "user", content: "Give one practical tip for organizing support tickets." }],
    max_tokens: 128,
    stream: false,
  }),
  signal: AbortSignal.timeout(120_000),
});
if (!response.ok) throw new Error(`Flonno returned HTTP ${response.status}. Check key permissions, model access, and wallet balance.`);
const result = await response.json();
console.log(result.choices?.[0]?.message?.content ?? "No text returned; inspect the response schema.");
console.log("Reported usage:", result.usage ?? "Unavailable");
