Skip to content

Commit 850bfa2

Browse files
Add SSE support documentation for streaming endpoints
Generated-By: mintlify-agent
1 parent bd0a666 commit 850bfa2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

x-api/fundamentals/consuming-streaming-data.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,47 @@ def connect_to_stream(url, bearer_token):
8080
print(line.decode("utf-8"))
8181
```
8282

83+
### Server-Sent Events (SSE)
84+
85+
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.
86+
87+
To use SSE, include the following header when establishing your connection:
88+
89+
```
90+
Content-Type: text/event-stream
91+
```
92+
93+
<Tabs>
94+
<Tab title="Python">
95+
```python
96+
import requests
97+
98+
def connect_to_stream_sse(url, bearer_token):
99+
headers = {
100+
"Authorization": f"Bearer {bearer_token}",
101+
"Content-Type": "text/event-stream"
102+
}
103+
104+
response = requests.get(url, headers=headers, stream=True)
105+
106+
for line in response.iter_lines():
107+
if line:
108+
print(line.decode("utf-8"))
109+
```
110+
</Tab>
111+
<Tab title="cURL">
112+
```bash
113+
curl -X GET "https://api.x.com/2/tweets/search/stream" \
114+
-H "Authorization: Bearer $BEARER_TOKEN" \
115+
-H "Content-Type: text/event-stream"
116+
```
117+
</Tab>
118+
</Tabs>
119+
120+
<Note>
121+
SSE support is currently available on the staging environment only. This will be rolled out to production in a future update.
122+
</Note>
123+
83124
---
84125

85126
## Consuming data

0 commit comments

Comments
 (0)