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: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.