Twitter Streaming API Guide: WebSocket vs REST vs Filtered Stream (2026)
How Twitter's streaming API works — filtered stream endpoints, WebSocket alternatives, and code examples for real-time alerts.
What Is the Twitter Streaming API?
The Twitter streaming API (now the X API) lets developers receive tweets in real time as they are posted, rather than polling an endpoint on a schedule. For trading bots, news aggregators, social listening dashboards, and any application where latency matters, streaming is the foundation of a responsive pipeline.
X's v2 API exposes two streaming endpoints: the filtered stream, which delivers tweets matching developer-defined rules, and the sampled stream, which returns a roughly 1 % random sample of all public tweets. Both use long-lived HTTP connections — the server holds the connection open and pushes newline-delimited JSON objects as matching tweets appear.
Historically, Twitter offered earlier streaming surfaces in v1.1. The specific packaging and entitlements around today's X API should always be verified in the current docs and your account console.
How the Streaming Protocol Works Under the Hood
The X streaming API does not use WebSockets. Instead, it relies on HTTP streaming — a long-lived HTTP/1.1 (or HTTP/2) connection where the server sends data incrementally without closing the response. Think of it as downloading an infinitely long file.
Your client opens an HTTP GET request to the filtered stream endpoint. The server responds with status 200 and begins writing newline-delimited JSON. Each tweet arrives as a single line. Between tweets, X sends keep-alive newlines (empty lines) roughly every 20 seconds so your client can detect stalled connections.
This design has consequences. Your HTTP client must support chunked transfer encoding and incremental parsing. Standard request/response libraries (like fetch or axios) buffer the full response before returning it, which defeats the purpose. You need a streaming HTTP client — such as Node.js's built-in http module, Python's requests with stream=True, or a library like undici.
- Protocol: HTTP/1.1 chunked transfer encoding (not WebSocket)
- Format: Newline-delimited JSON, one tweet per line
- Keep-alive: Empty newlines every ~20 seconds
- Reconnect: Client responsible for detecting drops and retrying with backoff
Streaming vs Polling vs WebSocket: A Latency Comparison
Polling (REST) means your app hits a search or timeline endpoint on a timer. You spend requests whether there is new data or not, and your worst-case latency is bounded by your poll interval.
HTTP streaming (X's filtered stream) pushes tweets as they match your rules. It reduces polling overhead, but you still need to verify current access, handle reconnects, and work with raw tweet JSON.
WebSocket delivery also pushes data in real time but over a persistent, bidirectional connection. WebSocket is a separate protocol (RFC 6455) that begins as an HTTP upgrade and then switches to a framed binary/text protocol. It supports server push, client push, ping/pong keep-alives, and built-in close handshakes — none of which HTTP streaming provides.
| Feature | REST Polling | HTTP Streaming (X API) | WebSocket |
|---|---|---|---|
| Typical latency | Poll interval dependent | Push-based; depends on provider | Push-based; depends on provider |
| Protocol | HTTP request/response | HTTP chunked transfer | WebSocket (RFC 6455) |
| Direction | Client pulls | Server pushes | Bidirectional |
| Reconnection | Not needed | Manual backoff required | Application-managed reconnect on socket close |
| Keep-alive | N/A | Empty newlines ~20s | Ping/pong frames |
| Minimum X tier | Check current docs | Check current docs | N/A (third-party) |
| Enrichment | None | None | Depends on provider |
The Filtered Stream Endpoint in Detail
The filtered stream (POST /2/tweets/search/stream/rules to set rules, GET /2/tweets/search/stream to connect) is X's primary real-time endpoint. You define up to 1,000 rules (at Enterprise tier) using a boolean query language similar to the search endpoint.
Each rule can match on keywords, usernames, hashtags, conversation IDs, and more. When a public tweet matches any rule, it appears in your stream with the matching rule IDs attached.
Key limitations to know:
- Rule and connection limits depend on the access level attached to your account
- No historical backfill — you only get tweets posted while connected
- Disconnections can lose data unless you have a recovery path
- Operational limits are part of the product decision, not just the protocol decision
Code Example: Connecting to X Filtered Stream (Node.js)
X API Streaming Access by Tier (April 2026)
Use the current X docs and Developer Console to confirm how streaming access is packaged for your account today:
| Tier | Monthly Cost | Tweet Read Cap | Streaming Access | Rules |
|---|---|---|---|---|
| Pay-per-use | Usage-based | Check X docs | Check current entitlement | Check current entitlement |
| Legacy fixed plans | Legacy / opt-in | Check X docs | Check current entitlement | Check current entitlement |
| Enterprise | Contact sales | Custom | Custom | Custom |
Treat old screenshots and pricing roundup posts as historical context only. Confirm current entitlements directly before you design around them.
Always confirm current pricing at the official X API documentation — tiers and limits change frequently.
Code Example: TweetStream WebSocket Connection
WebSocket Alternatives to the Twitter Streaming API
If you need low-latency monitored-account alerts without owning the full streaming pipeline, WebSocket-based services offer an alternative. These services handle the data pipeline and deliver tweets over a persistent WebSocket connection with additional enrichment.
TweetStream, for example, delivers tweet alerts in ~200 ms with automatic token detection, OCR text extraction from images, and live cryptocurrency prices — features you would need to build yourself on top of the raw X API.
- Push-based delivery with ~200 ms typical latency
- Persistent WebSocket connection with automatic reconnection
- No streaming infrastructure to build or maintain
- Built-in enrichment: OCR, token detection, live prices, Polymarket odds
- Starts at $199/month
When to Use a Streaming Alternative
Consider a WebSocket alternative when:
- You need sub-second delivery for trading or alerting
- You want enriched data (tokens, prices, OCR) without building pipelines
- Official API packaging or operational overhead is not a fit
- You do not want to manage reconnection logic and backfill
- You need specific account monitoring rather than keyword-based rules
Frequently Asked Questions
Next Steps
If you need streaming alerts with enrichment like token detection or OCR, start with the WebSocket quickstart. For a detailed comparison with the official X API, see our Twitter API alternative page.
TweetStream Team
Last updated: April 2026
Start real-time Twitter WebSocket alerts today
WebSocket delivery, OCR, and token detection - no infrastructure to build.
Start 7-Day TrialFrom $199/mo · Basic/Elite 7-day trial · OCR + token detection included
