Skip to Content
Integration GuidesStreaming Replies (SSE)

Streaming replies (SSE)

Streaming delivers responses over Server-Sent Events (SSE) using Content-Type: text/event-stream. Your UI can display typing status steps and stream text as words arrive, rather than waiting for the entire reply.

POST /threads/{id}/messagestext/event-streamYour BackendBella APIStatus & Delta FramesMember Chat UI

Requesting a stream

To stream replies, set "stream": true in the body of POST /api/v1/threads/{id}/messages:

{ "text": "Can I do barbell squats during week 28 of pregnancy?", "stream": true }

The server returns HTTP 200 OK with Content-Type: text/event-stream. Each event is delivered as a frame terminated by double newlines (\n\n).

Frame types

Every frame includes an event name and a JSON payload in data. The payload also repeats event so clients can parse data directly.

1. Status frames (event: status)

Status frames describe what the assistant is doing before text generation begins:

event: status data: {"event":"status","step":"reading_your_notes","label":"Reading your notes"}

Fields:

  • step: Machine-readable identifier.
  • label: Ready-to-display label for your UI.
Step valueLabelDescription
thinkingThinkingTurn intake and reasoning.
reading_your_notesReading your notesReviewing member memory and context.
searchingSearchingQuerying the content catalogue.
double_checkingDouble-checkingEvaluating clinical safety boundaries.
looking_it_upLooking it upRetrieving exercise or symptom specifics.
checking_your_stageChecking where you're atChecking gestational or postpartum week milestones.
replyingReplyingWord generation started; delta frames follow immediately.

2. Delta frames (event: delta)

Delta frames carry incremental Markdown text chunks:

event: delta data: {"event":"delta","text":"At week 28,"} event: delta data: {"event":"delta","text":" modifying your squat"} event: delta data: {"event":"delta","text":" stance helps manage pelvic pressure."}

Append each text snippet to your local buffer to stream words into the chat UI.

3. Done frames (event: done)

When generation completes and the response is saved, the server emits a done frame and closes the connection:

event: done data: {"event":"done","thread":"thr_9c41f0b7a2d64e83b15c7f20","message":{"id":"msg_7d02edd7fc430c94162cba02","role":"coach","text":"A wider stance helps manage pelvic pressure.","created_at":"2026-11-08T23:08:00.123456Z"}}

The payload echoes the thread ID and returns the persisted coach message object (id, role, text, created_at).


Disconnections mid-stream

If an HTTP connection drops during streaming:

  1. Member message is preserved: The incoming message is saved to the database before processing starts.
  2. Partial generation is discarded: If disconnected before the done frame, partial replies are not stored. This prevents truncated messages in conversation history.
  3. Recovery: Your client can prompt the member to resend or fetch thread history. Member memory remains unchanged.

Production parsers

Here are complete client examples in cURL, TypeScript, and Python showing how to consume the stream, handle buffering across TCP chunks, and dispatch frames.

To inspect raw SSE frames directly in your terminal, use curl -N (no buffer):

curl -N -X POST "https://api.bellacoach.ai/api/v1/threads/thr_9c41f0b7a2d64e83b15c7f20/messages" \ -H "Authorization: Bearer $BELLA_API_KEY" \ -H "Content-Type: application/json" \ -H "Accept: text/event-stream" \ -d '{ "text": "What exercises are recommended for postpartum pelvic recovery?", "stream": true }'

Next steps

Last updated on