text/event-stream
Text

Overview

text/event-stream is the media type for Server-Sent Events (SSE), a one-way real-time stream in which the server keeps one HTTP connection open and continuously pushes text events to the client. The browser's EventSource API consumes it.

Details

The event stream is a simple text protocol using line-based `data:`, `event:`, `id:`, and `retry:` fields, with a single blank line ending one event: e.g. `data: hello\n\n`. The encoding is always UTF-8. The server keeps the stream open (not closing the response) with `Cache-Control: no-cache` and settings to prevent proxy buffering. On disconnect the browser auto-reconnects, sending the last `id:` as a `Last-Event-ID` header, making resumption easy.

Unlike WebSocket, SSE is one-way (server to client) and runs over plain HTTP, making it firewall/proxy friendly and simple to implement. However, under HTTP/1.1 it can hit the per-domain concurrent-connection limit (about 6), which HTTP/2 multiplexing alleviates. It suits real-time notifications, progress updates, and LLM token streaming.

Syntax

e.g. Content-Type: text/event-stream

Notes

Related types

Related headers