The stream_events method opens a server-sent event (SSE) connection and yields TaskLifecycleEvent Pydantic models as they arrive. Pass a StreamOptions instance to filter by event type, set a heartbeat interval, and resume from a cursor after reconnection.
Basic usage
The async for loop runs until the server closes the stream or an error is raised. Each event is a validated TaskLifecycleEvent with id, type, and data fields.
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 heartbeat_seconds to a value lower than your infrastructure’s idle connection timeout. A value of 30 works well for most deployments.
StreamOptions fields
Required scope
Streaming events requires the events:read scope on your API key. A missing scope raises an InsufficientScopeError before the stream opens.