Tutorial · curl, Node.js, Python
How to scrape X (Twitter) search results with Python, Node.js or curl (2026)
Can rettiwt-api search X for free with no API key? Not for search. rettiwt-api (v7.2.0 on npm) needs Node 22 or 24, and its guest mode covers tweet details, user details and timelines. Search needs "user" authentication built from your own X account's login cookies. This tutorial calls GET /v1/twitter/search with fetch instead: no X account or cookies, and a Social Fetch key with 100 free credits.
A walkthrough for GET /v1/twitter/search, with the same request in curl, Node.js and Python. Copy the snippet, run it, then read the JSON.
GET /v1/twitter/search · 1 credit
In this tutorial
You'll search X (Twitter) for a phrase and see the results you get back.
Typical job: watching for mentions. Search your brand name; X search operators such as from:, OR and "quoted phrases" work in the query. Set section=latest for the newest posts, and page through with cursor. Store meta.creditsCharged with each run so your costs add up.
Step 1
Get ready
Create a Social Fetch API key, then get curl, Node.js or Python ready. New accounts include 100 free credits.

API key. Create a Social Fetch account, open API Keys and create a key. New accounts include 100 free credits.
curl. Any shell with curl. Set SOCIALFETCH_API_KEY to your key (export SOCIALFETCH_API_KEY=sfk_…) before you run the sample.
Node.js. Node 18 or later, which has fetch built in. Save the sample as an .mjs file so top-level await works, and set SOCIALFETCH_API_KEY to your key.
Python. Python 3 with requests installed (pip install requests). Set SOCIALFETCH_API_KEY to your key.
When you're done, SOCIALFETCH_API_KEY is set in your shell.
Step 2
Make the request
Pick curl, Node.js or Python, copy the sample and run it. It calls GET /v1/twitter/search with your key in the x-api-key header, using this example: /v1/twitter/search?query=from%3ANASA+artemis.
Each sample prints the JSON response with data and meta. On an error status, the Python sample stops at raise_for_status() and the Node.js sample throws with the error body, because it checks response.ok first. curl prints the error JSON; add --fail-with-body to make it exit non-zero.
Step 3
Read the response
The response is JSON with two parts: data holds the search results and meta holds creditsCharged and requestId. The sample below is a trimmed copy of a real response; the endpoint page lists every field. Credits are charged on completed lookups, not on failed requests.

Check data.lookupStatus first when the response has one. Keep meta.requestId in case a row looks wrong.
Watch out
keep query and section the same while you page with cursor. A page holds at most 20 posts. section=people returns accounts in data.people instead of posts.
Step 4
You finished
The Playground, the docs and your code all call the same endpoint at the same price. Pick a next step below.
FAQ
Common questions
Can rettiwt-api search X for free with no API key?
Not for search. rettiwt-api (v7.2.0 on npm) needs Node 22 or 24, and its guest mode covers tweet details, user details and timelines. Search needs "user" authentication built from your own X account's login cookies. This tutorial calls GET /v1/twitter/search with fetch instead: no X account or cookies, and a Social Fetch key with 100 free credits.
Do I need an official X (Twitter) developer account?
No. Social Fetch authenticates with your Social Fetch API key. You call GET /v1/twitter/search and we handle the lookup. You still need to follow each platform's terms for how you use public data.
What does the X (Twitter) search endpoint return?
JSON with two parts: data holds the search results and meta holds creditsCharged and requestId. The endpoint page and the API docs describe every field.
When should I use section=latest vs section=top on X search?
Use latest when you want the newest posts first, for example a mention watch that runs often. Use top for the most popular posts, for a weekly summary. Other sections are people, photos and videos. Leave section out to get top. Keep it the same while you page.
Can I use X search operators like from: or OR?
Yes. The query accepts X search operators, such as from:NASA, OR, "exact phrases" and filter:nativeretweets (is:retweet isn't supported). The example on this page uses from:NASA artemis.
How much does a successful request cost?
1 credit. Failed requests are free.
Is this okay for production?
Yes. It's the same API the Playground and the docs use: typed errors, a requestId on every response, and credits charged only on completed lookups. New accounts get 100 free credits.
Any curl-specific tips for this request?
Yes. Pass the key with -H "x-api-key: $SOCIALFETCH_API_KEY", and wrap the full URL in double quotes so the shell doesn't split it at the & between query parameters. -sS hides the progress meter but still shows connection errors. curl doesn't treat an HTTP error status as a failure, so read the error JSON it prints, or add --fail-with-body.
Any Node.js-specific tips for this request?
Yes. Native fetch doesn't throw on 4xx or 5xx responses, so check response.ok (or status) before parsing JSON. Keep meta.requestId from the body in case you need support with a row.
Any Python-specific tips for this request?
Yes. Call response.raise_for_status() before response.json(), set a timeout on requests.get, and keep response.json()["meta"]["requestId"] when a row looks wrong.
Related