Server-Sent Events streaming: define it and explain why chat APIs default to it
SSE is a one-way HTTP streaming protocol; chat APIs use it so each generated token can be flushed to the client the moment it is produced.
Imagine watching a slow printer dispense a long receipt. Instead of waiting for the whole receipt and then handing it to you, the printer slides each line out as soon as the ink dries. SSE is that printer for an LLM. The server opens one ordinary HTTP connection to your browser and keeps it open. Every time the model generates a new token, the server pushes a tiny event down that pipe, and the browser stitches the events together on screen. Compared to alternatives, SSE is simple: plain HTTP, no upgrade handshake, no two-way channel needed because the server is the only one talking. Your code just opens the URL, listens, and renders text as it arrives.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: define SSE as one-way HTTP streaming, name the `text/event-stream` content type and `EventSource` API, explain the TTFT win for token generation, contrast with WebSockets on directionality and handshake, and name one production gotcha around proxy buffering.
Real products, models, and research that use this idea.
- OpenAI Chat Completions with `stream: true` returns `text/event-stream` and pushes `data: {delta}` chunks plus a final `data: [DONE]` sentinel.
- Anthropic Messages streaming sends typed SSE events like `message_start`, `content_block_delta`, and `message_stop` for structured client parsing.
- vLLM and Hugging Face TGI both expose OpenAI-compatible SSE endpoints so any OpenAI SDK can consume their streams unchanged.
- Production deployments behind nginx or Cloudflare set `proxy_buffering off` and `X-Accel-Buffering: no` to stop the proxy from coalescing the stream.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the server detect a client disconnect during an SSE stream, and why does that matter for cost?
QWhy does HTTP/2 not replace SSE with server-push for LLM streaming?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking SSE is bidirectional like WebSockets. SSE is server to client only over plain HTTP; the client uses a separate POST for the request that opened the stream.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.