Trending topics on X, by location.
Call GET /twitter/trends with a WOEID: 1 for worldwide, 23424977 for the United States. You get the ranked list X shows for that place, each trend with a search query ready to use, for $0.0006 a request.
Lists refresh every 5 minutes. X’s own trends endpoint costs $0.010 a request, returns up to 50 trends and can add a post count to each.
One request per place.
Get trends takes a woeid and returns 30 trends by default, in rank order. Each has a name, a rank and a target.query you can pass straight to search.
metadata.woeid names the place the list belongs to, and refresh_interval_millis says how long the list stays current. Each request costs $0.0006, whatever the count.
Request
curl "https://api.cheapxapi.com/twitter/trends?woeid=23424977" \
-H "x-api-key: $CHEAPXAPI_KEY"Response, captured from the live API
{
"status": "success",
"msg": "success",
"trends": [
{
"trend": {
"name": "#WWERaw",
"target": {
"query": "#WWERaw"
},
"rank": 1
}
},
{
"trend": {
"name": "Haloti Ngata",
"target": {
"query": "\"Haloti Ngata\""
},
"rank": 2
}
},
{
"trend": {
"name": "South Sudan",
"target": {
"query": "\"South Sudan\""
},
"rank": 3
}
}
],
"metadata": {
"refresh_interval_millis": 300000,
"woeid": {
"name": "United States",
"id": 23424977
},
"context_mode": "full"
}
}The first three of 30 trends. metadata also carries a timestamp in milliseconds, left out here.
WOEIDs that work.
A WOEID is a numeric place ID. Trends exist for the whole world, for countries and for some cities. We called the API with every ID in this table, and each came back with its own ID and this name in metadata.woeid.
| Place | Type | WOEID |
|---|---|---|
| Worldwide | Worldwide | 1 |
| United States | Country | 23424977 |
| United Kingdom | Country | 23424975 |
| India | Country | 23424848 |
| Japan | Country | 23424856 |
| Brazil | Country | 23424768 |
| Indonesia | Country | 23424846 |
| Germany | Country | 23424829 |
| Canada | Country | 23424775 |
| Mexico | Country | 23424900 |
| Australia | Country | 23424748 |
| Nigeria | Country | 23424908 |
| New York | City | 2459115 |
| Los Angeles | City | 2442047 |
| London | City | 44418 |
| Tokyo | City | 1118370 |
| Mumbai | City | 2295411 |
What we found calling it.
A wrong WOEID still answers.
woeid=999999999 returned success and 30 trends, with no metadata.woeid. A typo gives you a list for no place in particular. Check that metadata.woeid.id is the ID you sent; the scripts below stop if it is not.
You may get a different count.
Without it you get 30. Asking for 100 returned 91, and asking for fewer than 10 still returned 10. With the default, Nigeria returned 28 and Tokyo 29, so read the length of the array rather than trusting count.
Every 5 minutes is enough.
refresh_interval_millis was 300000 in every response. Polling faster pays again for a list that has not been refreshed. To see how a topic moves, store each snapshot with its time and rank.
Record trends to CSV.
List your WOEIDs and run it. Each round appends one row per trend to trends.csv: the time, the place, the rank, the trend and its search query. Set SNAPSHOTS = 0 and it keeps going, one round every 5 minutes, until you stop it.
We ran both versions once as shown: 90 trends from 3 locations in 3 requests ($0.0018).
To read the posts behind a trend, pass its search_query to advanced search. Phrases already carry their quotes: "South Sudan" returned 19 posts in one request. Filters and paging are in the search API guide.
Python needs pip install requests. Save the Node.js version as trends.mjs; it needs Node 18 or later. Both read your key from CHEAPXAPI_KEY and pause half a second between locations, inside the free plan’s 2 a second.
import csv, datetime, os, time, requests
URL = "https://api.cheapxapi.com/twitter/trends"
HEADERS = {"x-api-key": os.environ["CHEAPXAPI_KEY"]}
WOEIDS = [1, 23424977, 23424975] # Worldwide, United States, United Kingdom
COUNT = 30 # trends per location
SNAPSHOTS = 1 # how many rounds to take; 0 keeps going until you stop it
FILE = "trends.csv"
def trends(woeid):
"""One location's list. A 429 is not billed: wait and ask again."""
while True:
res = requests.get(URL, headers=HEADERS, params={"woeid": woeid, "count": COUNT}, timeout=75)
if res.status_code != 429:
break
time.sleep(int(res.headers.get("retry-after", "1")))
res.raise_for_status()
body = res.json()
if body.get("status") != "success":
raise RuntimeError(body.get("msg"))
meta = body.get("metadata", {})
place = meta.get("woeid")
# An unknown WOEID still returns a list, just without metadata.woeid: refuse it.
if not place or place.get("id") != woeid:
raise ValueError(f"{woeid} is not a trends location")
return place["name"], body["trends"], meta.get("refresh_interval_millis", 300_000) / 1000
taken = 0
while True:
now = datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds")
rows, wait = [], 300
for woeid in WOEIDS:
name, items, wait = trends(woeid)
for item in items:
t = item["trend"]
rows.append([now, woeid, name, t["rank"], t["name"], t["target"]["query"]])
time.sleep(0.5)
first = not os.path.exists(FILE)
with open(FILE, "a", newline="", encoding="utf-8") as f:
out = csv.writer(f)
if first:
out.writerow(["snapshot_utc", "woeid", "location", "rank", "trend", "search_query"])
out.writerows(rows)
taken += 1
print(f"{now}: {len(rows)} trends from {len(WOEIDS)} locations")
if SNAPSHOTS and taken >= SNAPSHOTS:
break
time.sleep(wait) # trends refresh about every 5 minutes; asking sooner returns the same listWhat tracking costs.
Trends are billed per request everywhere, so the bill is places × checks. One place every 5 minutes for 30 days is 8,640 requests; the table also prices 10 and 30 places checked every 15 minutes.
X’s endpoint returns 20 trends by default and up to 50, and adds a post count to each when you ask for trend.fields=tweet_count. It takes an app bearer token from a developer account with prepaid credits. Personalized trends, the list a signed-in user sees, need that user’s OAuth sign-in.
| 30 days of | 1 place, 5 min8,640 requests | 10 places, 15 min28,800 requests | 30 places, 15 min86,400 requests |
|---|---|---|---|
| cheapxapi | $5.18 | $17.28 | $51.84 |
| Official X API | $86.40 | $288.00 | $864.00 |
| twitterapis.com | $6.91 | $23.04 | $69.12 |
| GetXAPI | $8.64 | $28.80 | $86.40 |
List prices per request: cheapxapi $0.0006, X $0.010 (its pricing page), the others from their own pricing and API pages. Sorsa sells plans rather than single requests and counts a trends call as one request from the plan (Pro: $199 a month for 100,000 requests). SocialData lists no trends endpoint. Other jobs are compared in our comparison; see pricing.
Get your API keyQuestions.
Is there a Twitter (X) trends API?
Yes. X's own API has GET /2/trends/by/woeid/:id, which takes an app bearer token, returns up to 50 trends and costs $0.010 a request, and personalized trends for a signed-in user. On cheapxapi, GET /twitter/trends?woeid=1 returns the worldwide list for $0.0006 a request with one API key.
What WOEID do I use for worldwide or the United States?
1 is worldwide and 23424977 is the United States. The table on this page lists 10 more countries and 5 cities, each checked against the live API.
How often do X trends update?
Every response we got said refresh_interval_millis: 300000, so the API treats a list as current for 5 minutes. Asking more often costs a request and gets you a list that has not been refreshed.
Does the trends API return tweet volume?
Not on cheapxapi: each trend has a name, a rank and a search query. X's own endpoint returns a post count when you ask for trend.fields=tweet_count. To size a trend yourself, search its query and count the posts.
How do I get the tweets behind a trend?
Pass the trend's target.query to advanced search. The query already has quotes around phrases, so it works as it is: "South Sudan" returned 19 posts in one request.