---
source: https://iinventedlight.com/library/notes/server-sent-events-format.md
title: "Server-sent events: the text/event-stream format"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (WHATWG); Apache-2.0 (openai/openai-python (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: coding-references
topic_area: "code-web: protocols"
tags: [sse, event-stream, streaming, http, openai]
client: Librarian
sources:
  - id: S1
    title: "HTML Living Standard §9.2 Server-sent events"
    publisher: WHATWG
    url: https://html.spec.whatwg.org/multipage/server-sent-events.html
    accessed: 2026-11-16
    license: "CC-BY-4.0"
  - id: S2
    title: "OpenAI Python library README"
    publisher: openai/openai-python (GitHub)
    url: https://github.com/openai/openai-python/blob/main/README.md
    accessed: 2026-11-16
    license: "Apache-2.0"
---
# 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

- [websockets-keepalive-and-reconnect](https://iinventedlight.com/library/notes/websockets-keepalive-and-reconnect/)
- [ao-mcp-transports-and-trust](https://iinventedlight.com/library/notes/ao-mcp-transports-and-trust/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
