How to Monitor a Keyword on X With an API
To monitor a keyword on X, run a search query on a schedule, for example every hour, keep the IDs of posts you've already seen, and alert on the new ones.

To monitor a keyword on X, run a search query on a schedule, for example every hour, keep the IDs of posts you’ve already seen, and alert on the new ones. apidojo’s Twitter Scraper Unlimited suits this because it allows repeated small queries: each hourly query costs $0.016 and includes about 40 posts.
This guide builds a keyword monitor: the query, the schedule, deduplication, alerts and costs. It turns the one-time searches in how to find viral tweets about any topic into a recurring feed.
Which apidojo Actor Should You Use for Monitoring?
Use Twitter Scraper Unlimited for monitoring, not Tweet Scraper V2. Tweet Scraper V2’s rules forbid running the same query repeatedly at short intervals and require at least 50 tweets per query, while Twitter Scraper Unlimited has no minimum and charges per query (Tweet Scraper V2, Twitter Scraper Unlimited).
| Point | Twitter Scraper Unlimited | Tweet Scraper V2 |
|---|---|---|
| Repeated queries | Allowed | Not allowed |
| Minimum per query | None | 50 tweets |
| Price | $0.016 per query (about 40 posts included), then from $0.0004 per item | $0.40 per 1,000 tweets |
| Concurrency | One run at a time | One run at a time |
How Do You Write a Monitoring Query?
Write a monitoring query that catches every way people mention the keyword, removes your own posts and reposts, and covers a window slightly longer than your schedule. The within_time: operator limits results to the last hours (twitter-advanced-search reference).
("acme" OR @acme OR acme.com) -from:acme -filter:retweets within_time:2h
A 2-hour window on an hourly schedule overlaps each run with the last, so no post falls between runs; deduplication removes the repeats. Operators for variants and exclusions are in how to search multiple keywords on X with OR and how to exclude words from Twitter search.
How Do You Build the Monitor in Python?
Run the query, compare post IDs with a stored set, and send only new posts to your alert channel. The fields come from the actor’s output example (Apify).
import json, os, pathlib, requests
from apify_client import ApifyClient
QUERY = '("acme" OR @acme) -from:acme -filter:retweets within_time:2h'
SEEN = pathlib.Path("seen_ids.json")
client = ApifyClient(os.environ["APIFY_TOKEN"])
seen = set(json.loads(SEEN.read_text())) if SEEN.exists() else set()
run = client.actor("apidojo/twitter-scraper-lite").call(run_input={
"searchTerms": [QUERY],
"sort": "Latest",
})
new = [t for t in client.dataset(run.default_dataset_id).iterate_items() if t["id"] not in seen]
for t in new:
requests.post(os.environ["SLACK_WEBHOOK_URL"], json={"text": f"{t['author']['userName']}: {t['text']}\n{t['url']}"})
seen.add(t["id"])
SEEN.write_text(json.dumps(sorted(seen)))
print(len(new), "new posts")
The alert here goes to a Slack incoming webhook; swap in email or any HTTP endpoint. The Python setup is in how to collect tweets with Python.
How Do You Run the Monitor on a Schedule?
Run the script with cron on your own server, or schedule the actor run in Apify and process its dataset afterwards. An hourly cron entry looks like this:
0 * * * * /usr/bin/python3 /opt/monitor/monitor.py
Twitter Scraper Unlimited allows one concurrent run, so keep the interval longer than a run takes (Apify).
What Does Keyword Monitoring Cost?
An hourly monitor costs about $0.38 a day in query fees, or about $11.52 over 30 days, plus $0.0004 for each post beyond the first 40 in a run. A quieter keyword stays inside the included posts; a busy one adds item costs (Apify).
| Schedule | Queries per 30 days | Query fees |
|---|---|---|
| Every 6 hours | 120 | $1.92 |
| Every hour | 720 | $11.52 |
| Every 15 minutes | 2,880 | $46.08 |
Polling the X API’s recent search instead costs $0.005 for every post returned, with a 3 million post reads monthly cap on pay-per-use (X API pricing).
What Can You Build on a Keyword Monitor?
A keyword monitor is the base for 4 common tools. Listed below are the guides for each.
- How to build a Twitter mention monitor for brand and handle mentions.
- How to build a competitor tweet tracker for rival accounts.
- How to collect tweets for sentiment analysis for scoring opinion over time.
- How to build a Twitter dataset for LLM and RAG projects for AI pipelines.
Questions people ask
Can you monitor X in real time?
Scheduled searches give near real-time results at the interval you choose; true streaming requires the X API's paid event delivery.
How do you avoid duplicate alerts?
Store the IDs of posts already sent and skip them, as in the script above.
Can you monitor several keywords?
Yes, list several queries in searchTerms; batches of up to 5 queries get the lowest per-item price.
Where do you start?
At the apidojo Twitter Scraper.