Streaming AI Replies with SSE on Cloudflare Workers
How BusyChat streams chat answers token-by-token from a Cloudflare Worker using Server-Sent Events — and the deploy gotcha that cost me an afternoon.
A chatbot that waits five seconds and then dumps a wall of text feels broken, even when it's correct. Streaming the answer as it's generated is what makes it feel alive.
Why SSE over WebSockets
For one-way model output, Server-Sent Events are simpler than WebSockets: a plain HTTP response that stays open and emits chunks. No handshake, no extra protocol, and it works cleanly from a Cloudflare Worker.
The adapter pattern
Each LLM provider exposes streaming differently, so I put a thin stream() method behind a common adapter. The Worker reads tokens from the provider and forwards them down the SSE connection as they arrive; the client appends them to the bubble in real time.
The gotcha
Workers cache aggressively. A stale build kept serving the old non-streaming handler even after deploy, and I chased a "streaming doesn't work" ghost that was really a caching artifact. Lesson: when a Worker behaves like old code, suspect the cache before the logic.
The payoff is a reply that types itself out the instant the model starts thinking — the small detail that makes the whole thing feel premium.