Server-sent events: the text/event-stream format
Answer: Server-sent events stream messages over HTTP with the text/event-stream MIME type. Each line is a field: value pair, and a blank line dispatches the event. The OpenAI Python library provides streaming responses using Server-Sent Events (SSE), with stream=True.
Fields (HTML Living Standard)
| Field | Value | |---|---| | data | append the value to the data buffer, then append a line feed | | event | sets the event type; the default event type is "message" | | id | sets the last event ID buffer to the value | | retry | ASCII digits set the reconnection time in milliseconds |
Rules
- A line starting with a colon is ignored, which makes it a comment.
- Event streams are always decoded as UTF-8.
- Clients will reconnect if the connection is closed; a server can stop that with HTTP 204 No Content.
See also
Claims
- id: C1 claim: SSE uses text/event-stream. source: S1 evidence: "with the text/event-stream MIME type"
- id: C2 claim: Streams are always UTF-8. source: S1 evidence: "Event streams are always decoded as UTF-8."
- id: C3 claim: 204 stops reconnection. source: S1 evidence: "told to stop reconnecting using the HTTP 204 No Content response code"
- id: C4 claim: The OpenAI SDK streams with SSE. source: S2 evidence: "We provide support for streaming responses using Server-Sent Events (SSE)."
Sources
- [S1] HTML Living Standard §9.2 Server-sent events. WHATWG. https://html.spec.whatwg.org/multipage/server-sent-events.html . License: CC-BY-4.0. Accessed 2026-11-16.
- [S2] OpenAI Python library README. openai/openai-python (GitHub). https://github.com/openai/openai-python/blob/main/README.md . License: Apache-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: WHATWG, HTML Living Standard §9.2 Server-sent events, CC-BY-4.0 (https://raw.githubusercontent.com/whatwg/html/main/LICENSE). Copyright © WHATWG (Apple, Google, Mozilla, Microsoft); openai/openai-python (GitHub), OpenAI Python library README, Apache-2.0 (https://raw.githubusercontent.com/openai/openai-python/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: WHATWG, HTML Living Standard §9.2 Server-sent events, CC-BY-4.0 (https://raw.githubusercontent.com/whatwg/html/main/LICENSE). Copyright © WHATWG (Apple, Google, Mozilla, Microsoft); openai/openai-python (GitHub), OpenAI Python library README, Apache-2.0 (https://raw.githubusercontent.com/openai/openai-python/main/LICENSE).
Cite this
iinventedlight. 2026. "Server-sent events: the text/event-stream format." iinventedlight Library, iil:note:3p1aey2v, version of 2026-11-16. https://iinventedlight.com/library/notes/server-sent-events-format/. License: CC-BY-4.0.
@misc{iil_note_3p1aey2v,
author = {{iinventedlight}},
title = {{Server-sent events: the text/event-stream format}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/server-sent-events-format/},
note = {Permanent ID iil:note:3p1aey2v. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/server-sent-events-format.md.