Lesson 00.06 · Phase 00 · Setup & Tooling

Streaming responses with SSE

Users don't feel total latency, they feel time to first token. Streaming turns a 3-second wait into a reply that starts in half a second, if your parser survives the network.

Learning objectives

  • Explain the Server-Sent Events (SSE) format LLM APIs use to stream: data: lines, blank-line boundaries, and [DONE].
  • Build an incremental SSE parser that's correct no matter where the network splits the bytes, including mid-line and mid-UTF-8 character.
  • Rebuild streamed text and streamed tool calls (arguments arrive in fragments, keyed by index).
  • Measure time to first token (TTFT) versus total time, and know when streaming matters for an agent.

A non-streamed request to a local model takes 3 seconds, and for 3 seconds your UI shows nothing. Streaming fixes that, but naive streaming code breaks in ways that only show up on real networks:

Loading the full lesson…