From 850bfa209a9d0623658029c5cffc309a26ed4055 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 05:04:37 +0000 Subject: [PATCH] Add SSE support documentation for streaming endpoints Generated-By: mintlify-agent --- .../fundamentals/consuming-streaming-data.mdx | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/x-api/fundamentals/consuming-streaming-data.mdx b/x-api/fundamentals/consuming-streaming-data.mdx index 9648fa71d..ad8c8fd5c 100644 --- a/x-api/fundamentals/consuming-streaming-data.mdx +++ b/x-api/fundamentals/consuming-streaming-data.mdx @@ -80,6 +80,47 @@ def connect_to_stream(url, bearer_token): print(line.decode("utf-8")) ``` +### Server-Sent Events (SSE) + +All streaming endpoints also support [Server-Sent Events (SSE)](https://www.w3.org/TR/2012/WD-eventsource-20120426/). SSE is a standard protocol that enables servers to push data to clients over HTTP, and is natively supported by most browsers and HTTP client libraries. + +To use SSE, include the following header when establishing your connection: + +``` +Content-Type: text/event-stream +``` + + + +```python +import requests + +def connect_to_stream_sse(url, bearer_token): + headers = { + "Authorization": f"Bearer {bearer_token}", + "Content-Type": "text/event-stream" + } + + response = requests.get(url, headers=headers, stream=True) + + for line in response.iter_lines(): + if line: + print(line.decode("utf-8")) +``` + + +```bash +curl -X GET "https://api.x.com/2/tweets/search/stream" \ + -H "Authorization: Bearer $BEARER_TOKEN" \ + -H "Content-Type: text/event-stream" +``` + + + + +SSE support is currently available on the staging environment only. This will be rolled out to production in a future update. + + --- ## Consuming data