import fetch from "node-fetch";
const res = await fetch("https://app.llmgrid.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer " + process.env.LLMGRID_PROJECT_TOKEN,
"Content-Type": "application/json"
},
body: JSON.stringify({
tenant_id: "TENANT_123",
project_id: "PROJ_abc",
route: "chat_default",
messages: [
{ role: "system", content: "Be concise." },
{ role: "user", content: "Summarize the pros and cons of no-till farming." }
],
stream: true
})
});
// Handle streaming (SSE-like)
if (!res.ok) throw new Error(await res.text());
const reader = res.body.getReader();
for (;;) {
const { value, done } = await reader.read();
if (done) break;
process.stdout.write(Buffer.from(value).toString());
}