# How to search X (Twitter) posts by keyword

One endpoint does it: X post search. The worked example below is 5 calls and costs $0.0100 in all; a failed call is not charged.

You get the X (Twitter) posts that match your terms, most popular or newest first: text, author, time, and like, reply, retweet, bookmark and view counts. X's own search operators work in the terms, such as `from:handle`.

## Step by step

### Step 1: X post search

Search with your terms as `query`; `sort` is `popular` (the default) or `latest`. For more posts, send `page.next_cursor` from one answer as `cursor` in the next call. ([X post search](https://dataxapi.com/apis/x/posts/search/), $0.0020 / a call)

cURL

```bash
curl -G "https://api.dataxapi.com/v1/x/posts/search" \
  --data-urlencode "query=weather forecast" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
```

Python

```python
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.x.posts.search(query="weather forecast")
print(result["data"]["items"])
```

TypeScript

```typescript
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.x.posts.search({ query: "weather forecast" });
console.log(result.data.items);
```

CLI

```bash
dataxapi call x.posts.search 'query=weather forecast'
```

Recorded response: From a response recorded 2026-10-12 19:10 UTC. Names, text and IDs are examples, and so are the links: none is the recorded one (the page shows no one's personal data); the figures are as recorded. Long lists are cut. The request ID, cursor and balance are made up.

```jsonc
{
  "code": "ok",
  "request_id": "f56e2410-206b-4506-a850-44cf2be4613e",
  "data": {
    "items": [
      {
        "id": "1860387339653354774",
        "url": "https://x.com/i/status/1860387339653354774",
        "type": "video",
        "text": "My honest take on weather forecast, a month in.",
        "lang": "en",
        "published_at": "2026-10-12T00:44:12.000Z",
        "author": {
          "id": "118815899823132376",
          "username": "trail_and_lens",
          "name": "Maya Chen",
          "avatar_url": "https://pbs.twimg.com/profile_images/1838837416644987075/31t9r3Fm_normal.jpg",
          "verified": true,
          "followers": 7425
        },
        "metrics": {
          "likes": 238,
          "comments": 37,
          "favorites": 145,
          "views": 8357,
          "reposts": 121
        },
        "images": [],
        "hashtags": [],
        "mentions": [
          {
            "id": "124366312906800227",
            "username": "fieldnotes_studio",
            "name": "Field Notes Studio"
          }
        ],
        "post_id": null,
        "parent_id": null
      },
      // … 19 more
    ]
  },
  "page": {
    "next_cursor": "c1.0BcduLiC6vViwQfDR_nS6Twlb6kjko4Qpbx3fUDt",
    "cursor_expires_at": "2026-10-12T20:10:39.000Z",
    "has_more": true,
    "returned": 20
  },
  "warnings": [],
  "meta": {
    "capability": "x.posts.search",
    "result_status": "complete",
    "fetched_at": "2026-10-12T19:10:39.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "title": "platform",
      "metrics.shares": "platform",
      "is_pinned": "capability",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}
```

## What the example costs

five pages of results, up to 100 posts

| Endpoint | Calls | Price | Subtotal |
| --- | --- | --- | --- |
| [X post search](https://dataxapi.com/apis/x/posts/search/) | 5 | $0.0020 | $0.0100 |
| Total | 5 |  | $0.0100 |

Prices are the prices in force when this page was built. A failed call, and an object that does not exist, cost nothing.

## In your AI (MCP)

Connect DataXAPI to your AI client once. Then say what you want; the agent finds these endpoints, checks the price and calls them on your balance.

Say: Use DataXAPI to search X for “weather forecast”, newest first, get 100 posts, and tell me which accounts post about it most.

What the agent sends to the call tool: 

```json
{
  "capability": "x.posts.search",
  "query": "weather forecast",
  "idempotency_key": "<a new UUID>"
}
```

[About the MCP server](https://dataxapi.com/mcp/)

## With a Skill

The Keyword search and mentions Skill does this job as a ready-made task, under a spending cap. “What is being said about this brand or keyword on each platform?” Its example run: 3 calls, at most $0.0240. [Keyword search and mentions](https://dataxapi.com/skills/mentions/)

## Good to know

- 20 posts a page; a cursor works for an hour, and an empty page is charged.
- `metrics.comments` is replies, `metrics.favorites` is bookmarks and `metrics.reposts` is retweets; quotes are counted apart, in `ext.quotes`.
- X has no share count, so `metrics.shares` is not returned; nor are a title or whether a post is pinned.
- To read what people say under one of the posts, pass its `id` to the post replies endpoint.

## Endpoints

- [X post search](https://dataxapi.com/apis/x/posts/search/)

## More about X (Twitter)

- [X (Twitter) API](https://dataxapi.com/apis/x/)
- [How to get X (Twitter) trending topics by country](https://dataxapi.com/guides/x-trends-by-country/)
- [How to get replies to an X (Twitter) post](https://dataxapi.com/guides/x-post-replies/)
- [How do I get X (Twitter) trends for a country?](https://dataxapi.com/answers/how-to-get-x-trends-for-a-country/)

---

Catalog revision c48ce454ae6c4c65. [HTML version](https://dataxapi.com/guides/x-search-posts-by-keyword/)
