x-api

Post tweets, threads, and media to X using OAuth 2.0 or OAuth 1.0a API calls.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill x-api-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: x-api
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/x-api
Command: npx skills add https://github.com/Femad-6/my-skills --skill x-api-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires requests, requests-oauthlib.

What problem does it solve? Integrating with the X (Twitter) API requires navigating two authentication schemes, split v1.1/v2 endpoints, and opaque rate limits. This Skill provides ready-to-use Python patterns for posting, reading, searching, and managing X content without re-deriving the API contract each time. ## Core Features & Use Cases - Posting & Threads: Publish single tweets, multi-tweet threads, and tweets with media attachments using v2 endpoints plus the v1.1 media upload endpoint. - Reading & Search: Fetch user timelines, recent search results, user profiles, and followers with field expansions like public_metrics. - Account Actions & Safety: Like, retweet, delete tweets, send direct messages, validate tweet length, and handle rate limits automatically via response headers. - Use Case: Build a content pipeline where generated posts are length-validated, published as a thread, and tracked through public_metrics for engagement analytics. ## Quick Start Set your X API credentials as environment variables and ask the assistant to post a tweet or thread using the X API patterns in this Skill.

Frequently Asked Questions about x-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I post a tweet using the X API in Python?

Post a tweet by sending a POST request to https://api.x.com/2/tweets with a JSON body containing the text field, authenticated via OAuth 1.0a or OAuth 2.0 user context. The response returns the new tweet ID under data.id.

How do I post a thread of multiple tweets on X?

Post each tweet sequentially, passing the previous tweet's ID in the reply.in_reply_to_tweet_id field of each subsequent request. Collect the returned IDs to track the full thread.

Should I use OAuth 2.0 or OAuth 1.0a for the X API?

Use OAuth 2.0 for new projects: a bearer token covers read-only access, and Authorization Code with PKCE covers user-context writes. OAuth 1.0a remains necessary for the v1.1 media upload endpoint and some legacy endpoints.

How do I upload images with a tweet using the X API?

Upload media first to the v1.1 endpoint upload.twitter.com/1.1/media/upload.json to get a media_id_string, then reference that ID in the media.media_ids array when posting via the v2 tweets endpoint.

How do I handle X API rate limits in Python?

Read the x-rate-limit-remaining and x-rate-limit-reset response headers on every call. When remaining hits zero, sleep until the reset timestamp before retrying, which can be wrapped in a decorator for automatic backoff.

Why does my X API request return a 403 or 401 error?

A 401 means authentication failed, so verify your tokens and environment variables. A 403 means the request lacks permission, so check that your app has the required scopes such as tweet.write or dm_write for the endpoint.