The streamEvents method opens a server-sent event (SSE) connection and yields TaskLifecycleEvent objects as they arrive. You can filter by event type, control reconnection with a cursor, and cancel the stream with an AbortController.
Basic usage
The for await loop runs until the stream closes or the signal is aborted. Each event object carries id, type, and data fields.
Stop the stream
Call abort() on the controller to close the stream from the consumer side:
Reconnect with a cursor
After a disconnect, pass the last received event ID as cursor to resume the stream without missing events:
The server replays any events that occurred after the cursor position.
Event types
Set heartbeatSeconds to a value lower than your load balancer’s idle connection timeout. A value of 30 works well for most deployments.
Required scope
Streaming events requires the events:read scope on your API key. A missing scope returns a 403 response before the stream opens.