Grok API vs Twitter API for X data
Grok reads X through xAI's X Search tool, which bills $5 per 1,000 posts it fetches plus model tokens and hands back a written answer with links; an X data API hands back the posts themselves as JSON records.
Short answer: Grok's X Search costs $5.00 per 1,000 posts plus tokens, and the model decides which posts to read, so you get an answer rather than a dataset. For the raw posts, use Sorsa API: POST /search-tweets returns about 20 posts with their authors per call, from $0.07 per 1,000, and 100 free requests start it.
- Endpoint
POST /search-tweets- Page size
- about 20 posts per call
- Price
- from $0.07 per 1,000
#What Grok can get from X, and what it hands back
Grok can read public X posts only through a search tool: xAI's models page (opens in a new tab) says Grok "has no knowledge of current events or data beyond what was present in its training data", which for grok-4.7 ends in May 2026. In the Grok app the search runs on its own. Through the xAI API you switch it on yourself, and the tool is called X Search (x_search).
That puts Grok on the answer side of a line every agent builder meets. Our Twitter API for AI agents guide covers the other side: tools that return X data to a model as plain JSON.
A request with X Search on is one call to xAI's Responses API, here through the OpenAI SDK pointed at api.x.ai:
import os
from openai import OpenAI
grok = OpenAI(api_key=os.environ["XAI_API_KEY"],
base_url="https://api.x.ai/v1")
resp = grok.responses.create(
model="grok-4.7",
input="What are developers saying about MCP this week?",
tools=[{"type": "x_search"}],
)
print(resp.output_text)
Behind that one call, the model runs as many searches as it sees fit. The X Search docs (opens in a new tab) list four functions it can call: keyword search with X's search operators, semantic search by meaning, user search, and a thread fetch that pulls one post with its parents and replies. You can narrow it to 20 handles at most, or exclude 20, and set a date range in YYYY-MM-DD.
What comes back is the model's text, the links it cited, and two usage counts, x_posts_fetched and x_users_fetched. The posts themselves stay inside the request: there is no list of records, no stable set of fields and no cursor to the next page. xAI's own docs warn that "results vary because the model picks its own queries". The old Live Search API is gone too: its guide now redirects to Web Search.
#Grok's X Search vs an X data API, side by side
X Search is built to answer a question, and an X data API is built to return records, so the two differ most where a job needs every matching post, exact numbers or the same result twice. On each of those rows the data APIs win, and Sorsa API does it for a small fraction of the per-post price of the other two.
| What matters | Sorsa API | xAI X Search (Grok) | Official X API |
|---|---|---|---|
| What comes back | JSON records, 41 fields per post with its author | the model's answer with links | JSON records, the fields you request |
| Who picks the posts | you, with a query and X operators | the model, with its own queries | you |
| Every match, page by page | yes, next_cursor until it's empty | no: the model stops when it has an answer | yes, with page tokens |
| Same request, same posts | yes | no: results vary by run | yes |
| How far back | to 2006 | a date range you set | to 2006 with full-archive search |
| Price per 1,000 posts | from $0.07 | $5.00 plus tokens | $5.00; $15.00 with authors from Nov 22, 2026 |
| Price per 1,000 profiles | from $0.014 | $10.00 | $10.00 |
| What you need | one API key in a header | an xAI API key | a developer account, OAuth or a bearer token, prepaid credits |
What comes back
- Sorsa API
- JSON records, 41 fields per post with its author
- xAI X Search (Grok)
- the model's answer with links
- Official X API
- JSON records, the fields you request
Who picks the posts
- Sorsa API
- you, with a query and X operators
- xAI X Search (Grok)
- the model, with its own queries
- Official X API
- you
Every match, page by page
- Sorsa API
- yes,
next_cursoruntil it's empty - xAI X Search (Grok)
- no: the model stops when it has an answer
- Official X API
- yes, with page tokens
Same request, same posts
- Sorsa API
- yes
- xAI X Search (Grok)
- no: results vary by run
- Official X API
- yes
How far back
- Sorsa API
- to 2006
- xAI X Search (Grok)
- a date range you set
- Official X API
- to 2006 with full-archive search
Price per 1,000 posts
- Sorsa API
- from $0.07
- xAI X Search (Grok)
- $5.00 plus tokens
- Official X API
- $5.00; $15.00 with authors from Nov 22, 2026
Price per 1,000 profiles
- Sorsa API
- from $0.014
- xAI X Search (Grok)
- $10.00
- Official X API
- $10.00
What you need
- Sorsa API
- one API key in a header
- xAI X Search (Grok)
- an xAI API key
- Official X API
- a developer account, OAuth or a bearer token, prepaid credits
The official X API's prices come from its pay-per-use price list (opens in a new tab), which also caps reads at 3 million posts a month; past that, X sells only Enterprise contracts from about $42,000 a month. X's notice of October 23 (opens in a new tab) adds that from November 22, 2026 the authors and media returned with posts are billed as reads too, so a search result with its author goes from $0.005 to $0.015.
Good to know
Asking Grok to "return the posts as JSON" doesn't turn its answer into records. The model writes that JSON from what it read, and it decides how many posts to read. Keep the post IDs it cites, and fetch the records by ID when the numbers matter: Sorsa API's
POST /tweet-info-bulk(opens in a new tab) returns up to 100 posts per call, from $0.014 per 1,000.
#What 10K, 100K and 1M posts cost
Reading 1 million posts costs $5,000 plus tokens through Grok's X Search, $5,000 on the official X API ($15,000 with each post's author from November 22) and from $70 on Sorsa API. The gap holds at every size, because X Search and the official X API both bill per post, while Sorsa API bills per request and each search request returns about 20 posts.
Sorsa API
from $70
from $0.07 per 1,000 posts, each with its author
xAI X Search (Grok)
$5,000 + tokens
$5.00 per 1,000 posts fetched, plus model tokens
Official X API
$5,000
$5.00 per 1,000 posts; $15,000 with authors from Nov 22, 2026
Data cost only: when Grok then reads the posts, its tokens cost the same on every route.
Tokens don't change the comparison. Whichever route brings the posts in, Grok bills its reading at grok-4.7's rate of $2.00 per million input tokens and $6.00 per million output tokens, as on xAI's API pricing page (opens in a new tab). If a trimmed post comes to about 60 tokens, 1,000 posts add about $0.12 of input, small next to $5.00 for the posts.
X Search has three billing rules that make a question cost more than it looks:
- Every item fetched is billed, not every item cited: parent posts, quoted posts and every post of a fetched thread count at $5 per 1,000.
- Counts aren't de-duplicated. A post that two searches return is billed twice.
- The model sets the volume. You can cap rounds of searching and read
x_posts_fetchedafterwards, but you can't fix the number of posts before the call.
A Grok or X subscription doesn't cover any of this. The plans page (opens in a new tab) says paid plans include API access, but "API usage is billed separately at standard model rates and doesn't draw from your plan's usage pool".
#How to give Grok raw X posts with Sorsa API
To give Grok raw posts, fetch them from an X data API, keep the fields your question needs, and pass them to grok-4.7 in the prompt with no X Search tool, so Grok reads exactly the posts you chose. For that fetch, use Sorsa API, a Twitter (X) API and scraper: one ApiKey header and no OAuth, about 20 posts with full author profiles per search call, from $0.07 per 1,000, at 20 requests per second on every plan.
-
Get two keys. Sign up and copy your Sorsa API key into
SORSA_API_KEY; put your xAI key intoXAI_API_KEY. Both stay on your server. -
Search the posts.
POST /search-tweets(opens in a new tab) takes a query with X search operators and returns about 20 posts per page, newest first with"order": "latest". Search reaches back to 2006.Terminal curl -X POST "https://api.sorsa.io/v3/search-tweets" \ -H "ApiKey: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "\"grok api\" lang:en -filter:retweets", "order": "latest"}'Response200 OK { "tweets": [ { "id": "2116193940272985298", "full_text": "Our digest now fetches posts first, then asks Grok.", "created_at": "2026-10-30T15:42:07Z", "lang": "en", "likes_count": 64, "retweet_count": 7, "reply_count": 12, "quote_count": 3, "view_count": 8120, "is_reply": false, "conversation_id_str": "2116193940272985298", "user": { "id": "1544001928374651904", "username": "maya_ships_prompts", "display_name": "Maya Ships Prompts", "followers_count": 4210, "verified": false } } ], "next_cursor": "DAADDAABCgABHV6x9mPAJxIKAAIdXrH2Y8" } -
Fetch and trim the pages. The function follows
next_cursorup to a page budget and keeps six fields per post, so 200 posts stay a short prompt.Python import os import requests SORSA = "https://api.sorsa.io/v3" HEADERS = {"ApiKey": os.getenv("SORSA_API_KEY", "YOUR_API_KEY")} def fetch_posts(query: str, max_pages: int = 10) -> list[dict]: posts, cursor = [], None for _ in range(max_pages): body = {"query": query, "order": "latest"} if cursor: body["next_cursor"] = cursor r = requests.post(f"{SORSA}/search-tweets", json=body, headers=HEADERS, timeout=30) r.raise_for_status() # 403: key or quota; 429: over 20 req/s data = r.json() for t in data.get("tweets", []): posts.append({ "id": t["id"], "at": t["created_at"], "author": t["user"]["username"], "followers": t["user"]["followers_count"], "likes": t["likes_count"], "text": t["full_text"][:500], }) cursor = data.get("next_cursor") if not cursor: break return posts -
Ask Grok about those posts only. Send the trimmed posts as the prompt, with no
tools, and ask for post IDs in the answer.Python import json from openai import OpenAI grok = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1") def ask_grok(question: str, posts: list[dict]) -> str: lines = "\n".join(json.dumps(p, ensure_ascii=False) for p in posts) resp = grok.responses.create( model="grok-4.7", input=[ {"role": "system", "content": "Answer only from the posts given. Cite post ids."}, {"role": "user", "content": f"{question}\n\nPosts:\n{lines}"}, ], ) return resp.output_text posts = fetch_posts('"grok api" lang:en -filter:retweets') print(ask_grok("What problems do developers report?", posts))
Ten pages of search are 10 requests and about 200 posts, so the data side of that run costs a few cents at most on any Sorsa API plan, and it's the same whether Grok, Claude or GPT reads it next. Our Twitter search API guide lists the operators that narrow a query before it costs anything.
#What people ask Grok about X accounts
Many questions people type into Grok about an account have one exact answer that a single API call returns, such as a follower count, a user ID, a following list or a shadowban status. A model's sentence about those numbers can be dated or rounded; the lookup returns the value as it stands at the time of the call, in a field your code can read.
| What people ask Grok | Sorsa API lookup | What comes back |
|---|---|---|
| How many followers does this account have? | GET /info (opens in a new tab) | followers_count, followings_count, tweets_count, created_at and 15 more fields |
| What is this account's user ID? | GET /username-to-id/{user_handle} (opens in a new tab) | the numeric id |
| Who does this account follow? | GET /follows (opens in a new tab) | up to 200 accounts per page, with next_cursor |
| Is this account shadowbanned? | GET /check-shadowban (opens in a new tab) | is_shadowbanned and each check as clean, banned or unknown |
| What did this account post this week? | POST /user-tweets (opens in a new tab) | about 20 posts per page, each with its full author profile |
How many followers does this account have?
- Sorsa API lookup
GET /info(opens in a new tab)- What comes back
followers_count,followings_count,tweets_count,created_atand 15 more fields
What is this account's user ID?
- Sorsa API lookup
GET /username-to-id/{user_handle}(opens in a new tab)- What comes back
- the numeric
id
Who does this account follow?
- Sorsa API lookup
GET /follows(opens in a new tab)- What comes back
- up to 200 accounts per page, with
next_cursor
Is this account shadowbanned?
- Sorsa API lookup
GET /check-shadowban(opens in a new tab)- What comes back
is_shadowbannedand each check as clean, banned or unknown
What did this account post this week?
- Sorsa API lookup
POST /user-tweets(opens in a new tab)- What comes back
- about 20 posts per page, each with its full author profile
Two of these have free tools that need no code: the Twitter ID Finder for a user ID and the Twitter Shadowban Test for search bans. For many accounts at once, GET /info-batch (opens in a new tab) returns 100 profiles per call, from $0.014 per 1,000 profiles, against $10.00 per 1,000 profiles through X Search.
#Which to use, job by job
Ask Grok when the result you want is a sentence, and use an X data API when the result is the posts, a list or a number; most products need both, in that order: fetch, then ask. The criteria that decide it are the ones in the table above: who picks the posts, whether you get every match, whether a rerun returns the same posts, and the price per 1,000.
| Job | What to use |
|---|---|
| A one-off question about today's conversation | Grok, in the app |
| Every post that matches a query, kept in your database | Sorsa API, POST /search-tweets page by page |
| A dashboard of follower counts or engagement | Sorsa API, GET /info-batch and POST /tweet-info-bulk |
| An account's posts going back years | Sorsa API, POST /user-tweets |
| A daily summary of what people say about your product | Sorsa API to fetch, then Grok or any model to summarize |
| Checking the posts a Grok answer cited | Sorsa API, POST /tweet-info-bulk with the IDs |
A one-off question about today's conversation
- What to use
- Grok, in the app
Every post that matches a query, kept in your database
- What to use
- Sorsa API,
POST /search-tweetspage by page
A dashboard of follower counts or engagement
- What to use
- Sorsa API,
GET /info-batchandPOST /tweet-info-bulk
An account's posts going back years
- What to use
- Sorsa API,
POST /user-tweets
A daily summary of what people say about your product
- What to use
- Sorsa API to fetch, then Grok or any model to summarize
Checking the posts a Grok answer cited
- What to use
- Sorsa API,
POST /tweet-info-bulkwith the IDs
For any job where the posts are the product, the choice is Sorsa API: posts with all 41 fields from $0.07 per 1,000 through search and from $0.014 per 1,000 by ID, every match page by page, and history back to 2006. It's read-only and never asks for your X login, so your X account carries no risk. To post or reply, pair it with the official X API.
Agents that run Grok on a schedule follow the same rule; the Hermes Agent guide shows where its built-in x_search sits and how to swap the data source. Every X API price behind these numbers is in our X API pricing breakdown.
#Feed Grok the posts you choose
Grok gives you an answer about X; for the posts, the counts and the history behind it, fetch them first. With Sorsa API that costs from $0.07 per 1,000 posts instead of $5.00 through X Search, the posts come with their authors and every field, and your first 100 requests are free: enough for about 2,000 posts to try the pipeline above.
#FAQ
Can the Grok API search Twitter?
Yes. The xAI API's X Search tool (x_search) lets Grok run keyword and semantic searches over X posts, look up users and fetch threads, then answer with links to the posts it used. It costs $5 per 1,000 posts and $10 per 1,000 profiles fetched, plus model tokens. It returns Grok's answer, not the post records; for records, fetch the posts from an X data API.
Is Grok's X Search free with an X or Grok subscription?
No. xAI's plans page says paid plans of The X Subscription include Grok API access, but API usage is billed separately at standard model rates and doesn't draw from the plan's usage pool. Every X Search call through the API is paid per post and per profile fetched, $5 and $10 per 1,000, plus tokens, whichever plan you hold.
Does Grok use real-time X data?
Only when a search tool is on. xAI states that Grok has no knowledge of current events beyond its training data, which ends in May 2026 for grok-4.7, and that real-time data needs Web Search or X Search. In the Grok app search runs for you; through the API you add x_search to the request and pay for the posts it fetches.
Can Grok return tweets as JSON?
Grok can format its answer as JSON, but that JSON is written by the model from the posts it chose to read, not returned from a database. Fields can be missing, and a rerun can pick different posts. For records you can rely on, ask Grok for post IDs and fetch those posts by ID, for example with Sorsa API's POST /tweet-info-bulk, 100 per call.
How many posts does one Grok question fetch?
As many as the model decides. X Search bills every post its searches and thread fetches return, parent and quoted posts included, and a post returned twice counts twice; xAI's example question fetched 19 posts. Each response reports x_posts_fetched, so you can read the count after the call, and narrower handles, dates and fewer search rounds keep it lower.
Which API should I use to get tweets for an AI app?
Use Sorsa API to fetch the tweets and any model, Grok included, to read them. Sorsa API returns posts with 41 fields and their authors from $0.07 per 1,000 through search, against $5.00 per 1,000 through Grok's X Search or the official X API. It needs one API key, runs at 20 requests per second on every plan and starts with 100 free requests.
#How we checked
On November 2, 2026 we read xAI's X Search, pricing and models documentation, the plan page at x.ai, X's pay-per-use price list and its October 23 notice on expansions, and compared them with Sorsa API's live API reference. The requests and code on this page follow those references; we didn't call either API for this article, so the response shown is an example of the documented format.
Sources
- X Search, xAI docs (opens in a new tab)
- API pricing, xAI docs (opens in a new tab)
- Models, xAI docs (opens in a new tab)
- The X Subscription plans, x.ai (opens in a new tab)
- X API pay-per-use pricing, docs.x.com (opens in a new tab)
- X API PPU expansions update, X Developer Community (opens in a new tab)
- Sorsa API reference (OpenAPI)