const response = await fetch("https://api.haloagents.ai/api/sdk/chat/stream", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer ab_live_xxxxxxxxxxxxxxxx",
},
body: JSON.stringify({
user_id: "user_123",
message: "How do I set up event tracking?",
}),
});
// Read metadata from response headers
const sessionId = response.headers.get("X-Session-Id");
const agentId = response.headers.get("X-Agent-Id");
const reader = response.body?.getReader();
const decoder = new TextDecoder();
let fullText = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
fullText += chunk;
// Update your UI with the partial response
updateChatBubble(fullText);
}