Skip to content
cheapxapi

Get all tweets from one account.

Page through the account’s timeline, keep each post once by ID, then search from: the account for anything older than the timeline reached. Write the result to CSV.

On @cursor_ai that took 32 requests ($0.0192) and returned 599 posts, back to 22 January 2024. The official X API’s timeline stops at the 3,200 most recent posts and charges $0.005 for each.

One page of a timeline.

Get user’s latest tweets takes a screen name and returns about 20 posts, newest first, with likes, views and the author on each. Pass next_cursor back as cursor for the next page, until has_next_page is false.

Replies are left out unless you add includeReplies=true. Each request costs $0.0006. If you store numeric IDs, the timeline by user ID does the same job.

Request

curl "https://api.cheapxapi.com/twitter/user/last_tweets?userName=cursor_ai&includeReplies=true" \
  -H "x-api-key: $CHEAPXAPI_KEY"

Response, captured from the live API

{
  "status": "success",
  "code": 0,
  "msg": "success",
  "data": {
    "tweets": [
      {
        "type": "tweet",
        "id": "2123198359309853169",
        "url": "https://x.com/cursor_ai/status/2123198359309853169",
        "text": "Learn more: https://t.co/dRzBckVZgU",
        "isReply": true,
        "inReplyToId": "2123198346802450926",
        "inReplyToUsername": "cursor_ai",
        "createdAt": "Wed Nov 18 23:35:10 +0000 2026"
      },
      {
        "type": "tweet",
        "id": "2123198346802450926",
        "url": "https://x.com/cursor_ai/status/2123198346802450926",
        "text": "Gemini 4 Neon is now available in Cursor!\n\nAt its default effort, it sets a new cost-performance frontier on CursorBench 4.1, scoring 63.7%, up from 57.3% for Gemini 4 Hydrogen.\n\nPriced at $3/M input and $15/M output tokens. https://t.co/7DRI2Rxl8o",
        "retweetCount": 189,
        "replyCount": 248,
        "likeCount": 3158,
        "quoteCount": 125,
        "viewCount": 254851,
        "bookmarkCount": 308,
        "createdAt": "Wed Nov 18 23:35:07 +0000 2026",
        "lang": "en",
        "isReply": false,
        "isQuote": false,
        "author": {
          "userName": "cursor_ai",
          "name": "Cursor",
          "id": "1695890961094909952",
          "followers": 503271
        }
      }
    ]
  },
  "has_next_page": true,
  "next_cursor": "TWFSB2113661518780998003"
}

The first two of 20 items, trimmed to the main fields. The first is the account’s reply under its own post: inReplyToId points at the second.

Two things a plain loop gets wrong.

Pages can repeat.

Paging @cursor_ai with replies on, page 4 came back as a copy of page 1 and page 6 as a copy of page 2. A loop that appends every page writes those posts twice. Keep posts in a map keyed by id, and stop after a few pages that add nothing new, so a loop cannot keep billing you for copies.

The timeline can stop early.

In one run the timeline step stopped after 500 posts; in the next it returned 597. So after the timeline, search from:cursor_ai until: the day after the oldest post you have, and keep paging. That added 99 posts to the first run and none to the second. Search filters are explained in the search API guide and searching by date.

The export script.

Set USER, run it, and you get cursor_ai_tweets.csv: one row per post with its date, kind, likes, reposts, replies, quotes, views, URL and text, newest first. We ran both versions on @cursor_ai, whose profile shows 607 posts:

Two live runs of the export script on @cursor_ai
RunTimelineSearchPostsRequests
Python5009959932 ($0.0192)
Node.js597059735 ($0.021)

Both reached 22 January 2024. The Python CSV held 331 replies, 228 posts, 29 retweets, 11 quotes. Set REPLIES = False for the account’s own posts only.

Python needs pip install requests. Save the Node.js version as export_tweets.mjs; it needs Node 18 or later. Both read your key from CHEAPXAPI_KEY and pause half a second between requests, inside the free plan’s 2 a second. MAX_PAGES caps the bill.

import csv, datetime, os, time, requests

BASE = "https://api.cheapxapi.com/twitter"
HEADERS = {"x-api-key": os.environ["CHEAPXAPI_KEY"]}
USER = "cursor_ai"   # screen name without the @
REPLIES = True       # False: the account's own posts, retweets and quotes only
MAX_PAGES = 300      # hard stop on billed requests (about 20 posts each)
pages = 0

def fetch(path, params):
    """One page. A 429 is not billed: wait and ask again."""
    global pages
    while True:
        res = requests.get(f"{BASE}/{path}", headers=HEADERS, params=params, timeout=75)
        if res.status_code != 429:
            break
        time.sleep(int(res.headers.get("retry-after", "1")))
    res.raise_for_status()
    pages += 1
    return res.json()

def walk(path, params, list_of, posts):
    """Follow next_cursor; stop at the end, at MAX_PAGES, or after 3 pages with nothing new."""
    cursor, stale = None, 0
    while pages < MAX_PAGES and stale < 3:
        page = fetch(path, {**params, **({"cursor": cursor} if cursor else {})})
        new = [p for p in list_of(page) if p["id"] not in posts]
        posts.update((p["id"], p) for p in new)
        stale = 0 if new else stale + 1
        if not page.get("has_next_page") or not page.get("next_cursor"):
            break
        cursor = page["next_cursor"]
        time.sleep(0.5)

def when(post):
    return datetime.datetime.strptime(post["createdAt"], "%a %b %d %H:%M:%S %z %Y")

posts = {}  # id -> post; pages can repeat, so every post is kept once
# 1. The account's timeline, newest first.
walk("user/last_tweets", {"userName": USER, "includeReplies": str(REPLIES).lower()},
     lambda page: page["data"]["tweets"], posts)
timeline = len(posts)
# 2. Search for anything older than the oldest post the timeline returned.
oldest = min(when(p) for p in posts.values())
query = f"from:{USER} until:{(oldest + datetime.timedelta(days=1)):%Y-%m-%d}"
if not REPLIES:
    query += " -filter:replies"
walk("tweet/advanced_search", {"query": query, "queryType": "Latest"},
     lambda page: page["tweets"], posts)

def kind(post):
    if post.get("retweeted_tweet"):
        return "retweet"
    if post["isReply"]:
        return "reply"
    return "quote" if post["isQuote"] else "post"

rows = sorted(posts.values(), key=when, reverse=True)
with open(f"{USER}_tweets.csv", "w", newline="", encoding="utf-8") as f:
    out = csv.writer(f)
    out.writerow(["id", "created_at", "kind", "likes", "retweets", "replies", "quotes", "views", "url", "text"])
    for p in rows:
        out.writerow([p["id"], when(p).isoformat(), kind(p), p["likeCount"], p["retweetCount"],
                      p["replyCount"], p["quoteCount"], p["viewCount"], p["url"], " ".join(p["text"].split())])
print(f"{len(rows)} posts ({timeline} from the timeline, {len(rows) - timeline} more from search) "
      f"in {pages} requests, oldest {when(rows[-1]):%Y-%m-%d}")

What an export costs.

cheapxapi bills each request, and a request returns about 20 posts. X bills each post it returns, $0.005 apiece, and counts a post once a day if you ask for it again. The 599 posts above cost $0.0192 with us and would be $3.00 on X.

X’s user timeline returns up to 100 posts a request but only the 3,200 most recent (800 without replies). Past that you need its full-archive search, at the same price per post. Reading your own account with your own developer app is $0.001 a post.

List price of exporting an account’s posts, by number of posts
Posts1,0003,20020,000
cheapxapi$0.03$0.096$0.60
Official X API$5.00$16.00$100.00*

* More than the timeline returns: the posts past 3,200 come from full-archive search.

List price of 100,000 posts at other providers
Other providers100,000 posts
cheapxapi$3.00
twitterapis.com$4.00
GetXAPI$5.00
SocialData$20.00
Sorsa$199 monthly plan$2.00
Apify Tweet Scraper V2$40.00

List prices. X’s figures are from its developer documentation and pricing page; the other providers’ are from their own pricing pages, with sources in our comparison. cheapxapi assumes full pages of 20 at $0.0006 a request; real pages run a little under, as the runs above show. See pricing.

Get your API key

Questions.

How do I get all tweets from a user with an API?

Page through the account's timeline with GET /twitter/user/last_tweets, passing next_cursor back each time, and keep every post by ID because a page can repeat. Then search from:username with until: set to the oldest date you got, to pick up anything the timeline did not return. The scripts on this page do both and write a CSV.

Is there a limit on how many tweets the official X API returns for a user?

Yes. X's documentation says the user posts timeline (GET /2/users/:id/tweets) returns up to the 3,200 most recent posts, or 800 when you exclude replies. Asking past that returns a successful response with no data. Older posts need full-archive search.

How much does it cost to download all of an account's tweets?

On cheapxapi, about $0.0006 for every 20 posts. Our run on @cursor_ai returned 599 posts in 32 requests: $0.0192. The official X API charges $0.005 a post, $3.00 for the same 599, or $0.001 a post when you read your own account with your own developer app.

Can I include replies and retweets?

Retweets and quotes come back by default. Replies come back with includeReplies=true. The CSV marks each row as post, reply, retweet or quote, so you can filter afterwards.

Why did I get fewer posts than the profile says?

The profile count is X's own counter, and an export rarely matches it exactly. @cursor_ai's profile said 607; our two runs got 599 and 597, and both reached the oldest post search returned for the account. If you get far fewer, check that the search step ran and that MAX_PAGES did not stop it.