The streaming endpoint
POST /chats/:id/messages/stream sends a message to an existing chat and returns the response as Server-Sent Events (SSE). The connection stays open, emitting events until the response is complete.
-N flag disables curl’s output buffering so you see events as they stream.
Event types
Each SSE message carries an event with a JSON payload. Handle these types:| Event | What it carries | How to handle it |
|---|---|---|
ping | Keep-alive heartbeat | Ignore it. It only keeps the connection open. |
user_message | Confirmation of the message you sent | Optional — useful to render the user’s turn. |
agent_thought | A progress update from a multi-step run | Show as optional progress UI. |
data_preview | A preview of available grounded data | Use for optional context or progress UI. |
todo_update | Updated task state from the agent | Refresh task or progress UI. |
mcp_tool_call / mcp_tool_result | Tool activity from an MCP server | Show only when your product exposes tool progress. |
final_response | The assistant’s answer in content | Treat isComplete: true as the canonical complete answer. Also support partial events for protocol compatibility. |
sources | Cited source passages | Render as citations when they arrive. |
chart | A structured chart the answer produced | Render the chart. |
tokens | Usage information for the turn | Record for accounting if needed. |
done | The stream has finished successfully | Close the connection. |
error | An error occurred during generation | Surface the message and close the connection. |
The main runtime normally emits one
final_response with isComplete: true and the complete answer in content. Clients should also support partial final_response events: append partial content, then replace the accumulated text with the canonical content when isComplete is true.Read the stream in JavaScript
This example reads the SSE body withfetch, parses each event, and accumulates the answer.
One active stream per chat
A chat has one active stream at a time. If the connection drops mid-response, the partial answer generated so far is saved to the chat. Reopen the chat to see what was produced and continue the conversation from there — you don’t lose progress. To stop a stream in progress, call:Non-streaming alternative
If you don’t need a live experience,POST /chats/:id/messages returns the complete response in a single JSON body once generation finishes.
Next steps
Chat lifecycle
How a chat turn is created, streamed, saved, and resumed.
Streaming reference
The event protocol in full detail.
Chats API
Endpoints for creating chats and sending messages.
Rate limits & credits
Handle backoff and credit balance in your client.