npx skills add ...
npx skills add https://docs.x.com --skill x
Use when building applications that interact with X's public
npx skills add https://docs.x.com --skill x
The X API provides programmatic access to X's public conversation through modern REST endpoints. Use it to search posts, retrieve user data, publish content, manage relationships, access trends, and stream real-time data. The API uses pay-per-usage pricing with no commitments. Key endpoints live at https://api.x.com/2/. Authentication uses OAuth 1.0a (user context), OAuth 2.0 (app-only or user context), or Bearer tokens. Official SDKs exist for Python (xdk) and TypeScript (@xdevplatform/xdk). Primary documentation: https://docs.x.com/x-api/introduction
Reach for this skill when:
| Method | Use case | Scope |
|---|---|---|
| Bearer Token (OAuth 2.0 app-only) | Public data, no user context | App-level rate limits |
| OAuth 1.0a user context | User-specific actions (post, like, follow) | User-level rate limits |
| OAuth 2.0 authorization code | User-facing apps, delegated access | User-level rate limits, scoped permissions |
| Task | Endpoint | Method |
|---|---|---|
| Look up user | /2/users/by/username/{username} | GET |
| Search posts (7 days) | /2/tweets/search/recent | GET |
| Search posts (all history) | /2/tweets/search/all | GET |
| Get post by ID | /2/tweets/{id} | GET |
| Create post | /2/tweets | POST |
| Delete post | /2/tweets/{id} | DELETE |
| Get user's posts | /2/users/{id}/tweets | GET |
| Follow user | /2/users/{id}/following | POST |
| Like post | /2/users/{id}/likes | POST |
| Filtered stream (real-time) | /2/tweets/search/stream | GET |
| Stream rules | /2/tweets/search/stream/rules | GET/POST |
| Parameter | Purpose | Example |
|---|---|---|
tweet.fields | Additional post data | created_at,public_metrics,conversation_id |
user.fields | Additional user data | username,created_at,public_metrics |
expansions | Include related objects | author_id,attachments.media_keys |
max_results | Results per page | 10 to 100 (varies by endpoint) |
pagination_token | Page through results | Base32hex-encoded token from meta.next_token |
query | Search string | from:xdevelopers lang:en |
Check x-rate-limit-remaining before making requests. When you hit a limit (429), wait until x-rate-limit-reset (Unix timestamp).
| Scenario | Use | Endpoint |
|---|---|---|
| Get a specific user's recent posts | Timeline | GET /2/users/{id}/tweets |
| Search across all posts for keywords | Search | GET /2/tweets/search/recent or /all |
| Get posts from 7+ days ago | Full-archive search | GET /2/tweets/search/all |
| Monitor posts in real-time | Filtered stream | GET /2/tweets/search/stream |
| Requirement | Use |
|---|---|
| Legacy integrations, user context | OAuth 1.0a |
| New apps, user context, scoped permissions | OAuth 2.0 authorization code |
| Server-to-server, public data only | OAuth 2.0 app-only (Bearer token) |
| Need | Use |
|---|---|
| Additional fields on the primary object (post, user) | tweet.fields or user.fields |
| Include related objects (author, media, referenced posts) | expansions |
| Both additional fields AND related objects | Combine: expansions=author_id&user.fields=created_at |
from:, lang:, has:media, etc.) to build your query string.GET /2/tweets/search/recent or /all with query, expansions=author_id, and tweet.fields=created_at,public_metrics.data[], author IDs from includes.users[]. Check meta.next_token for pagination.meta.next_token exists and you need more results, repeat step 2 with pagination_token=<next_token>.errors[] array.POST /2/media/upload or chunked upload endpoints. Capture media_id.text (required), media.media_ids (if attaching), reply_settings, etc.POST /2/tweets with Bearer token or OAuth 1.0a user context.data.id from response for future reference (delete, reply, etc.).data.text matches input; confirm no errors in response./2/tweets/search/stream/rules with rule objects (value, optional tag). Max 1,000 rules./2/tweets/search/stream/rules to confirm rules are active./2/tweets/search/stream with tweet.fields and expansions.data (post), matching_rules, and includes.tweet.fields and user.fields to get data you need.expansions=author_id includes the author object, but you still need user.fields=username to get username. Expansions alone return only IDs.pagination_token parameter (not next_token). The token is base32hex-encoded; don't modify it.x-rate-limit-reset header and wait until that Unix timestamp.errors[] array even in successful (200) responses when requesting multiple resources.twitter-text library to count characters correctly (URLs, emoji, etc.). Don't rely on string length.Before submitting work with the X API:
x-rate-limit-remaining in response headers; implement backoff for 429s.data and errors arrays; handle partial failures gracefully.meta.next_token logic and loop termination.from:, lang:, has:media) are correct.media_id from upload step is included in post payload.Comprehensive navigation: https://docs.x.com/llms.txt — Feed this to your AI tool for full page-by-page documentation.
Critical pages:
For additional documentation and navigation, see: https://docs.x.com/llms.txt