Skip to content
Guest
AI Engineering · Course Syllabus Show lessons
Production UX · 9 min read · Intermediate

Streaming Responses (SSE) & Perceived Latency

Stream tokens to the browser using Server-Sent Events (SSE) so users see answers in under 500ms.

What you'll learn

  • Measure Time to First Token (TTFT) vs total generation time
  • Stream chunks via HTTP text/event-stream (SSE)
  • Support request cancellation with AbortController when users click Stop

Overview

Stream tokens to the browser using Server-Sent Events (SSE) so users see answers in under 500ms.

Code Example

const res = new Response(stream, {
  headers: {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
  },
});

Key Takeaways

  • Measure Time to First Token (TTFT) vs total generation time
  • Stream chunks via HTTP text/event-stream (SSE)
  • Support request cancellation with AbortController when users click Stop

Quick Check

Check Your Understanding

Score: 0 / 1

1. Which metric improves dramatically when you stream LLM tokens over SSE instead of waiting for the full completion?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind