const response = await fetch("http://localhost:3000/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ model: "gpt-5.2", messages: [{ role: "user", content: "Say hi in one word" }], stream: true, }), }); console.log("Status:", response.status); const reader = response.body.getReader(); const decoder = new TextDecoder(); let buffer = ""; let count = 0; while (true) { const { done, value } = await reader.read(); if (done) break; buffer += decoder.decode(value, { stream: true }); const lines = buffer.split("\n"); buffer = lines.pop() || ""; for (const line of lines) { if (line.startsWith("data: ")) { count++; const data = line.substring(6); if (data.trim() !== "[DONE]") { try { const parsed = JSON.parse(data); console.log( `Response ${count}:`, JSON.stringify(parsed).substring(0, 200), ); } catch (e) { console.log(`Raw response ${count}:`, data.substring(0, 100)); } } } } }