How to Connect X (Twitter) API to an AI Agent
Auth setup
1. Apply at developer.x.com. 2. Create project and app. 3. Get Bearer token for app-only access. 4. Use OAuth 2.0 PKCE for user-context actions.
Key facts
| Base URL | https://api.x.com/2/ |
| API version | v2 |
| Auth | OAuth 2.0 with PKCE for user context. OAuth 1.0a also supported. App-only: Bearer token. |
| Token URL | https://api.x.com/2/oauth2/token |
| Scopes | tweet.read tweet.write users.read |
| Request body | application/json |
| Pagination | cursor-based: pagination_token in response. Use next_token for next page. |
| Rate limit | Free: 1,500 tweets read/month, 50 write/month. Basic ($100/mo): 10K read. Pro ($5K/mo): 1M read. |
| Error format | JSON: {"errors":[{"message":"...","type":"..."}]} |
Key endpoints
| Method | Path | Description |
POST | /tweets | Create tweet |
GET | /tweets/search/recent | Search recent tweets |
GET | /users/{id} | Get user by ID |
GET | /users/{id}/tweets | Get user's tweets |
Quickstart
GET /2/tweets/search/recent?query=MCP protocol&max_results=10
Authorization: Bearer {bearer_token}
Agent pitfalls & tips
- Free tier is very limited โ 1,500 tweets/month read.
- OAuth 2.0 PKCE required for posting (user context).
- Use 'tweet.fields' and 'expansions' params to get full data.
- Rate limits are per-endpoint โ check X-Rate-Limit headers.
- API v2 is current โ v1.1 is deprecated but still works for some endpoints.
Source: curated by KanseiLink from official documentation (docs) and registry checks. Last reviewed: 2026-04-07. Specs change โ verify against the official docs before production use.
Frequently Asked Questions
What is X (Twitter) API's AEO score?
โผ
X (Twitter) API has an AEO score of 0.90 and is rated AA (Strong agent support with minor gaps). AEO (Agent Engine Optimization) measures how well a SaaS service works with AI agents. Scores range from 0.00 to 1.00, with grades from AAA (best) to D (not agent-ready).
Is X (Twitter) API AI-agent-ready?
โผ
X (Twitter) API is currently connectable for AI agent use. Third-party MCP integrations are available for this service. For detailed connection guides, auth setup, and known pitfalls, use the KanseiLink MCP tool.
How does X (Twitter) API compare to other Marketing services?
โผ
In the Marketing category, X (Twitter) API is rated AA. KanseiLink evaluates services based on MCP availability, API quality, documentation, auth-guide clarity, and integration recipe availability (methodology published). Visit the full rankings at kansei-link.com to see how X (Twitter) API compares.
How can I integrate X (Twitter) API with an AI agent?
โผ
The fastest way to integrate X (Twitter) API with an AI agent is through KanseiLink MCP. Install it with: npx @kansei-link/mcp-server โ then use the search_services and get_service_detail tools to get the current auth setup, endpoints, rate limits, and agent-specific tips. This data is kept fresh from registry checks, curated official-doc guides, and agent reports.
How do I authenticate with X (Twitter) API?
โผ
OAuth 2.0 with PKCE for user context. OAuth 1.0a also supported. App-only: Bearer token. Setup: 1. Apply at developer.x.com. 2. Create project and app. 3. Get Bearer token for app-only access. 4. Use OAuth 2.0 PKCE for user-context actions.
What are X (Twitter) API's API rate limits?
โผ
Free: 1,500 tweets read/month, 50 write/month. Basic ($100/mo): 10K read. Pro ($5K/mo): 1M read.