# How do I give my AI agent live X (Twitter) search without the official X API?

> Give an agent X search with operators like from: and lang:, an account's latest posts and country trends, paid per call with no X developer account. Costs and code.

Canonical page: https://okdata.online/answers/ai-agent-live-x-search/

**Short answer: **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.006, which is $0.30 per 1,000 posts. An account's latest posts cost $0.006 a page and a country's trends $0.009.

A developer-tools startup ships on Tuesday. They want an agent that checks X every hour, picks out posts worth answering, and drops them in Slack with a one-line reason. The agent needs live search, a way to read what a few key accounts said, and nothing that involves logging bot accounts into X. Three endpoints cover it, and each call is billed on its own, so a quiet hour costs one call.

## The tools to give the agent

- [X post search](/apis/x/posts/search/) runs a query with X's own syntax: `"your product" -from:yourhandle lang:en`, sorted `latest` or `top`. Each call is one page of about 20 posts.
- [X account posts](/apis/x/users/posts/list/) returns an account's posts, newest first, by handle. Useful for "what did these 30 people say this week".
- [X trending topics](/apis/x/trends/list/) returns trends worldwide or for one country (`country=US`, `JP`, ...).

Over the [MCP server](/mcp/) the agent finds and calls these on its own. In a scheduled job it is a short loop:

```python
import json, os, pathlib
import requests

API = "https://api.okdata.online"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
SEEN = pathlib.Path("seen_ids.json")

seen = set(json.loads(SEEN.read_text())) if SEEN.exists() else set()
params = {"query": '"acme cli" -from:acme_dev', "sort": "latest",
          "fields": "id,url,text,published_at,metrics.likes,author.username,author.followers"}
body = requests.get(API + "/v1/x/posts/search", headers=H, params=params, timeout=60).json()
if body["code"] != "ok":
    raise SystemExit(f"{body['code']}: {body['message']}")

new = [p for p in body["data"]["items"] if p["id"] not in seen]
SEEN.write_text(json.dumps(sorted(seen | {p["id"] for p in new})))
print(f"{len(new)} new posts for the agent to triage")  # hand `new` to your model
```

## What it costs

| Job | Calls | Cost |
|---|---|---|
| One search page every hour for 30 days | 720 | $4.32 |
| 1,000 posts from search | 50 | $0.30 |
| Latest posts of 50 accounts, daily for 30 days | 1,500 | $9.00 |
| Trends for 3 countries, daily for 30 days | 90 | $0.81 |

## Gotchas

- Every page is a separate charge. Tell the agent its limit in the tool description ("stop after 3 pages") and enforce it in code.
- Search sees public posts. Protected accounts are invisible, and operators that depend on a logged-in user, such as `filter:follows`, mean nothing here.
- `top` and `latest` return different sets. Monitoring wants `latest`; research on what resonated wants `top`.
- On a burst you may get `rate_limited`; wait the seconds it gives, then retry with the same Idempotency-Key.
- Post text is written by strangers. The agent should treat it as data when it decides what to flag.

## Alternatives

If the agent must also post or reply, use the official X API; it needs a developer account and X bills it directly, but it is the sanctioned way to write. twscrape and similar open-source tools are free and run on X accounts you supply; expect those accounts to be locked from time to time, which is fine for a hobby project and painful for an alert people rely on. More on monitoring mentions across platforms is on the [word-of-mouth page](/solutions/word-of-mouth/).

## Endpoints used

- [X post search](https://okdata.online/apis/x/posts/search/) `x.posts.search`: $0.006 per call · about 20 posts per page
- [X account posts](https://okdata.online/apis/x/users/posts/list/) `x.users.posts.list`: $0.006 per call · about 20 posts per page
- [X trending topics](https://okdata.online/apis/x/trends/list/) `x.trends.list`: $0.009 per call · about 30 board entries per page

Updated 2026-11-12
