How to Get Historical Tweets With an API

To get historical tweets with an API, use the X API's full-archive search endpoint, which reaches back to March 2006 at $0.005 per post, or a scraper API such as apidojo's Tweet Scraper V2, which searches the same history at $0.40 per 1,000 tweets.

Cover card reading 'How to Get Historical Tweets With an API'

To get historical tweets with an API, use the X API’s full-archive search endpoint, which reaches back to March 2006 at $0.005 per post, or a scraper API such as apidojo’s Tweet Scraper V2, which searches the same history at $0.40 per 1,000 tweets. The X API’s recent search endpoint covers only the last 7 days, so it can’t return historical posts.

This guide compares the ways to collect historical tweets, shows the code for each, and explains how to size a job before you pay for it. The overview of both X search endpoints is in the Twitter search API guide.

What Are the Ways to Get Historical Tweets With an API?

There are 3 ways to get historical tweets programmatically: X’s full-archive search, X’s owned-read endpoints for your own account, and a scraper API. The table compares them.

Method History Cost Best for
X API full-archive search (/2/tweets/search/all) Back to March 2006 $0.005 per post; 3 million post reads per month cap Apps that need X’s official API
X API owned reads (/2/users/{id}/tweets) Your own account’s posts $0.001 per post Your own history and analytics
apidojo Tweet Scraper V2 Same history as X web search, back to 2006 $0.40 per 1,000 tweets Research, datasets, large volumes

X API prices, the monthly cap and owned-read rates are from X’s pricing documentation (X API pricing); archive coverage from X’s search documentation (X API docs).

You get historical tweets with X’s full-archive search by calling GET /2/tweets/search/all with a query and a start_time and end_time window. Without a window the endpoint returns only the last 30 days (X API quickstart). Full-archive search is available on pay-per-use and Enterprise access, returns up to 500 posts per request, and accepts queries of up to 1,024 characters (X API docs).

import os, requests

url = "https://api.x.com/2/tweets/search/all"
headers = {"Authorization": f"Bearer {os.environ['BEARER_TOKEN']}"}
params = {
    "query": "from:NASA pluto -is:retweet",
    "start_time": "2015-07-01T00:00:00Z",
    "end_time": "2015-08-01T00:00:00Z",
    "max_results": 500,
    "tweet.fields": "created_at,public_metrics",
}

posts = []
while True:
    data = requests.get(url, headers=headers, params=params).json()
    posts.extend(data.get("data", []))
    token = data.get("meta", {}).get("next_token")
    if not token:
        break
    params["next_token"] = token

print(len(posts), "posts")

Each post returned is billed at $0.005, and the same post requested again within one 24-hour UTC window is charged once (X API pricing).

How Do You Size a Historical Job Before Paying?

Size a historical job with X’s counts endpoint first, because a count request is billed per request rather than per post. Counts: All costs $0.010 per request, while reading the posts costs $0.005 each (X API pricing). A query that matches 400,000 posts would cost $2,000 to read through the X API, so the count tells you which route to take.

How Do You Get Historical Tweets With apidojo’s Tweet Scraper V2?

You get historical tweets with Tweet Scraper V2 by writing X web search queries with since: and until:, one per period, and running them through the Apify API. Splitting long periods into windows is the approach the actor’s documentation shows (Apify).

from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("apidojo/tweet-scraper").call(run_input={
    "searchTerms": [
        "from:NASA pluto since:2015-01-01 until:2015-07-01",
        "from:NASA pluto since:2015-07-01 until:2016-01-01",
    ],
    "sort": "Latest",
})

posts = {i["id"]: i for i in client.dataset(run.default_dataset_id).iterate_items()}
print(len(posts), "posts")

Each query must return at least 50 tweets, and one run batches up to 5 queries. Generating windows for a whole year is shown in how to scrape tweets by date range.

What Does Historical Tweet Data Cost?

Historical tweet data costs $5 per 1,000 posts through X’s full-archive search and $0.40 per 1,000 through Tweet Scraper V2. The table shows the difference at common volumes.

Posts X API full-archive Tweet Scraper V2
10,000 $50 $4
100,000 $500 $40
1,000,000 $5,000 $400
3,000,000 $15,000 (the monthly cap) $1,200

Above 3 million post reads per month, the X API requires an Enterprise plan (X API pricing). The full decision guide is X API vs Twitter scraper API.

Which Historical Tweets Can’t Any API Return?

No API returns deleted posts, and search-based methods don’t return posts from protected accounts. Private and suspended accounts are not in X’s search index (twitter-advanced-search reference). For your own deleted posts, only an X archive you downloaded before deleting them still holds them; see how to find deleted tweets.

Questions people ask

Is there a free API for historical tweets?

No, new X developers pay per use from prepaid credits; full-archive search is on pay-per-use and Enterprise access (X API docs).

How far back does the X API go?

Full-archive search reaches back to March 2006; recent search covers the last 7 days.

Can you get your own old tweets more cheaply?

Yes, X bills reads of your own posts at $0.001 each as owned reads, and your X archive download is free; see how to find old tweets on X.

Where do you start?

Start at how to scrape Twitter data in 2026 or the apidojo Twitter Scraper.