# X post search API

> Posts matching a query (X search operators work), latest or top.

Canonical page: https://okdata.online/apis/x/posts/search/

- **Endpoint**: `GET /v1/x/posts/search`
- **ID**: `x.posts.search`
- **Price**: $0.002 per call · about 20 posts per page
- **Returns**: a page of about 20 posts (`data.items`, Post objects)
- **Status**: preview
- **Good for**: Word of mouth, Trend research

## Price

One call costs $0.002 and returns one page of about 20 posts. Collecting 1,000 posts takes about 50 calls, $0.10 in total. Each page is a separate call. A call that reached the data source is charged even when it comes back empty, not found or failed; calls stopped before reaching a source are free.

## Parameters

| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| `query` | string | yes |  | Keywords, as a person would type them into the platform search box. (e.g. `"claude code" lang:zh`) |
| `sort` | string: latest / top | no | `latest` | Result order. |
| `cursor` | string | no |  | Opaque cursor from page.next_cursor of the previous call. Each page is a separate call. |
| `view` | string: brief / compact / standard / full | no | `standard` | How much of each object comes back. brief: IDs, title, the first 100 characters of the text, link, time and the main counts, for scanning a list (then get what you need by ID). compact leaves out empty fields and cuts long text at 500 characters. full adds platform-specific fields under ext. |
| `fields` | string[] | no |  | Fields to keep, by path (author.name), to save tokens. In a query string: comma-separated. |

cursor, view and fields work as described in [Requests](https://okdata.online/docs/requests/).

## Returned fields

Each item is a [Post](https://okdata.online/docs/objects/post/).

| Field | Type | Description |
|---|---|---|
| `id` | string | Post ID on the platform. |
| `url` | string | Link to the post. |
| `type` | string | What kind of post it is. |
| `title` | string \| null | Title, where the platform has one (videos, notes, articles). |
| `text` | string | Caption, body or description as plain text; articles come as Markdown. |
| `lang` | string \| null | Language code, as reported or detected. |
| `published_at` | string \| null | When it was published, ISO 8601 in UTC; null only where the source gives no time (wechat_mp.articles.metrics, wechat_channels.videos.metrics, youtube.channels.videos.list with type=short) or left it out of an answer (youtube.videos.get now and then), then listed in meta.unavailable. Never an empty string. |
| `author` | AccountRef | Who posted it. |
| `metrics` | Metrics | Counts at fetch time; a count the platform hides is null. |
| `images` | string[] \| null | Image URLs for image posts and notes. |
| `hashtags` | string[] \| null | Hashtags or topics, without the # sign. |
| `ext` | object | Platform-specific extras. Only returned with view=full. |

## Request examples

### cURL

```bash
curl -G "https://api.okdata.online/v1/x/posts/search" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query="claude code" lang:zh'
```

### Python

```python
import os
import requests

resp = requests.get(
    "https://api.okdata.online/v1/x/posts/search",
    headers={"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"},
    params={"query": "\"claude code\" lang:zh"},
    timeout=60,
)
body = resp.json()
if body["code"] != "ok":
    raise RuntimeError(f"{body['code']}: {body['message']} (charged: {body['charged']})")

for row in body["data"]["items"]:
    print(row["id"], row["metrics"]["likes"], row["text"][:60])
print("cost: $" + body["meta"]["billing"]["amount"])
```

### TypeScript

```ts
const url = new URL('https://api.okdata.online/v1/x/posts/search');
url.searchParams.set('query', "\"claude code\" lang:zh");

const res = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.OKDATA_API_KEY}`,
  },
});
const body = await res.json();
if (body.code !== 'ok') throw new Error(`${body.code}: ${body.message}`);

for (const row of body.data.items) {
  console.log(row.id, row.metrics.likes, row.text.slice(0, 60));
}
console.log('cost: $' + body.meta.billing.amount);
```

### MCP

```json
{
  "name": "call",
  "arguments": {
    "capability": "x.posts.search",
    "query": "\"claude code\" lang:zh"
  }
}
```

Or ask an agent that has the MCP server connected:

> Use X post search and list the five posts with the most likes, with links.

## Response example

```json
{
  "code": "ok",
  "request_id": "0f6c2a8e-4b1d-4e0a-9a51-3c7d2b9e1f20",
  "data": {
    "items": [
      {
        "id": "1856012345678901234",
        "url": "https://x.com/trailkit/status/1856012345678901234",
        "type": "text",
        "title": null,
        "text": "Shipped the lighter tent today. 1.1 kg packed, same footprint.",
        "lang": "en",
        "published_at": "2026-11-02T09:30:00Z",
        "author": {
          "id": "1450012345678901248",
          "username": "trailkit",
          "name": "Trail Kit",
          "avatar_url": "https://cdn.example.com/avatar/trailkit.jpg",
          "followers": 18230,
          "verified": true
        },
        "metrics": {
          "views": 1250000,
          "likes": 48200,
          "comments": 1312,
          "shares": null,
          "favorites": 9650,
          "reposts": 640
        },
        "images": null,
        "hashtags": null
      }
    ]
  },
  "page": {
    "next_cursor": "c1.k3Vq9TzR0bYw2LmXe8NdPa",
    "cursor_expires_at": "2026-11-12T08:00:00Z",
    "has_more": true,
    "returned": 1
  },
  "warnings": [],
  "meta": {
    "capability": "x.posts.search",
    "result_status": "complete",
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    },
    "unavailable": {
      "metrics.shares": "platform"
    },
    "cached": false,
    "replayed": false,
    "fetched_at": "2026-11-11T08:00:00Z"
  }
}
```

## Errors

Errors share one shape: code, request_id, message and message_zh (a fixed sentence per code), charged, retry, retry_after_seconds, param and docs_url, with the specifics in problems. An error from a call that reached the data source (not found, a failure or a timeout of the source) is charged once at this endpoint's price, with charged: true and amount; errors before that, such as bad parameters, are not charged. Only settlement_unknown is unknown until looked up. The full table: https://okdata.online/docs/errors/

## Questions

### How much does the X post search API cost?

One call costs $0.002 and returns one page of about 20 posts. Collecting 1,000 posts takes about 50 calls, $0.10 in total. Each page is a separate call. A call that reached the data source is charged even when it comes back empty, not found or failed; calls stopped before reaching a source are free.

### How do I get the next page?

Pass page.next_cursor from the response back as the cursor parameter. When page.has_more is false there is nothing left. Every page is its own call at $0.002.

### Do I need a X (Twitter) account, cookies or a QR login?

No. You send only your okdata API key. The data is public data from X (Twitter); nothing is fetched with your own X (Twitter) account.

### Am I charged when a call fails?

Yes, once, when the call reached the data source: an empty answer, a not_found, a failure or a timeout of the source costs one call (one item for per-item endpoints), and the error says charged: true with amount. Calls refused before reaching a source, such as bad parameters or a low balance, cost nothing.

### What if X (Twitter) does not show a field?

The field is null, and meta.unavailable names it with the reason: platform (the platform never shows it) or capability (we cannot fetch it yet).

## More X (Twitter) endpoints

- [X post detail](https://okdata.online/apis/x/posts/get/): $0.0003 per call
- [X account profile](https://okdata.online/apis/x/users/get/): $0.0004 per account · at most $0.04 per call
- [X account posts](https://okdata.online/apis/x/users/posts/list/): $0.002 per call · about 20 posts per page
- [X trending topics](https://okdata.online/apis/x/trends/list/): $0.009 per call · about 30 board entries per page
- [X post replies](https://okdata.online/apis/x/posts/replies/list/): $0.002 per call · about 35 posts per page
- [X post quotes](https://okdata.online/apis/x/posts/quotes/list/): $0.0003 per post · at most $0.006 per call
- [X post retweeters](https://okdata.online/apis/x/posts/retweeters/list/): $0.002 per call · about 100 accounts per page
- [X article](https://okdata.online/apis/x/posts/article/get/): $0.002 per call
- [X thread](https://okdata.online/apis/x/threads/posts/list/): $0.0003 per post · at most $0.015 per call
- [X account search](https://okdata.online/apis/x/users/search/): $0.0004 per account · at most $0.008 per call
- [X account followers](https://okdata.online/apis/x/users/followers/list/): $0.0001 per account · at most $0.02 per call
- [X account following](https://okdata.online/apis/x/users/following/list/): $0.0001 per account · at most $0.02 per call
- [X account mentions](https://okdata.online/apis/x/users/mentions/list/): $0.0003 per post · at most $0.006 per call
- [X list posts](https://okdata.online/apis/x/lists/posts/list/): $0.002 per call · about 100 posts per page
- [X list members](https://okdata.online/apis/x/lists/members/list/): $0.0004 per account · at most $0.008 per call
- [X list followers](https://okdata.online/apis/x/lists/followers/list/): $0.0004 per account · at most $0.008 per call
- [X community profile](https://okdata.online/apis/x/communities/get/): $0.0004 per call
- [X community posts](https://okdata.online/apis/x/communities/posts/list/): $0.0003 per post · at most $0.006 per call
- [X community members](https://okdata.online/apis/x/communities/members/list/): $0.0004 per account · at most $0.008 per call

## At a glance

- **Short name**: X post search
- **Category**: [Social media](https://okdata.online/categories/social/)
- **Data type**: [Post search API](https://okdata.online/roles/posts-search/)
- **Status**: preview. It may still change; any change is announced beforehand.
- **Price**: $0.002 per call · bad parameters are free
- **Returns**: About 20 posts a page, with a cursor for the next page
- **If a call fails**: Charged once. When a data source fails, the next one is tried. A call that reached a source is charged once even if it fails; bad parameters are free.

## When it is charged

- Data comes back: $0.002 per call
- Bad parameters, too little balance, a paused endpoint: Free

| When | Charge |
|---|---|
| Each further page | A new call: $0.002 |
| Most one call costs | $0.002 |
| An empty answer | $0.002 |
| The data source fails or times out | $0.002 |
| Bad parameters, too little balance, a paused endpoint | Free |
| Resent with the same Idempotency-Key within 24 hours | Free when the kept result comes back |

A call that reached the data source costs $0.002 even when the answer is empty, not found or a failure of the source; a call stopped before that, such as for bad parameters, is free.

Prices from price book 53dd8ce13c359590. [Every price on this platform](https://okdata.online/pricing/x/)

- New accounts get $0.10 of credit, no card needed: 50 calls to this endpoint.
- About 50 calls fetch 1,000 posts: $0.10 in all.

## Known limits

- About 20 posts come back per page; the platform sets the page size, so there is no page-size parameter.
- For the next page, pass `page.next_cursor` back as `cursor`. A cursor stays valid for 24 hours. When `page.has_more` is false there is nothing left.

## Fields by view

The view column is the smallest `view` a field comes back in: `compact` returns only compact fields, `standard` adds the standard ones, `full` returns everything. The default is `standard`.

- `compact`: `id`, `url`, `type`, `title`, `text`, `published_at`, `author`, `metrics`
- `standard`: `lang`, `images`, `hashtags`
- `full`: `ext`

## What this endpoint cannot give

- `metrics.shares`: the platform does not show it (null, listed in meta.unavailable)

## Common errors on this endpoint

| HTTP | Code | Meaning | Charged | Retry |
|---|---|---|---|---|
| 400 | `invalid_params` | A parameter is missing, has the wrong type or value, or the method is wrong. problems lists each one; param names the first. | no | after a fix |
| 400 | `cursor_mismatch` | The cursor was sent to another endpoint, or with other parameters than the page it came from (view and fields may change). | no | after a fix |
| 401 | `unauthorized` | The key is missing, malformed, revoked, disabled or expired (reason says which when known). | no | no |
| 402 | `insufficient_balance` | The balance (available) cannot cover the most this call could cost (required). | no | after a fix |
| 410 | `cursor_expired` | The cursor is older than the endpoint's cursor lifetime (page.cursor_expires_at said when). | no | no |
| 429 | `rate_limited` | The account sent too many requests this minute (reason: rate) or has too many calls running (reason: concurrency). | no | yes |
| 500 | `settlement_unknown` | The data came back, but the charge could not be confirmed. | unknown until looked up | with the same Idempotency-Key |
| 502 | `upstream_failed` | Every data source for this endpoint failed on this request. If a source billed the attempt, it is charged once at the endpoint's price (charged: true and amount); otherwise nothing is charged. | once, if it reached a data source | yes |
| 503 | `capability_paused` | This endpoint is paused right now; nothing ran. | no | yes |
| 504 | `timeout` | The data did not come back in time. If the request had reached a data source that bills it, it is charged once at the endpoint's price (charged: true and amount); otherwise the hold is released. | once, if it reached a data source | yes |

[All error codes](https://okdata.online/docs/errors/)

## Same data on other platforms

- [Douyin video search](https://okdata.online/apis/douyin/videos/search/): $0.02 per call · about 20 videos per page
- [Xiaohongshu note search](https://okdata.online/apis/xiaohongshu/notes/search/): $0.02 per call · about 20 notes per page
- [Bilibili video search](https://okdata.online/apis/bilibili/videos/search/): $0.002 per call · about 20 videos per page
- [Weibo post search](https://okdata.online/apis/weibo/posts/search/): $0.002 per call · about 10 posts per page
- [TikTok video search](https://okdata.online/apis/tiktok/videos/search/): $0.002 per call · about 30 videos per page
- [YouTube video search](https://okdata.online/apis/youtube/videos/search/): $0.004 per call · about 20 videos per page
- [Reddit post search](https://okdata.online/apis/reddit/posts/search/): $0.004 per call · about 25 posts per page
- [Kuaishou video search](https://okdata.online/apis/kuaishou/videos/search/): $0.02 per call · about 10 videos per page
- [Zhihu search](https://okdata.online/apis/zhihu/posts/search/): $0.002 per call · about 20 posts per page
- [WeChat Channels video search](https://okdata.online/apis/wechat_channels/videos/search/): $0.02 per call · about 10 videos per page
- [WeChat Search articles and videos](https://okdata.online/apis/wechat/posts/search/): $0.02 per call · about 20 posts per page
- [Xigua Video search](https://okdata.online/apis/xigua/videos/search/): $0.002 per call · about 10 videos per page

[Post search API](https://okdata.online/roles/posts-search/)

## Use it in your AI

> Read https://okdata.online/apis/x/posts/search.md, then call this endpoint for me through okdata; my key is in the OKDATA_API_KEY environment variable. Use X post search and list the five posts with the most likes, with links.

## X (Twitter) endpoints by group

- [X Lists API](https://okdata.online/apis/x/lists/): X list posts $0.002, X list members $0.0004, X list followers $0.0004
- [X Communities API](https://okdata.online/apis/x/communities/): X community profile $0.0004, X community posts $0.0003, X community members $0.0004

## Answers that use this endpoint

- [Is there an X (Twitter) MCP server for Claude that reads live posts, replies and followers?](https://okdata.online/answers/x-twitter-mcp-server-claude/): Yes, two kinds. X's own MCP server runs on an X developer app that you create and set up. To only read public X data, add okdata's MCP server (https://api.okdata.online/mcp) to Claude as a custom connector and sign in, with no X account: Claude can then search posts ($0.002 for about 20 posts), read an account's timeline, the replies under a post, followers, lists, communities and trends. Every post that mentioned a brand this week plus the replies under the 20 most-liked costs about $0.10.
- [If my agent retries a tool call after a timeout, will I be charged twice?](https://okdata.online/answers/agent-retry-charged-twice/): Not if the retry carries the same idempotency key as the first attempt: okdata keeps each successful result for 24 hours and hands it back with no new charge, so a retried X search costs $0.002 once. A call that reached the data source is charged even when it comes back empty or failed, and retrying a failed one is a new call. After a timeout, resend with the same key to find out whether the first attempt went through.
- [How do I give my AI agent live X (Twitter) search without the official X API?](https://okdata.online/answers/ai-agent-live-x-search/): Give the agent a pay-per-call X search tool: okdata's X post search takes the same query syntax as the X search box (quoted phrases, from:, lang:) and returns about 20 posts for $0.002, which is $0.10 per 1,000 posts. An account's latest posts cost $0.002 a page and a country's trends $0.009.
- [Can a pay-per-call data API change its prices in the middle of my project?](https://okdata.online/answers/data-api-price-changes/): Yes. Any vendor can change prices, and several have, X among them. On okdata each call is charged the endpoint's price at the moment of the call (X post search is $0.002 today, Douyin search $0.02), the price book has a version number your script can watch, and every response states its exact charge, so a change shows up on the first call after it.
- [How do I get all the tweets from a Twitter account?](https://okdata.online/answers/get-all-tweets-from-account/): Page the account with X account posts ($0.002 per page of about 20 posts, newest first), and reach older periods with X post search using from:handle plus since:/until: dates ($0.002 per page). A year of an account that posts ten times a day is about 183 pages, roughly $0.366.
- [Is it legal to scrape public social media data?](https://okdata.online/answers/is-scraping-public-social-media-data-legal/): Often it can be, but it depends on where you are, how you collect and what you do with the data, so treat this as general information and ask a lawyer about your case. US courts have found that scraping public pages is unlikely to count as hacking, yet contract, copyright and privacy law still apply. A data API such as okdata returns public data only (X search is $0.002 a page), but it does not take the legal responsibility for your use off you.
- [How do I give a LangChain or LangGraph agent social media data tools?](https://okdata.online/answers/langchain-mcp-social-data-tools/): Either wrap the endpoints you need as LangChain tools that call okdata over HTTP, or load the okdata MCP server with langchain-mcp-adapters and get the find, describe, call, read_more and account tools for all 265 endpoints at once. Only data calls are billed, for example $0.02 per Xiaohongshu search page and $0.002 per X search page.
- [How do I monitor brand mentions on X without an enterprise plan?](https://okdata.online/answers/monitor-brand-mentions-x/): Run X post search sorted by latest every 30 minutes for your brand name and handle, and stop paging as soon as you reach a post you have already seen. Each page of about 20 posts costs $0.002, so a check every half hour is 1,440 calls a month, $2.88 if one page is usually enough.
- [Should I use a platform's official API or a third-party social data API?](https://okdata.online/answers/official-api-vs-third-party-social-data/): Use the official API when you need to post, need private metrics of accounts you control, or need a direct agreement with the platform. Use a third-party API for public data about accounts you do not control, or when the official one does not offer it: YouTube's API cannot download captions for videos you cannot edit, while okdata returns any public video's transcript for $0.004. X's official reads are priced per post; okdata X search is $0.002 a page of about 20.
- [snscrape fails on Twitter with blocked (404). Is there a working replacement?](https://okdata.online/answers/snscrape-twitter-blocked-404/): snscrape's Twitter modules relied on logged-out access that X closed, and there is no fix in the project. Rebuild the pipeline on X post search ($0.002 per page of about 20 posts) and X account posts ($0.002 per page). A 10,000-post research corpus costs about $1.00.
- [What happens to a social data API when the platform changes or a source goes down?](https://okdata.online/answers/social-data-api-reliability-failover/): A good one absorbs the break so your code does not change: it tries another source where it has one, returns a clear, retryable error when every source fails, and keeps the same fields. On okdata, trying several sources behind one call does not multiply its price: a call that reached a data source is charged once at the normal price even when the source fails, such as $0.002 for X search, and a retry is a new call at that price.
- [Is there one API to track a brand across TikTok, YouTube and X?](https://okdata.online/answers/social-listening-api-tiktok-youtube-x/): Yes: okdata searches TikTok ($0.002 a page), YouTube ($0.004 a page) and X ($0.002 a page) with one key, and returns posts in the same shape on all three. A weekly brand sweep of about 120 TikTok videos, 40 YouTube videos with their top comments and 200 X posts costs $0.076.
- [What should a social media monitoring job cost per month?](https://okdata.online/answers/social-listening-monthly-budget/): A typical brand watch on okdata, 10 keywords checked twice a day with one page each on Weibo, Xiaohongshu, Douyin and X, is 2,400 calls a month and costs $26.40. Adding the Weibo hot search list every hour costs another $1.44. There is no monthly fee: the bill is the number of calls times each endpoint's price.
- [What does it cost to pull 1,000 posts from X, TikTok, Weibo or Xiaohongshu through an API?](https://okdata.online/answers/social-media-posts-cost-per-1000/): Through okdata keyword search, 1,000 posts cost $0.10 on X, $0.068 on TikTok, $0.20 on Weibo and $1.00 on Xiaohongshu. Each call is one page of results ($0.002 for about 20 X posts), and results already carry likes, comment counts and the author, so most jobs need no extra calls.
- [Is there an MCP server that gives Claude TikTok, YouTube and X data?](https://okdata.online/answers/tiktok-youtube-x-mcp-server/): Yes. Add the okdata MCP server (https://api.okdata.online/mcp) to Claude with your API key, and Claude can search TikTok ($0.002 a page), read YouTube transcripts ($0.004 a video) and search X ($0.002 a page), plus comments, profiles and trends, all with one key and no platform logins. A ten-call research session across the three costs $0.035.
- [How do I get the view count of any tweet through an API?](https://okdata.online/answers/tweet-view-count-api/): Send the post's link or ID to X post detail: it returns views, likes, replies, reposts and bookmarks for any public post, yours or not, for $0.0003 a post. Checking 50 campaign posts once a day for two weeks is 700 calls, $0.21.
- [Twitter's free academic API is gone. How can researchers collect tweets now?](https://okdata.online/answers/twitter-academic-api-alternative/): X ended free academic access in 2023. Today a researcher can pay X directly ($0.005 per post through full-archive search, so 20,000 posts cost $100) or collect public posts with X post search at $0.002 per page of about 20, which puts 20,000 posts at $2.00. Slice queries by month and keep the exact queries for your methods section.
- [twscrape says No active accounts and my X accounts keep getting locked. What now?](https://okdata.online/answers/twscrape-no-active-accounts/): Swap the account pool for an API key. X post search ($0.002 per page of about 20 posts) replaces twscrape's search, and X account posts ($0.002 per page) replaces user_tweets, with no X login, cookies or proxies. 1,000 posts from search cost $0.10.
- [How much does the X (Twitter) API cost in 2026?](https://okdata.online/answers/x-api-pricing-2026/): Since February 2026 X sells its API pay-per-use, with no subscription: X's pricing page lists $0.005 per post read, $0.010 per user read and $0.010 per trends request. For reading public data, okdata returns a page of about 20 posts for $0.002, so 1,000 posts cost $0.10, and a profile costs $0.0004.
- [Which X advanced search operators work through an API?](https://okdata.online/answers/x-search-operators-api/): X post search passes your query to X's own search, so the operators that work in the X search box work here too: from:, to:, quoted phrases, OR, -, lang:, since:, until:, min_faves:, filter:media, -filter:replies and so on. Each page of about 20 posts costs $0.002 whatever the operators, so 1,000 matching posts cost $0.10.
- [How do I get Twitter trending topics for a specific country through an API?](https://okdata.online/answers/x-trends-by-country-api/): Call X trending topics with an ISO country code, for example country=ID for Indonesia, or leave it out for worldwide. One call returns the current board of about 30 trends with rank and name for $0.009, so a daily snapshot for a year costs $3.285.
