Everything an AI agent can do with the X (Twitter) API.

A reference guide for building AI agents: every method, how to authenticate, and the permissions each one needs.

Endpoints34
API versionv2
Last updated23 June 2026
Orientation

How the X (Twitter) API works.

The X (Twitter) API is how an app or AI agent works with an X account: creating and looking up posts, searching the public conversation, following accounts, and sending direct messages. Access is granted through a token, where an OAuth 2.0 token carries granular scopes that set what each call can read or write, and an agent is limited to those scopes and to what its access tier allows. Which endpoints and volumes are reachable depends on that tier, and X can push account events to a webhook on its highest tier.

34Endpoints
11Capability groups
19Read
15Write
14Permissions
Authentication
The X API v2 supports three ways to authenticate. OAuth 2.0 Authorization Code with PKCE acts on behalf of an account with granular scopes and is the recommended route for agents; an app-only Bearer Token authenticates the app itself and reaches only public data; OAuth 1.0a user context is the older per-app model that some endpoints still require. Adding offline.access to an OAuth 2.0 token returns a refresh token so access lasts until the account revokes it.
Permissions
OAuth 2.0 access is scoped per token. Read scopes include tweet.read, users.read, follows.read, like.read, list.read, space.read, dm.read, and bookmark.read; write scopes include tweet.write (covering posting and reposting), follows.write, like.write, list.write, dm.write, bookmark.write, mute.write, and block.write. users.email returns an account's email address. A token carries only the scopes it was granted, and a call missing the right scope returns 403.
Access tiers
Which endpoints and volumes an account can reach depends on its access level, not just its scopes. Since 6 February 2026 new developers default to pay-per-use, billed per request, with no free tier and post reads capped at 2 million per month. Legacy Basic and Pro plans remain for existing subscribers, and enterprise access, which alone unlocks the full archive at scale and the Account Activity webhooks, runs into the tens of thousands of dollars per month.
Data model
The API is resource-oriented JSON at https://api.x.com/2. Posts live under /2/tweets, accounts under /2/users, and actions an account takes on its own behalf, like following, liking, reposting, and bookmarking, are nested under that account at /2/users/:id. Lists, direct message conversations, and Spaces have their own paths. The current version is 2; the older version 1.1 is being retired.
Connect & authenticate

Connection & authentication methods.

How an app or AI agent connects to X determines what it can reach. There is a route for acting on behalf of a person, a route for reading public data without a person, and a hosted server that exposes X tools to agents, and each is governed by the token behind it and the scopes that token carries.

Ways to connect

REST API (v2)

The version 2 REST API answers at https://api.x.com/2. A call authenticates with an OAuth 2.0 user token, an OAuth 1.0a user token, or an app-only Bearer Token, and returns JSON. It is the current API; the older version 1.1 and legacy hosts are being retired.

Best forConnecting an app or AI agent to X.
Governed byThe token and the scopes it carries.
Docs ↗

MCP server (Model Context Protocol)

X publishes a first-party Model Context Protocol server, xmcp, that turns the X API OpenAPI spec into callable tools for an AI agent, covering posts, users, direct messages, lists, trends, and more, while leaving out streaming and webhook endpoints. It runs locally as a Python application and authenticates with a Bearer Token plus optional OAuth 1.0a or OAuth 2.0 user tokens. It is in developer preview, with no tagged release, at github.com/xdevplatform/xmcp.

Best forConnecting an AI agent to X through MCP.
Governed byThe token and the scopes it carries.
Docs ↗

Account Activity API (webhooks)

The Account Activity API delivers events to a registered webhook URL when something happens on a subscribed account, such as a post being created or deleted, a direct message arriving, or a follow. It is part of the enterprise tier rather than the standard endpoints.

Best forReceiving X account events at an app or AI agent.
Governed byThe subscription and the enterprise access behind it.
Docs ↗
Authentication

OAuth 2.0 Authorization Code with PKCE

OAuth 2.0 with PKCE lets an app act on behalf of an account with granular scopes chosen per token, such as tweet.write, follows.write, like.write, or dm.write. It is the only supported OAuth 2.0 grant, and adding offline.access returns a refresh token so access persists until the account revokes it. This is the route for least-privilege agent access.

TokenOAuth 2.0 user access token
Best forGranular, per-scope access on behalf of an account
Docs ↗

App-only (OAuth 2.0 Bearer Token)

An app-only Bearer Token authenticates the app itself, with no user attached, and reaches only publicly available data. It cannot post, message, or read private data, and it suits read-only work like looking up public posts, users, and search.

TokenApp-only Bearer Token
Best forRead-only access to public data
Docs ↗

OAuth 1.0a User Context

OAuth 1.0a user context lets an app act on behalf of an account and access private data or take actions for it. It predates the scope model, granting access by the app's overall read, write, and direct-message permission level rather than per-token scopes, and some endpoints still rely on it.

TokenOAuth 1.0a access token and secret
Best forEndpoints that still require OAuth 1.0a
Docs ↗
Capability map

What an AI agent can do in X (Twitter).

The X API is split into areas an agent can act on, like posts, search, users, follows, likes, reposts, bookmarks, lists, and direct messages. Each area has its own methods and its own scope, and which areas an account can reach at all depends on its access tier.

Posts

4 endpoints

Look up posts by ID, create a post, and delete a post on behalf of the authenticated account.

Writes here publish or remove real posts visible to the public.
View endpoints

Search

2 endpoints

Search recent posts from the last seven days, and search the full archive back to 2006.

Reads here can return any public post matching a query.
View endpoints

Timelines

2 endpoints

Read the posts authored by a user and the posts that mention a user.

Reads here return a user's posts and mentions.
View endpoints

Users

4 endpoints

Look up an account by ID or username, look up many at once, and read the authenticated account.

Reads here return profile data for accounts an agent can see.
View endpoints

Follows

4 endpoints

List who an account follows and who follows it, and follow or unfollow an account.

Writes here change who the authenticated account follows.
View endpoints

Likes

3 endpoints

List the posts an account has liked, and like or unlike a post.

Writes here add or remove likes from the authenticated account.
View endpoints

Reposts

3 endpoints

List the accounts that reposted a post, and repost or undo a repost.

Writes here repost or unrepost on behalf of the authenticated account.
View endpoints

Bookmarks

3 endpoints

List the authenticated account's bookmarks, and add or remove a bookmark.

Writes here change the authenticated account's bookmarks.
View endpoints

Lists

4 endpoints

Create a list, look one up, and add or remove a member from a list.

Writes here change real list data and membership.
View endpoints

Direct Messages

3 endpoints

Read direct message events, and send a message into a conversation or to a participant.

Writes here send private messages from the authenticated account.
View endpoints

Spaces

2 endpoints

Look up a live audio Space by ID, and search for Spaces by keyword.

Reads here return data about live and scheduled Spaces.
View endpoints
Endpoint reference

Every X (Twitter) API method.

Filter by method, access, or permission, or search any path. Select a row for version detail, rate limits, the related webhook event, and the source.

MethodEndpointWhat it doesAccessPermissionVersion

Posts

Look up posts by ID, create a post, and delete a post on behalf of the authenticated account.4

App-only Bearer Token also works for public posts. The OAuth 1.0a user-context route needs no scope token.

Acts onpost
Permission (capability)tweet.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

App-only access allows 3,500 requests per 15 minutes; user access allows 5,000.

Acts onpost
Permission (capability)tweet.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limit3,500 per 15 min (app) | 5,000 per 15 min (user)

Also needs tweet.read and users.read on the token. Each created post is billed under the pay-per-use model. Programmatic replies are restricted to self-serve tiers since 23 Feb 2026.

Acts onpost
Permission (capability)tweet.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limit100 per 15 min (user) | 10,000 per 24 hr (app)

Also needs tweet.read and users.read on the token. Irreversible.

Acts onpost
Permission (capability)tweet.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply
Search recent posts from the last seven days, and search the full archive back to 2006.2

App-only Bearer Token also works. The 4 May 2026 search index added min_likes, min_replies, and min_reposts operators.

Acts onpost
Permission (capability)tweet.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limit450 per 15 min (app) | 300 per 15 min (user)

Full-archive search is reachable only on higher access tiers, not on a new pay-per-use account by default. App-only access is limited to 1 request per second.

Acts onpost
Permission (capability)tweet.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limit1 per sec, 300 per 15 min (app)

Timelines

Read the posts authored by a user and the posts that mention a user.2

App-only Bearer Token also works for public posts. Reading the authenticated account's own posts is billed as an owned read.

Acts onpost
Permission (capability)tweet.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

App-only Bearer Token also works.

Acts onpost
Permission (capability)tweet.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Users

Look up an account by ID or username, look up many at once, and read the authenticated account.4

App-only Bearer Token also works. User-lookup endpoints allow 300 requests per 15 minutes app-only and 900 with user access.

Acts onuser
Permission (capability)users.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limit300 per 15 min (app) | 900 per 15 min (user)

App-only Bearer Token also works.

Acts onuser
Permission (capability)users.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

App-only Bearer Token also works.

Acts onuser
Permission (capability)users.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

User context only; not callable with an app-only Bearer Token. Adding the users.email scope returns the account's email address.

Acts onuser
Permission (capability)users.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Follows

List who an account follows and who follows it, and follow or unfollow an account.4

tweet.read and users.read are also accepted on the token.

Acts onuser
Permission (capability)follows.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

tweet.read and users.read are also accepted on the token.

Acts onuser
Permission (capability)follows.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token. The :id must be the authenticated account.

Acts onuser
Permission (capability)follows.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token. The source must be the authenticated account.

Acts onuser
Permission (capability)follows.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Likes

List the posts an account has liked, and like or unlike a post.3

tweet.read and users.read are also accepted on the token.

Acts onpost
Permission (capability)like.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token.

Acts onpost
Permission (capability)like.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token.

Acts onpost
Permission (capability)like.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Reposts

List the accounts that reposted a post, and repost or undo a repost.3

Reposting is covered by tweet.write; the token also needs tweet.read and users.read.

Acts onpost
Permission (capability)tweet.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Covered by tweet.write; the token also needs tweet.read and users.read.

Acts onpost
Permission (capability)tweet.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

App-only Bearer Token also works. users.read is also accepted.

Acts onuser
Permission (capability)tweet.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Bookmarks

List the authenticated account's bookmarks, and add or remove a bookmark.3

User context only. tweet.read and users.read are also needed. Bookmarks are an owned read in pay-per-use billing.

Acts onpost
Permission (capability)bookmark.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token.

Acts onpost
Permission (capability)bookmark.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token.

Acts onpost
Permission (capability)bookmark.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Lists

Create a list, look one up, and add or remove a member from a list.4

Also needs tweet.read and users.read on the token.

Acts onlist
Permission (capability)list.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

App-only Bearer Token also works for public lists. tweet.read and users.read are also accepted.

Acts onlist
Permission (capability)list.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token.

Acts onlist
Permission (capability)list.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token.

Acts onlist
Permission (capability)list.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Direct Messages

Read direct message events, and send a message into a conversation or to a participant.3

User context only. tweet.read and users.read are also needed. Limited to 15 requests per 15 minutes.

Acts ondirect message
Permission (capability)dm.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limit15 per 15 min (user)

Also needs tweet.read and users.read on the token.

Acts ondirect message
Permission (capability)dm.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Also needs tweet.read and users.read on the token.

Acts ondirect message
Permission (capability)dm.write
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Spaces

Look up a live audio Space by ID, and search for Spaces by keyword.2

App-only Bearer Token also works. tweet.read and users.read are also accepted.

Acts onspace
Permission (capability)space.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

App-only Bearer Token also works.

Acts onspace
Permission (capability)space.read
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply
No endpoints match those filters.
Webhooks

Webhook events.

X can notify an app or AI agent when something happens on an account, like a post being created or a direct message arriving, through the Account Activity API. That subscription model is part of the enterprise tier rather than the standard endpoints.

EventWhat it signalsTriggered by
No events match that search.
Rate limits & pagination

Rate limits, pagination & request size.

X limits how fast an app or AI agent can call, through per-endpoint windows that reset every 15 minutes or every 24 hours, counted separately for app-only and user-authenticated calls. A separate usage cap, billed per request, sits on top of the rate limits.

Request rate

X meters each endpoint with its own window, counted separately for app-only and user-authenticated calls. Most windows reset every 15 minutes, with some daily caps that reset every 24 hours. Post lookup by IDs allows 3,500 requests per 15 minutes app-only and 5,000 with user access; recent search allows 450 app-only and 300 with user access; user lookup allows 300 app-only and 900 with user access; creating posts is held to 100 per 15 minutes per user and 10,000 per 24 hours per app; full-archive search is capped to 1 request per second; reading direct message events is limited to 15 per 15 minutes. Exceeding a window returns HTTP 429 with x-rate-limit-limit, x-rate-limit-remaining, and x-rate-limit-reset headers. Rate limits are separate from billing: under the pay-per-use model a usage cap and per-request charges apply on top, with reads capped at 2 million posts per month before an enterprise plan is required.

Pagination

List endpoints page with a cursor. A max_results parameter sets the page size within each endpoint's allowed range, and a next_token returned in the response meta is passed back as pagination_token to fetch the following page. Paging stops when no next_token is returned. Full-archive and recent search also support a since_id and until_id, and a start_time and end_time, to bound a query by post.

Request size

Results are JSON. A standard post is up to 280 characters, with longer posts available to premium accounts. Search and lookup endpoints cap how many posts or users come back per page through max_results, and the full archive reaches back to X's first posts in 2006. Pay-per-use post reads are capped at 2 million per month.

Errors

Status codes & error handling.

The status codes an agent should handle, and what to do about each.

StatusCodeMeaningWhat to do
400Bad RequestThe request was malformed: invalid JSON, a malformed search query, or a missing required parameter. The body carries an errors array, and a 400 can hold more than one error object.Read the errors array, correct the named parameter or query, and resend. The request is not retryable as-is.
401UnauthorizedAuthentication credentials are missing or invalid. The problem-details body shows type, title 'Unauthorized', detail, and status.Check the token and the Authorization header, refresh an expired OAuth 2.0 token, and send valid credentials.
403ForbiddenAuthentication succeeded but the token lacks permission for this resource or action, for example a missing scope, an action the account is not allowed to take, or an endpoint above the current access tier.Grant the missing scope on the token, or move to an access tier that includes the endpoint.
404Not FoundThe resource does not exist or has been deleted, such as a post, user, or list that is gone or not visible to the token.Confirm the ID is correct and the token can see the resource.
429Too Many RequestsA rate-limit window was exhausted or a usage cap was hit. The x-rate-limit-limit, x-rate-limit-remaining, and x-rate-limit-reset headers report the state, where reset is a Unix timestamp for the next window.Wait until the x-rate-limit-reset time, then retry, and back off exponentially on repeated limits.
500Internal Server ErrorAn error on X's side, which can also appear as 502, 503, or 504.Wait and retry with exponential backoff, and check the X API status page if it persists.
Versioning & freshness

Version history.

X runs a single current version of its API, version 2, and ships dated changes through its changelog rather than minting new version numbers. Older hosts and the version 1.1 API are being retired in favor of it.

Version history

What changed, and when

Latest versionv2
v2Current version
X API version 2 (current)

Version 2 is the current X API. Rather than minting new version numbers, X ships dated changes through its changelog, so an integration builds against one live version and tracks the changelog for additions and deprecations. The older version 1.1 and legacy hosts are being retired in favor of it. The entries below are recent dated changes within version 2.

What changed
  • 11 Jun 2026: Articles draft and publish endpoints launched.
  • 4 Jun 2026: Post create and delete events added to the Account Activity API.
  • 3 Jun 2026: paid_partnership field support introduced for marking posts as paid promotions.
2026-05-04Feature update
Search migrated to a new index

Search endpoints moved to a new index with performance improvements and three new precision operators for filtering by engagement.

What changed
  • Added min_likes, min_replies, and min_reposts operators to recent and full-archive search.
2026-04-16Feature update
Pricing restructured

Per-request pricing under the pay-per-use model was updated, lowering owned reads and setting per-post creation costs.

What changed
  • Owned reads set to $0.001 per resource.
  • Post creation set to $0.015, or $0.20 for a post containing a link.
2026-03-11Requires migration
Legacy DM events folded into Account Activity

The legacy direct message events were consolidated into the Account Activity API, and event type naming moved to a dot-separated lowercase format.

What changed
  • dm.received, dm.sent, dm.read, and dm.indicate_typing integrated into the Account Activity API.
  • Event type naming changed from PascalCase to dot-separated lowercase.
2026-02-06Requires migration
Pay-per-use pricing launched

X replaced its tiered pricing model with pay-per-use as the default for new developers, removing the free tier for new sign-ups. Legacy Basic and Pro plans remain for existing subscribers, and enterprise access continues separately.

What changed
  • Pay-per-use billing launched as the default for new developers, with no free tier.
  • Post reads capped at 2 million per month before enterprise is required.
  • Programmatic replies later restricted to self-serve tiers on 23 Feb 2026.

There is one live version to build against, and changes arrive as dated changelog entries.

X API changelog ↗
Questions

X (Twitter) API, answered.

Is there still a free tier for the X API?+
Not for new developers. Since 6 February 2026, new sign-ups default to pay-per-use, where credits are bought up front and each call is charged, with post reads capped at 2 million per month. The earlier free tier was closed to new developers, and existing free-tier users were moved to pay-per-use with a one-time credit. Legacy Basic and Pro plans remain only for accounts that already subscribed.
Which authentication method should an agent use?+
For acting on behalf of an account, OAuth 2.0 Authorization Code with PKCE is the route, because it grants only the scopes the token was given, such as tweet.write or dm.write, and offline.access keeps the connection alive with a refresh token. For read-only work on public data, an app-only Bearer Token is simpler and needs no user. OAuth 1.0a user context still backs a handful of endpoints that predate the scope model.
What scope does posting need?+
Creating a post needs tweet.write, and the token must also carry tweet.read and users.read. Reposting is covered by the same tweet.write scope. Deleting a post the account owns also uses tweet.write. Beyond scopes, posting is billed per call under pay-per-use, and programmatic replies have been restricted to self-serve tiers since 23 February 2026.
How do the rate limits work?+
Each endpoint has its own window, counted separately for app-only and user calls, and most reset every 15 minutes with some daily caps. For example, recent search allows 450 requests per 15 minutes app-only and 300 with user access, and creating posts is held to 100 per 15 minutes per user. Exceeding a window returns HTTP 429, and the x-rate-limit-reset header gives the Unix time when the window reopens. Rate limits are separate from the per-request billing on top.
Can an agent receive events instead of polling?+
Yes, through the Account Activity API, which posts events to a registered webhook URL when something happens on a subscribed account, such as a post being created or deleted, a direct message arriving, or a follow. It is part of the enterprise tier rather than the standard endpoints, so it is not available on a pay-per-use or Basic account.
Does X have an official MCP server for AI agents?+
Yes. X publishes a first-party Model Context Protocol server, xmcp, that turns the X API OpenAPI spec into callable tools covering posts, users, direct messages, lists, trends, and more, while leaving out streaming and webhooks. It runs locally as a Python application and authenticates with a Bearer Token plus optional OAuth 1.0a or OAuth 2.0 user tokens. It is in developer preview, with no tagged release, at github.com/xdevplatform/xmcp.
How does pagination work?+
List endpoints use cursor pagination. A max_results parameter sets the page size within each endpoint's range, and the response meta carries a next_token that is passed back as pagination_token to fetch the next page, stopping when no token is returned. Search endpoints also accept since_id, until_id, start_time, and end_time to bound a query.
Related

More social API guides for agents

What is Bollard AI?

Control what every AI agent can do in X.

Bollard AI sits between a team's AI agents and X. Grant each agent exactly the access it needs, read or write, area by area, and every call is checked and logged.

  • Set read, write, or full access per agent, never a shared X key.
  • Denied by default, so an agent reaches only what has been explicitly allowed.
  • Every call recorded in plain English: who, what, where, and the decision.
X (Twitter)
Social Agent
Read mentions ResourceOffReadFull use
Post and repost ActionOffReadFull use
Send direct messages ActionOffReadFull use
Per-agent access, set in Bollard AI, not in X