SupportAiDocs

Streaming replies

Consume Server-Sent Events from the chat endpoint.

Set "stream": true in the body (or send Accept: text/event-stream) on POST /chatbots/{botId}/chat to receive tokens as they’re generated.

bash
curl -N https://supportai.co.uk/api/public/v1/chatbots/BOT_ID/chat \
  -H "Authorization: Bearer sk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"message":"Where is my order 48213?","stream":true}'

Events #

eventdata
start{ conversationId } — sent immediately.
delta{ text } — a chunk of the reply. Concatenate in order.
tool{ name, input } — the agent is calling an action.
widgetA widget object to render alongside the reply.
doneThe full ChatResponse (same shape as the non-streaming response).

Node.js example #

js
const res = await fetch("https://supportai.co.uk/api/public/v1/chatbots/BOT_ID/chat", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SUPPORTAI_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ message, conversationId, stream: true }),
});

const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });
  let idx;
  while ((idx = buffer.indexOf("\n\n")) !== -1) {
    const frame = buffer.slice(0, idx); buffer = buffer.slice(idx + 2);
    const event = /^event: (.+)$/m.exec(frame)?.[1];
    const data = JSON.parse(/^data: (.+)$/m.exec(frame)?.[1] ?? "null");
    if (event === "delta") process.stdout.write(data.text);
    if (event === "done") console.log("\n", data);
  }
}

Reuse conversationId from the first response on subsequent turns so the agent keeps context and the thread shows as one conversation in the inbox.