# Twitter/X data for AI agents

> Give Claude, Cursor or LangChain agents read access to X: an MCP server and toolkits with 61 % fewer tokens, $0.065 to $0.09 per 1,000 calls.

HTML page: https://www.twittrapi.com/use-cases/ai-agents

Solutions · AI agents

Read-only access to public X data for Claude, Cursor, LangChain and LlamaIndex agents: profiles, tweets, replies, search, followers, lists, communities and trends. No X account, no cookies, no developer app. Every tool call is one API call, $0.065 to $0.09 per 1,000.

[Get an API key](https://www.twittrapi.com/start) [All integrations →](https://www.twittrapi.com/docs/integrations)

Hosted MCP server: connect Claude, ChatGPT, Cursor or VS Code by URL, nothing to install. [Setup guide](https://www.twittrapi.com/docs/hosted-mcp)

Setup

## Pick your setup

Every option below is read-only and returns the simple format unless you ask for raw JSON.

No person to sign up? An agent can buy its own key with USDC, USDT or LTC at its own deposit address. [Buy access with crypto](https://www.twittrapi.com/docs/for-agents#buy-access-with-crypto-no-human)

- Hosted MCP server

  Connect by URL, nothing to install: Claude.ai, Claude Desktop and ChatGPT as a custom connector, Claude Code, Cursor and VS Code in their MCP settings. Sign in with your TwittrAPI account; 23 read-only tools.

  [Setup guide](https://www.twittrapi.com/docs/hosted-mcp) [Setup guide](https://www.twittrapi.com/docs/hosted-mcp)
- Local MCP server

  The open-source server on your own machine, for clients that only start local servers. Same 23 tools.

  [Setup guide](https://www.twittrapi.com/docs/integrations#local-mcp-server-stdio) [Setup guide](https://www.twittrapi.com/docs/integrations#local-mcp-server-stdio)
- Agent skill

  Teaches coding agents such as Claude Code, Codex and Cursor the API: auth, the simple format, pagination, errors and keeping spend inside a budget. Works next to the MCP server.

  [Setup guide](https://github.com/twittrapi/twittrapi-skills) [Setup guide](https://github.com/twittrapi/twittrapi-skills)
- LangChain and LlamaIndex

  Python packages with 13 tools each for LangChain, LangGraph and LlamaIndex agents (TwittrAPIToolkit, TwittrAPIToolSpec, sync and async).

  [Setup guide](https://www.twittrapi.com/docs/integrations#langchain-and-llamaindex) [Setup guide](https://www.twittrapi.com/docs/integrations#langchain-and-llamaindex)
- n8n node

  The TwittrAPI community node works as a tool for n8n's AI Agent.

  [Setup guide](https://www.twittrapi.com/docs/no-code#use-it-as-an-ai-agent-tool) [Setup guide](https://www.twittrapi.com/docs/no-code#use-it-as-an-ai-agent-tool)
- SDKs for your own agent

  The Python, Node.js or Go SDK with the simple format, and your own tool schema.

  [Setup guide](https://www.twittrapi.com/docs/integrations#your-own-agent-tool) [Setup guide](https://www.twittrapi.com/docs/integrations#your-own-agent-tool)

Hosted MCP server URL, with /mcp at the end

`https://mcp.twittrapi.com/mcp`

Install the agent skill

`npx skills add twittrapi/twittrapi-skills`

Video: Connect your AI agent: hosted MCP server and agent skill (2 min)

MCP

## Connect by URL, or run it yourself

The same read-only tools run as a hosted server and as the open-source [twittrapi-mcp](https://github.com/twittrapi/twittrapi-mcp) package. Both answer in the simple format; raw JSON is one setting away, for the whole server or per tool call.

- Every tool has a size cap (50,000 characters by default). Longer output is cut with a marker, and the cursor stays above the cut so it is never lost.
- Errors come back as tool errors (402 balance, 429 rate limit, 404 not found), so the model can react.
- Every tool call is one billed API call on the caller's own balance, at the normal price and rate limit.

- Hosted, by URL

  Claude.ai, Claude Desktop and ChatGPT add it as a custom connector; Claude Code, Cursor and VS Code take the URL in their MCP settings. Sign in with OAuth or send your API key in a header.

  [Setup guide](https://www.twittrapi.com/docs/hosted-mcp) [Setup guide](https://www.twittrapi.com/docs/hosted-mcp)
- Local, on your machine

  The open-source server runs with Node.js 20 or newer and your key, for clients that only start local servers.

  [Setup guide](https://www.twittrapi.com/docs/integrations#local-mcp-server-stdio) [Setup guide](https://www.twittrapi.com/docs/integrations#local-mcp-server-stdio)
- Your own server for a team

  Run the open-source server in HTTP mode; every request carries the caller's own key, so one server serves a team without sharing a key.

  [Setup guide](https://www.twittrapi.com/docs/integrations#local-mcp-server-stdio) [Setup guide](https://www.twittrapi.com/docs/integrations#local-mcp-server-stdio)

Frameworks

## LangChain and LlamaIndex

Both packages are built on the official Python SDK, return the simple format and cut each result at 20,000 characters by default. The SDK underneath retries 429 and 5xx with backoff.

Pick only the tools the agent needs (search, one tweet, a user's timeline) to keep its choice simple, and lower the size cap per result. Both work with any chat model that supports tool calling, and both can return raw JSON instead when you need cards, polls, edit history or community notes.

[LangChain and LlamaIndex setup](https://www.twittrapi.com/docs/integrations#langchain-and-llamaindex)

Context window

## Why response size matters for agents

X's raw JSON repeats long keys, IDs and nested wrappers for every tweet. The simple format keeps the content (full text with links expanded, author, counts, media, quoted tweet) in flat fields that are always present.

Measured on real responses: **61 % fewer input tokens** at the median, 52–68 % depending on the endpoint. Same price per call, same parameters, same errors.

- /user/{userId}/tweetsAndReplies

  raw 81.7 KB → simple 24.2 KB23,009 → 7,274 tokens

  −68 %
- /user/{userId}/tweets

  raw 72.2 KB → simple 22.8 KB20,484 → 6,866 tokens

  −66 %
- /tweet/{tweetId}

  raw 38.7 KB → simple 15.0 KB10,601 → 4,669 tokens

  −56 %
- /search

  raw 34.3 KB → simple 14.4 KB9,582 → 4,556 tokens

  −52 %
- /user/{userId}/followers

  raw 9.1 KB → simple 2.8 KB2,272 → 801 tokens

  −65 %

The big number is how many fewer input tokens the simple format needs. One captured response per endpoint, minified, tokens counted with o200k_base. Method and all nine endpoints: [Simple format](https://www.twittrapi.com/docs/simple-format).

Custom tools

## Your own tool in a dozen lines

If you run your own agent loop, the Python, Node.js and Go SDKs return the simple format when you ask for it. Keep only the fields the agent needs and the result shrinks further.

- One function per tool: take the query and an optional cursor, call search, return the next cursor.
- Return only id, author, time, text and likes; the agent rarely needs more, and every field costs tokens.
- Skip tweets marked unavailable (deleted or protected) before they reach the model.

[Example tool in Python, Node.js and Go](https://www.twittrapi.com/docs/integrations#your-own-agent-tool)

In practice

## Example prompts and the calls they turn into

Tool names and arguments as the MCP server defines them. Each page is one call.

- What has @XDevelopers announced recently?

  get_user_tweets({ username: "XDevelopers", count: 20 })

  1 call (2 if it pages back)
- Find English complaints about our checkout from the last 3 days, skip retweets.

  search_tweets({ searchItem: "\"acme checkout\" lang:en within_time:3d -filter:nativeretweets", category: "Latest" })

  1 call per page
- Summarize the replies under this tweet.

  get_tweet({ tweetId: "2019881223666233717" })

  1 call per page of replies
- Which of these 80 accounts are verified and have over 10k followers?

  users_by_ids({ ids: ["…80 IDs…"] })

  1 call (up to 100 profiles)
- What is trending in Japan right now?

  get_trend_locations() → get_trends({ locationId: "23424856" })

  2 calls

Tip for the system prompt: resolve handles to IDs once and reuse them, and stop paging when the answer is complete.

Cost

## What tool calls cost

One tool call is one API call; a paginated tool returns one page per call. Calls that fail with 400, 408, 409 or a 5xx error are refunded, and 429 is not charged. In practice the model's tokens cost more than the data.

### Standard

$0.09 per 1,000 calls

**100,000 calls**

$9.00

**1,000,000 calls**

$90.00

### Volume

$0.075 per 1,000 calls

**100,000 calls**

$7.50

**1,000,000 calls**

$75.00

### Scale

$0.065 per 1,000 calls

**100,000 calls**

$6.50

**1,000,000 calls**

$65.00

Volume: for 30 days after a top-up of $100. Scale: while top-ups of the last 30 days reach $500. New accounts get $0.10 free credit, about 1,100 calls at Standard. [Pricing](https://www.twittrapi.com/pricing)

Rate limits

## Parallel tool calls and rate limits

Agents that run tools in parallel reach a limit quickly. The trial key allows 3 requests per second; after the first top-up you get 30, and higher tiers up to 1,000 per second are booked in the dashboard. A 429 is not charged, and the SDK-based tools retry it. [Rate limits](https://www.twittrapi.com/docs/helpful-infos/rate-limits)

FAQ

## AI agent questions

**Can the agent post tweets or send DMs?**

No. All agent tools are read-only. Posting from your own account exists as separate account actions that need your X session cookie and your own proxy; they are deliberately not wired into the agent tools.

**Do I need an X developer account?**

No. You need a TwittrAPI key, or a RapidAPI key subscribed to the Twitter AIO API; the MCP server, the LangChain toolkit and the LlamaIndex tool spec accept both.

**Which format do the MCP and LangChain tools return?**

The simple format by default: flat camelCase JSON with a fixed schema, about 61 % fewer input tokens than X's raw JSON (median over the endpoints we measured). For raw JSON, pass format "raw" per MCP tool call or set TWITTRAPI_RESPONSE_FORMAT=raw; in LangChain and LlamaIndex use api_response_format="raw".

**How do I stop an agent from burning through my balance?**

Give it a small tool set, set max_chars low, cap the number of pages in the system prompt, and keep the balance small. At zero balance calls return 402 and are not charged.

**Can I host the MCP server for my team?**

You usually do not need to: with the hosted MCP server each person connects with their own account, and usage is billed to each of them. To run your own instance (for example inside a company network), the open-source server has an HTTP mode that uses the caller's key on every request. The integrations docs describe both.

**Does it work with models other than Claude?**

Yes. The LangChain and LlamaIndex tools work with any chat model that supports tool calling, and the MCP server with any MCP client.

Related

## Read next

- [Integrations → SDKs, MCP, LangChain, LlamaIndex, n8n /docs/integrations](https://www.twittrapi.com/docs/integrations)
- [Simple format → Schema, fields and the measurement /docs/simple-format](https://www.twittrapi.com/docs/simple-format)
- [Search reference → Operators and the filters object /docs/reference/search](https://www.twittrapi.com/docs/reference/search)
- [Research datasets → Collect tweets in Python, cost per million /use-cases/research](https://www.twittrapi.com/use-cases/research)
- [No-code workflows → The n8n node as an AI Agent tool /use-cases/no-code](https://www.twittrapi.com/use-cases/no-code)
- [TwittrAPI vs the official X API → When the official API fits better /compare/official-x-api](https://www.twittrapi.com/compare/official-x-api)

## Give your agent X data today

Get a key, connect the MCP server, and ask your first question. New accounts start with $0.10 free credit.

[Get an API key](https://www.twittrapi.com/start) [Connect the MCP server →](https://www.twittrapi.com/docs/hosted-mcp)
