Skip to main content
Long-lived connections drop on deploys, network switches, and sleeping laptops, and the server closes every stream after about 4 minutes. Each stored event carries a monotonic seq. Reconnect after the last processed sequence to receive later events.
Each SSE frame sets id to the event’s seq. Stored events replay first, then live ones follow with no gap (see Stream session events for query options).

With the SDK

client.sessions.events.stream reconnects automatically and filters out events it already delivered. To survive a process restart, persist each seq as you handle it and pass it back as after:
follow.mts
Run npx tsx follow.mts "$SESSION_ID" from the same directory each time. The checkpoint belongs to a deployment and Session. Run one follower per checkpoint. A missing checkpoint starts the stream from the beginning. If an existing checkpoint is unreadable, incomplete, or belongs to another deployment or Session, the example stops before opening a stream. The follower checkpoints each event after handling it. If the process exits after an external effect and before the checkpoint is replaced, that event can replay. For duplicate suppression across restarts, use a durable idempotency key derived from the deployment, Session ID, and sequence, or commit the processing record and the external effect in one transaction.

Catch up from history

To render an existing transcript and then follow live updates, page through the list endpoint and start streaming from the last seq:

In the browser

EventSource cannot send an Authorization header, and your API key should stay on your server. Relay the stream from your backend and forward the browser’s Last-Event-ID header as after. Add an agent to your app shows a working relay.