Skip to main content
AutoSage can stream live progress, sources, charts, and final answer content so your users can follow a run as it happens. This guide covers the event stream, how to read it, and the non-streaming alternative.

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.
The -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:
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 with fetch, parses each event, and accumulates the answer.
For the best experience, show progress events while the run is active, render final_response content when it arrives, and show sources as soon as they are emitted. Always handle done and error to close the stream cleanly, and treat ping as a no-op.

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.
The response contains the full answer text, its sources, and usage information — the same content the stream produces, delivered all at once.

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.