How it works

SSE, Server-Sent Events, is an HTTP standard where the server keeps a connection open and sends messages to the client as they are generated. The client uses the browser's EventSource API, or reads the stream in other languages, and receives events in real time.

Unlike WebSocket, which is bidirectional, SSE is unidirectional: only the server sends. This simplifies implementation and works over plain HTTP, passing through proxies and firewalls with fewer issues.

Practical example

A server sends SSE events like this:

Terminal
curl -N https://api.exemplo.com/stream \
  -H "Accept: text/event-stream"

The response arrives in chunks with the prefix data::

data: {"token": "Olá"}

data: {"token": " mundo"}

data: [DONE]

The client reads each line and updates the interface. Chat APIs, OpenAI and Anthropic, use SSE for response streaming.

What it's for

SSE is for cases where the server needs to push data to the client continuously: streaming responses from AI models, notifications, real time logs and progress of long running tasks. It is the technical foundation for response streaming in many AI products, because it is simple and compatible with HTTP.