How to Monitor Twitter Accounts and Keywords in Real Time via API
Real-time Twitter monitoring - detecting new tweets from specific accounts, tracking keyword mentions as they happen, and feeding live X data into your applications - is the foundation of social listening, breaking news alerts, competitive intelligence, and automated engagement tools. This guide shows you how to build a near-real-time monitoring system using the Sorsa API that detects new tweets within seconds of posting, with complete working examples in Python and JavaScript. Sorsa API delivers fresh data on every request: if a tweet was posted half a second ago, your next API call will return it. Combined with a rate limit of 20 requests per second and response times under 400ms, you can build monitoring loops that rival dedicated streaming services - with the simplicity of standard REST calls and without managing persistent connections, reconnection logic, or complex authentication flows.How Polling-Based Monitoring Works
There are two approaches to getting real-time data from a social platform: push-based (streaming/webhooks) and pull-based (polling). The official X API offers a Filtered Stream endpoint, but it requires expensive access tiers ($5,000+/month Pro plan), persistent HTTP connections with reconnection logic, and careful rule management. Sorsa API uses a pull-based approach. The pattern has four steps:- Poll an endpoint at a regular interval (every 1-30 seconds).
- Compare results against previously seen tweet IDs to identify new tweets.
- Process new tweets - send alerts, store in a database, post to Slack, etc.
- Repeat.
Choosing the Right Endpoint
| What you want to monitor | Endpoint | Method | Why this one |
|---|---|---|---|
| A single account | /user-tweets | POST | Returns the latest tweets from one user’s timeline. |
| A group of accounts (up to 5,000) | /list-tweets | GET | Single request covers all members of an X List. |
| A keyword or hashtag | /search-tweets | POST | Full search operator support, chronological ordering. |
| @mentions of an account | /mentions | POST | Purpose-built for mention tracking with engagement filters. |
Level 1: Monitor a Single Account
The simplest case. You want to know the moment a specific account posts something new - a competitor, a CEO, a regulator, or an influencer.Python
JavaScript
Level 2: Monitor Many Accounts with a Single Request
X Lists let you group up to 5,000 accounts and fetch their combined activity in one API call via/list-tweets. This is the most efficient approach for multi-account monitoring and the pattern you should default to in production. For more on working with Lists, see Lists & Communities.
Step 1: Create a Public X List
- Go to X Lists and create a new list.
- Add the accounts you want to monitor.
- Make sure the list is Public - private lists cannot be accessed via the API.
- Copy the List ID from the URL (e.g., in
https://x.com/i/lists/1234567890, the ID is1234567890).
Step 2: Poll the List
/list-tweets costs 8,640 requests/day - a 50x reduction. For more cost optimization patterns like this, see Optimizing API Usage.
Level 3: Monitor a Keyword or Hashtag
Instead of tracking specific accounts, you can monitor a keyword, hashtag, or complex search query in real time. This uses/search-tweets with order: "latest" for chronological results.
Routing New Tweets to Slack, Discord, or Webhooks
The monitoring loop detects new tweets; the callback decides what to do with them. Here is a callback that forwards each tweet to a Slack channel via an Incoming Webhook:API Usage Calculator
Polling uses one request per cycle. Before choosing your interval, consider the monthly cost:| Interval | Req/Hour | Req/Day | Req/Month (30d) |
|---|---|---|---|
| 1 second | 3,600 | 86,400 | 2,592,000 |
| 5 seconds | 720 | 17,280 | 518,400 |
| 10 seconds | 360 | 8,640 | 259,200 |
| 30 seconds | 120 | 2,880 | 86,400 |
| 1 minute | 60 | 1,440 | 43,200 |
For high-volume monitoring needs that exceed standard plan limits, contact us at [email protected] or on Discord for custom enterprise quotas and volume discounts.
Production Hardening
The examples above work for development and testing. For production, address these three concerns:1. Persist last_seen_id Across Restarts
If your script crashes and restarts without remembering its checkpoint, it either reprocesses old tweets (duplicate alerts) or misses the gap entirely. Store the last seen ID in a file, database, or Redis:
2. Implement Exponential Backoff for Errors
Network issues, rate limits (HTTP 429), and temporary API errors will happen. Instead of retrying immediately, back off gradually. For the full error code reference, see Error Codes.3. Separate Polling from Processing
Do not run expensive operations (NLP, database writes, external API calls) synchronously inside the polling loop. If a downstream system is slow, your polling loop falls behind schedule. Instead, push new tweets into a queue and process them in a separate worker:4. Monitor Your Monitor
In production, log each poll cycle (timestamp, new tweet count, errors). Set up an alert if the monitor has not completed a successful poll in the last N minutes - this catches silent failures before they become data gaps. You can check the API’s operational status at any time on the Sorsa Status Page.Next Steps
- Search Operators - use advanced filters to reduce noise in keyword-based monitoring.
- Track Mentions - dedicated endpoint for tracking @mentions with engagement filters.
- Rate Limits - handling 429 errors and optimizing request patterns.
- Pagination - backfill historical data alongside real-time monitoring.
- API Reference - full specification for
/list-tweets,/user-tweets,/search-tweets, and all Sorsa API endpoints.