Skip to content
anythingai.space
Backend for AIintermediate11 min · 10 steps

Streaming with SSE

Server-sent events stream tokens, agent status and citations over one long-lived HTTP response, which is how model APIs stream and the simplest way to stream to a browser.

first visible text3.7s
POST messageone JSON blob0.0 s → 3.7 s: blank screen, then everything at onceBrowserchat UIAssistant APIreturns JSON at the endModel APIstreams via SSE
requesttokenresponsetool calldataerror
metrics are illustrative
1 / 10
ProblemStep 1 of 10

Nothing on screen until the whole answer is done

A user asks "Is my VPN ticket still open?". The agent looks up tickets, calls the model and writes ~120 tokens. Returned as one JSON response, the screen stays blank for almost 4 seconds.

Worse, the user can't see that anything is happening: no "looking up your tickets", no partial text, no sign the request didn't just hang.

Lesson 4 of 20 in Backend for AI