Stream Events
Task API
Stream Events
Unified SSE stream for history replay and live task events
GET
Stream Events
Stream Task Events
Connect to the unified SSE stream to receive the complete conversation history followed by live execution events. This is the recommended way to build a real-time chat UI.Request
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The unique task identifier |
Stream Behavior
The stream delivers events in three phases:- History replay - Emits
history_messageevents for each saved conversation message - History complete - Emits
history_donewith{ messageCount, isStreaming } - Live events (if task is running) - Catch-up state followed by real-time
content,thought,tool_call,tool_result,subagent_start,subagent_thought,subagent_tool,subagent_end,error, anddoneevents
history_done.
Reconnection
You can disconnect and reconnect at any time. On reconnect, the stream replays the full history and catches up to the current state. The task continues executing in the background regardless of stream connections - disconnecting does not cancel the task.Heartbeat
The server sends:heartbeat comments every 15 seconds to keep the connection alive. These can be safely ignored by your SSE parser.
Stream Output Example
Event Types
history_message
A replayed conversation message from history.
| Field | Type | Description |
|---|---|---|
id | string | Message identifier |
role | string | user or assistant |
content | string | Message text |
createdAt | string | ISO timestamp |
attachedFiles | array | Uploaded files (user messages only) |
thoughts | array | Agent reasoning (assistant messages only) |
toolCalls | array | Tool executions (assistant messages only) |
history_done
Signals that history replay is complete.
| Field | Type | Description |
|---|---|---|
messageCount | number | Number of history messages sent |
isStreaming | boolean | Whether the task is currently running (live events follow if true) |
Live Events
Afterhistory_done, if isStreaming is true, the stream delivers live events including content, thought, tool_call, tool_result, subagent events (subagent_start, subagent_thought, subagent_tool, subagent_end), error, and done. See Streaming Events for the complete event format reference.
Examples
Use Cases
Building a Chat UI
Use the stream endpoint to hydrate your chat interface and receive live updates:Reconnecting After Disconnect
The stream endpoint is the recommended way to consume task events. It replaces the previous pattern of reading SSE from POST endpoints. Use
GET /tasks/:id/history as a REST alternative when SSE is not practical.Errors
| Code | Description |
|---|---|
AUTH_REQUIRED | No authentication provided |
INVALID_API_KEY | Invalid or expired API key |
NOT_FOUND | Task with the specified ID was not found |