LLMscore
Streaming
Send tokens to the user as they’re generated instead of waiting for the whole answer.
What it is and why it exists
Providers stream responses as server-sent events: small JSON deltas for text, tool-call argument fragments and a final usage event. Streaming doesn’t make generation faster, but perceived latency drops to TTFT.
Quick prototype
Pass the provider’s stream straight through to the browser.
In production, at scale
Proxy the stream through your backend (SSE to the client), assemble tool-call deltas before acting, parse partial JSON incrementally, cancel the upstream call when the client disconnects, and make streams resumable for flaky mobile networks.
Vendors and tools
| OpenAI / Anthropic / Gemini SDKs | Event streams with text and tool-call deltas |
|---|---|
| Vercel AI SDK | Stream helpers and UI hooks for React |
| FastAPI StreamingResponse / sse-starlette | Python SSE endpoints |
On AWS: Bedrock InvokeModelWithResponseStream / ConverseStream; API Gateway and Lambda response streaming for the HTTP side.
How it fails
- Buffering proxies (or gzip) that hold the stream until it ends
- Acting on a half-received tool call
- Users closing the tab while you keep paying for tokens
What the interviewer asks next
How do you stream structured output to a UI?
Parse the partial JSON incrementally and render fields as they complete; only commit side effects once the final object validates.
SSE or WebSockets for a chat UI?
SSE: one-way, plain HTTP, auto-reconnect, works through most proxies. WebSockets when the client must send data mid-stream (voice, collaborative editing).