Using Agent SDK to Support Long-Running SSE Connections
I'd like to experiment with Server Sent Events (SSE) and Datastar to serve up an interactive website using potentially long-running SSE connection streams. I've read about ways to game this in standard workers but there is a CPU-limit that can occur which requires a keep-alive signal on the stream to bypass and it's not "officially" supported (meaning, this might not be allowed moving forward).
I notice that the Agent SDK specifically calls out support for long-running SSE connections as being supported:
https://developers.cloudflare.com/agents/api-reference/http-sse/#implementing-server-sent-events
1. Is it possible to leverage this but simply not respond with any form of Ai? Can we use this as a generic way to implement SSE with workers?
2. Is this overkill and is it potentially better (and simpler) to just do this in a standard worker with SSE headers and an empty keep-alive event?
3. Is there an option 3?
Is there a way to calculate potential costs with workers and long-running connections? We'd be talking about a long-running connection per-frontend client.
Cloudflare Docs
HTTP and Server-Sent Events
The Agents SDK allows you to handle HTTP requests and has native support for Server-Sent Events (SSE). This allows you build applications that can push data to clients and avoid buffering.
0 Replies