X's API searches posts, but recent search looks back only 7 days, and full-archive search is a separate endpoint with its own access rules. ToolzerHub searches back to 2014 for 5 credits a call, about 18 posts a call. One query stops after roughly 900 to 2,100 posts, so you slice long jobs into date windows.
What X's two search endpoints cover
X's Search Posts docs list two endpoints. Recent search is open to all developers; full-archive search is for pay-per-use and Enterprise customers. Dates go in start_time and end_time parameters, not as query operators, and retweets no longer come back in keyword search.
| Recent search | Full-archive search | |
|---|---|---|
| Path | /2/tweets/search/recent |
/2/tweets/search/all |
| Reach | last 7 days | back to March 2006 |
| Posts per request | 100 max | 500 max |
| Rate limit, per app | 450 / 15 min | 1/sec, 300 / 15 min |
X's pricing page lists posts at $0.005 per resource and has no search row, so each post a search returns counts as a post read. 1,000 matching posts cost $5.00 on X: 10 requests at 100 on recent search, or 2 at 500 on full-archive. X's API is the better pick for bigger pages, counts, streaming, anything that writes, and enterprise contracts. For the rest of X's prices, see is the Twitter API free.
Search posts with ToolzerHub
We make ToolzerHub. Our X API has GET /v1/x/search, which takes query, sort (latest or top) and cursor and costs 5 credits a call. Dates go inside the query, as in from:NASA since:2020-01-01 until:2020-02-01, and you need no X developer account.
Queries with from:, to:, lang:, has:images, min_likes: and a #hashtag each returned a full page of 20 matching posts.
How deep one query goes
A query ends when has_more turns false, and where it ends varies. Account queries ended at 1,060 posts (NASA) and 2,042 (SpaceX), and a top-sorted keyword at 906. A busy keyword like artemis was still going at 1,609 posts spanning three days.
| Query | Sort | Unique posts | Oldest post | Ended |
|---|---|---|---|---|
from:NASA |
latest | 1,060 | 2025-09-10 | yes, 54 calls |
sourdough |
top | 906 | 2014-06-11 | yes, 58 calls |
sourdough |
latest | 2,025 | 2026-09-20 | yes, 114 calls |
from:SpaceX |
latest | 2,042 | 2023-11-11 | yes, 111 calls |
artemis |
latest | 1,609 | 2026-10-14 | no, stopped at 100 calls |
sort=top reaches older posts, back to 2014, but fewer.
Reach further back with date windows
Date windows get past the stop. Unsliced, from:NASA ended at 2025-09-10, yet month windows returned NASA posts for January to March 2020: 272, 248 and 240, or 760 in all. until: includes its end day, so windows do not overlap.
A script that pages date windows to a CSV
The script appends since: and until: to your query, pages each window to its end or a page cap, and writes one row per post id. It leaves the author out, so put from: in the query for one account.
import argparse
import csv
import os
import sys
import time
from datetime import date, timedelta
import requests
BASE = "https://api.toolzerhub.com/v1/x/search"
HEADERS = {"x-api-key": os.environ.get("TOOLZERHUB_API_KEY", "")}
FIELDS = ["id", "created_at", "url", "likes", "reposts", "replies", "quotes", "views", "lang", "text"]
calls = 0
BAD = object() # a 400: skip this window
GAVE_UP = object() # a 5xx or a 429/503 that kept coming back: skip this window
def cell(value):
# Spreadsheets run text that starts with = + - or @ as a formula; an apostrophe keeps it text.
if isinstance(value, str) and value[:1] in ("=", "+", "-", "@", "\t", "\r"):
return "'" + value
return value
def get(params, tries=5):
# 429 and 503 are retried; the wait comes from the error body or the Retry-After header.
global calls
for attempt in range(tries):
r = requests.get(BASE, headers=HEADERS, params=params, timeout=90)
calls += 1
if r.status_code == 200:
return r.json().get("data") or {}
if r.status_code == 400:
print("bad request:", r.json()["error"]["message"].splitlines()[0])
return BAD
if r.status_code in (401, 402, 403):
sys.exit(f"HTTP {r.status_code}: check the API key and your credit balance")
if r.status_code not in (429, 503):
return GAVE_UP if r.status_code >= 500 else r.raise_for_status()
if attempt == tries - 1:
return GAVE_UP
try:
wait = r.json()["error"]["details"]["retryAfter"]
except (ValueError, KeyError, TypeError):
wait = None
try:
wait = int(wait or r.headers.get("Retry-After") or 5 * (attempt + 1))
except ValueError:
wait = 5 * (attempt + 1)
time.sleep(min(wait, 60))
return GAVE_UP
def windows(since, until, size):
# Inclusive day ranges. until: in a query includes the whole end day, so windows do not overlap.
if size == "none" or not since:
return [(since, until)]
start, end, out = date.fromisoformat(since), date.fromisoformat(until or str(date.today())), []
while start <= end:
if size == "day":
stop = start
elif size == "week":
stop = start + timedelta(days=6)
else:
nxt = (start.replace(day=1) + timedelta(days=32)).replace(day=1)
stop = nxt - timedelta(days=1)
stop = min(stop, end)
out.append((str(start), str(stop)))
start = stop + timedelta(days=1)
return out
def run(query, since, until, size, pages, sort, out):
seen, written = set(), 0
with open(out, "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=FIELDS)
writer.writeheader()
for lo, hi in windows(since, until, size):
q = f"({query})" + (f" since:{lo}" if lo else "") + (f" until:{hi}" if hi else "")
params, n, page, how = {"query": q, "sort": sort}, 0, 0, "ended"
while True:
if page == pages:
how = "stopped at the page cap"
break
data = get(params)
if data is BAD:
how = "skipped (bad request)"
break
if data is GAVE_UP:
how = "gave up (server errors or rate limit)"
break
page += 1
for p in data.get("posts") or []:
if p["id"] in seen: # one row per post id
continue
seen.add(p["id"])
n += 1
writer.writerow({
"id": p["id"], "created_at": p["created_at"], "url": p["url"],
"likes": p["like_count"], "reposts": p["repost_count"],
"replies": p["reply_count"], "quotes": p["quote_count"],
"views": p["view_count"], "lang": p["lang"],
"text": cell((p["text"] or "").replace("\n", " ")),
})
f.flush()
if not data.get("posts") or not data.get("has_more") or not data.get("cursor"):
break
params["cursor"] = data["cursor"]
time.sleep(0.2)
written += n
print(f"{lo or 'any'}..{hi or 'now'}: {n} new posts, {page} pages, {how}")
print(f"wrote {written} posts to {out} in {calls} calls")
def main():
ap = argparse.ArgumentParser(description="Search X posts through ToolzerHub and write a CSV.")
ap.add_argument("query", help='for example "from:NASA" or "artemis lang:en"')
ap.add_argument("--since", help="first day, YYYY-MM-DD")
ap.add_argument("--until", help="last day, YYYY-MM-DD (default: today when slicing)")
ap.add_argument("--window", choices=["none", "day", "week", "month"], default="none",
help="slice since..until into windows; each window pages to its own end")
ap.add_argument("--pages", type=int, default=60, help="page cap per window (default 60)")
ap.add_argument("--sort", choices=["latest", "top"], default="latest")
ap.add_argument("--out", default="x_search.csv")
a = ap.parse_args()
if not HEADERS["x-api-key"]:
sys.exit("set TOOLZERHUB_API_KEY first")
if a.window != "none" and not a.since:
sys.exit("--window needs --since")
run(a.query, a.since, a.until, a.window, a.pages, a.sort, a.out)
if __name__ == "__main__":
main()
export TOOLZERHUB_API_KEY=your_key
python x_search.py "from:NASA" --since 2020-01-01 --until 2020-03-31 --window month --out nasa_2020.csv
2020-01-01..2020-01-31: 272 new posts, 15 pages, ended
2020-02-01..2020-02-29: 248 new posts, 14 pages, ended
2020-03-01..2020-03-31: 240 new posts, 13 pages, ended
wrote 760 posts to nasa_2020.csv in 42 calls
The run took 65 seconds and gave 760 unique post ids. The views column is 0 on posts from 2020.
What 1,000 matching posts cost
A call returns 14.6 to 18.1 posts, so 1,000 matching posts take 56 to 69 calls at 5 credits, or 280 to 345 credits.
| Job | X, per post read | ToolzerHub |
|---|---|---|
| 1,000 matching posts | $5.00 | 280 to 345 credits |
| The 760-post run above | $3.80 | 210 credits |
You get 100 free credits a month; $19 buys 10,000 credits that never expire, and plans for higher volume cover more posts. Set your key and run the script on your first query.
For another list that a single X call cannot cover, see the Twitter API followers list. To find what to search for, the Twitter trends API guide pulls trending topics by place, each with a ready search query.
We are not affiliated with X Corp.