Jan 1 → Dec 31 · 12 windows
Build an X Wrapped for 2026: pull a full year of posts with an API
A Wrapped card needs every post an account made this year. The reliable way to get them is a search for from:handle in twelve monthly date windows, run a few at a time, with results deduplicated by tweet ID and each window stopped on an empty page. The code below does exactly that in about 60 lines of Python or TypeScript. On TwitterAPI.io it costs $0.15 per 1,000 posts: our test account's 373 posts for the year cost about $0.058.
Why the user timeline is the wrong tool
The obvious endpoint is the user timeline (/twitter/user/last_tweets). It returns the account's recent profile timeline, newest first, and it has two limits for a year-in-review. It follows X's own depth limit, which ends at a different point for every account. And it mostly leaves out replies: in a test on one large account, a month with 37 posts on the timeline had 71 in a from: search, and every one of the extra 34 was a reply. For many accounts, replies are the bulk of what they posted this year.
Advanced search avoids both limits. It takes a date range, so you can slice the year into windows, and it returns replies too.
The method: 12 windows, three stop rules
- One query per month.
from:naval since:2026-03-01_00:00:00_UTC until:2026-04-01_00:00:00_UTCwithqueryType=Latest.untilis exclusive, so consecutive windows neither overlap nor leave a gap. - Page with the cursor until a stop rule fires: the page is empty,
has_next_pageis false, or the API hands back a cursor you already used. In our runs every window ended with one empty page, billed at the $0.00015 minimum. - Deduplicate by tweet ID within a window and again when you merge the twelve, then sort by ID (IDs increase with time).
- Run a few windows at once. Four in parallel finished our test account's year in 21 to 32 seconds. Paid accounts get 20 requests a second; before the first payment the limit is one request every 5 seconds, so the scripts back off on 429 and retry.
- Split busy months into weeks. If one window keeps paginating for many pages (roughly 1,000 or more posts a month), use weekly windows: shorter cursor chains are faster and less likely to be cut short. On our test account weekly windows took 103 calls against 37 for monthly ones and found the same posts, so stay monthly unless an account needs it.
Copy-paste code: Python and TypeScript
Both scripts take a handle, pull the year in monthly windows four at a time, retry on 429, 5xx and dropped connections, and write handle-2026.json. Set TWITTERAPI_IO_KEY to your key from the dashboard first.
# Pull one account's 2026 tweets in 12 monthly search windows, in parallel.
# pip install requests · export TWITTERAPI_IO_KEY=...
import os, sys, json, time
from concurrent.futures import ThreadPoolExecutor
import requests
KEY = os.environ["TWITTERAPI_IO_KEY"]
URL = "https://api.twitterapi.io/twitter/tweet/advanced_search"
YEAR = 2026
def windows(year):
for m in range(1, 13):
y2, m2 = (year + 1, 1) if m == 12 else (year, m + 1)
yield f"{year}-{m:02d}-01_00:00:00_UTC", f"{y2}-{m2:02d}-01_00:00:00_UTC"
def get(params, tries=5):
for i in range(tries):
try:
r = requests.get(URL, params=params, headers={"X-API-Key": KEY}, timeout=60)
except requests.RequestException: # dropped connection: retry
time.sleep(2 ** i)
continue
if r.status_code == 429 or r.status_code >= 500:
time.sleep(2 ** i) # back off and retry
continue
r.raise_for_status()
return r.json()
raise RuntimeError(f"gave up after {tries} tries")
def pull_month(handle, since, until):
query = f"from:{handle} since:{since} until:{until}"
tweets, cursor, seen_cursors = {}, "", set()
while True:
page = get({"query": query, "queryType": "Latest", "cursor": cursor})
batch = page.get("tweets") or []
for t in batch:
tweets[t["id"]] = t # dedupe by tweet ID
cursor = page.get("next_cursor") or ""
# stop on an empty page, no next page, or a cursor we have already used
if not batch or not page.get("has_next_page") or not cursor or cursor in seen_cursors:
return tweets
seen_cursors.add(cursor)
def pull_year(handle, year=YEAR):
with ThreadPoolExecutor(max_workers=4) as pool: # 4 months at a time
parts = pool.map(lambda w: pull_month(handle, *w), windows(year))
merged = {}
for part in parts:
merged.update(part)
return sorted(merged.values(), key=lambda t: t["id"])
if __name__ == "__main__":
handle = sys.argv[1]
tweets = pull_year(handle)
with open(f"{handle}-{YEAR}.json", "w") as f:
json.dump(tweets, f)
top = max(tweets, key=lambda t: t.get("likeCount", 0), default=None)
print(f"{len(tweets)} tweets in {YEAR}")
if top:
print("top tweet by likes:", top["likeCount"], top["url"])
Run: python wrapped.py naval or npx tsx wrapped.ts naval. Both printed the same account's year and the same top post in our runs.
What a real run returned
| Run on one account, 2026 to date | Posts | Calls |
|---|---|---|
| 12 monthly windows, four runs | 331, 372, 373 and 376 | 37 |
| 53 weekly windows | 373 | 103 |
| A very active account, one day | 60 | 4 |
The runs did not return the identical set: three agreed within 4 posts and one came back about 12% short. Every post a run missed still existed when we looked it up by ID. So run the pull twice and merge by ID when the count matters, and show totals on the card as approximate.
Cost calculator
Each account costs $0.00015 per post, one $0.00015 empty page per window and $0.00018 for the profile. The comparison uses the official X API's pay-per-use price of $0.005 per post read and $0.010 per user read. The post counts per preset are assumptions; use your own account mix.
1 to 100,000
Repeat views and accounts someone already generated
Per account, TwitterAPI.io
$0.2270
1,500 posts, about 88 calls
All 500 pulls
$113.49
Turning the JSON into a Wrapped
Everything a Wrapped card shows comes from fields already in each post, so you compute it locally with no extra calls:
- Top posts: sort by
likeCount,retweetCountorviewCount. - Posts per month and busiest day: group
createdAtby month, weekday and hour. - Inner circle: count the @-mentions in the text, especially at the start of replies.
- Originals vs replies:
isReplyon each post. - Totals: sum views and likes across the year.
If you launch it as a public app
Wrapped apps spread through the cards people share, and every share sends new people to generate their own. Plan for a spike before it happens:
- Require sign-in and generate cards only for the signed-in person's own account, or accounts that asked for one.
- Set hard daily caps per user and per IP, and a global daily spend cap that pauses generation rather than draining your balance.
- Cap posts per account. Stop after a set number of pages, so one very active account costs a known maximum.
- Cache by handle and month. Past months rarely change, so a second request for the same person, or a refresh in December, only needs the current month.
- Queue the pulls and show progress, instead of holding one HTTP request open for half a minute.
For accounts you track all year rather than once, Twitter Stream pushes each new post as it happens, so December needs no backfill at all.
Questions
- Why not just page through the user's timeline?
- The user timeline endpoint returns the account's recent profile timeline. It follows X's own depth limit, which differs from account to account, and it mostly leaves out replies: in our test on a large account, one month had 37 posts on the timeline and 71 in a from: search, and the extra 34 were replies. For a full year, search with from: and date windows.
- How much does one Wrapped cost?
- About $0.15 per 1,000 posts, plus $0.00015 for the empty last page of each window and $0.00018 for the profile. Our test account, 373 posts in the year, cost about $0.058. Very active accounts cost more, which is why a public app should cap and cache.
- Are replies and retweets included?
- A from: search includes the account's replies; add -filter:replies to the query for original posts only. Our test results also contained some retweets, so check each post's fields before you count them as the account's own writing.
- Will I get every single post?
- Search returns the account's posts in each window, but treat totals as close, not exact: four monthly runs on our test account returned 331, 372, 373 and 376 posts. Deduplicate by ID, merge reruns if you need a tighter count, and split busy months into weeks.
- Do I need an X developer account?
- No. You need a TwitterAPI.io API key, sent in the X-API-Key header. The official X API is the alternative, at $0.005 per post read on its pay-per-use plan.
Get a key and run it
Sign up, copy your API key and run either script on your own handle.