Last-Event-ID

When a Server-Sent Events connection drops, the client needs to resume without data loss. The HTTP Last-Event-ID request header carries the ID of the last received event during reconnection, allowing the server to resume transmission from the correct position.

Usage

Server-Sent Events (SSE) provides a standard mechanism for servers to push real-time updates to clients over HTTP. Connections sometimes drop due to network instability, timeouts, or server restarts. The Last-Event-ID header enables automatic resumption of event streams after connection loss.

When an SSE stream includes an id field in its events, the browser's EventSource API stores this value. If the connection drops and the EventSource attempts to reconnect, the browser includes the Last-Event-ID header in the reconnection request. The server reads this header and resumes sending events from the appropriate position in the stream, preventing data loss or duplicate delivery.

The header value is a UTF-8 encoded string matching the id field from the last successfully received event. Servers typically use this ID to query their event log or buffer and determine which events the client still needs. An empty id field in the event stream resets the stored ID, resulting in no Last-Event-ID header being sent during the next reconnection attempt.

Values

The Last-Event-ID header contains a single string value matching the event ID sent by the server in the SSE stream. The value is any UTF-8 encoded text excluding null characters (U+0000), line feeds (U+000A), and carriage returns (U+000D).

Event IDs are typically sequential integers, timestamps, UUIDs, or database cursor tokens, depending on how the server generates and tracks events.

Example

A client receiving events from a notification stream drops the connection after receiving an event with id: 1234. When the EventSource reconnects, the browser sends the stored ID back to the server.

Last-Event-ID: 1234

The server uses this ID to locate the next event in its buffer and resumes sending events from the stored position forward, maintaining stream continuity without client intervention.

Note

Server-Sent Events work over HTTP/2 and HTTP/3 without protocol changes. SSE uses standard HTTP responses with a text/event-stream content type, and multiplexing in HTTP/2 and HTTP/3 eliminates the connection-per-stream limit that affected HTTP/1.1 deployments.

See also

Last updated: April 4, 2026