X (Twitter) posting API: POST /2/tweets and pricing (2026)
By Natnael Girma · Published
To post to X (Twitter) through the API, you send POST https://api.x.com/2/tweets with a JSON body such as {"text": "Hello"} and a user access token from OAuth 2.0 with the tweet.read, tweet.write and users.read scopes. Images are uploaded first with POST /2/media/upload and attached by ID. As of December 2026, X charges per request on a prepaid credit model: $0.015 per post, or $0.20 if the post contains a URL.
Pricing has changed several times since 2023, so this guide starts there. Everything below comes from docs.x.com as read in December 2026.
X API pricing in December 2026
X launched pay-per-use pricing on February 6, 2026. You buy credits in the Developer Console at console.x.com, and each request deducts from the balance. There is no subscription, contract or minimum spend.
The rates that matter for publishing:
| Action | Price |
|---|---|
| Create a post | $0.015 per request |
| Create a post containing a URL | $0.200 per request |
| Create a post as a summoned reply | $0.010 per request |
| Media metadata | $0.005 per request |
| Read a post | $0.005 per post returned |
| Read a user | $0.010 per user returned |
| Owned Reads (your own posts, mentions, followers, through your own app) | $0.001 per resource |
Other rules from the same page:
- Reads are deduplicated within a UTC day, so fetching the same post twice in one day is charged once.
- Pay-per-use accounts are capped at 3 million post reads per monthly billing cycle. Above that you need Enterprise.
- You can set a spending limit per billing cycle, after which requests are blocked.
- New accounts get $20 in free credits after their first credit purchase and a match of their first auto-recharge up to $50, per the free credits page. These credits expire after 3 months.
- Spend of $200 or more in a billing cycle earns 10% to 20% back in xAI API credits.
The pricing page lists no charge for uploading media itself.
What happened to Free, Basic and Pro?
The X changelog entry for the February 6, 2026 launch says Basic and Pro plans remain available and existing subscribers can opt in to pay-per-use. Recently active Legacy Free users got a one-time $10 voucher, and Public Utility Apps keep free access. We could not confirm current Basic or Pro prices on an official X page, so check the Developer Console before you rely on older figures you see quoted elsewhere.
Two later changes affect posting apps:
- February 23, 2026: Programmatic replies through
POST /2/tweetsare only allowed when the original post's author has "summoned" your account by mentioning it or quoting one of its posts. This applies to self-serve tiers, not Enterprise. - April 20, 2026: Post creation moved to $0.015, posts with a URL to $0.20, and following, likes and quote posts were removed from all self-serve tiers. Quote posting with
quote_tweet_idnow requires Enterprise.
What a month of posting costs
Say a company publishes 3 posts a day, 90 a month, from its own developer app to its own account, and reads its last 20 posts once a day to check engagement. Because the app owner is reading their own posts, those reads qualify for Owned Read pricing:
| Usage | Calculation | Monthly cost |
|---|---|---|
| 90 text posts | 90 × $0.015 | $1.35 |
| 90 posts that each include a link | 90 × $0.20 | $18.00 |
| Reading your last 20 posts daily (Owned Reads) | 30 × 20 × $0.001 | $0.60 |
Links are the expensive part. The same schedule costs about 13 times more when every post carries a URL. If your posts exist to drive clicks, budget for the URL rate. If not, keep links out of most posts.
Step 1: Create an app and turn on OAuth 2.0
- Sign up at console.x.com, create a developer account and describe how you will use the API.
- Create an app. Newly created apps use OAuth 2.0 only. OAuth 1.0a is disabled for new apps and scheduled to be retired on January 31, 2027.
- In the app's authentication settings, enable OAuth 2.0, add your exact callback URL and choose an app type. Web App, Automated App and bot types are confidential clients and get a client secret. Native and single-page apps are public clients.
- Buy credits, because requests are blocked at a zero balance.
Step 2: Get a user token with PKCE
Build the authorize URL with a PKCE code_challenge. Ask for offline.access, or you get no refresh token and the access token dies after two hours:
https://x.com/i/oauth2/authorize
?response_type=code
&client_id=<CLIENT_ID>
&redirect_uri=<REDIRECT_URI>
&scope=tweet.read%20tweet.write%20users.read%20media.write%20offline.access
&state=<STATE>
&code_challenge=<CHALLENGE>
&code_challenge_method=S256
| Scope | Why you need it |
|---|---|
tweet.write |
Create posts |
tweet.read, users.read |
Also required by POST /2/tweets |
media.write |
Upload images and video |
offline.access |
Get a refresh token |
Exchange the code quickly. X's docs say the authorization code expires 30 seconds after the user approves:
curl -X POST https://api.x.com/2/oauth2/token \
-u "$CLIENT_ID:$CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=<CODE>" \
--data-urlencode "redirect_uri=<REDIRECT_URI>" \
--data-urlencode "code_verifier=<VERIFIER>"
Confidential clients authenticate with the Basic header shown here. Public clients send client_id in the body instead. To refresh, call the same endpoint with grant_type=refresh_token and the refresh_token.
Step 3: Publish a post
curl -X POST https://api.x.com/2/tweets \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Shipping the new release today."}'
{
"data": {
"id": "1880028106020515840",
"text": "Shipping the new release today.",
"edit_history_post_ids": ["1880028106020515840"]
}
}
The post lives at https://x.com/{username}/status/{id}. Get the username once from GET /2/users/me.
Useful body fields
From the Create Post reference:
| Field | What it does |
|---|---|
text |
Up to 280 characters unless the account has X Premium. Optional if media is attached. |
media.media_ids |
Up to 4 photos, 1 GIF or 1 video, attached in the order given |
reply.in_reply_to_tweet_id |
Reply to a post (subject to the summoned rule) |
reply_settings |
Who can reply: following, mentionedUsers, subscribers or verified |
poll |
2 to 4 options of 1 to 25 characters, open 5 to 10,080 minutes |
made_with_ai |
Discloses AI-generated media |
paid_partnership |
Discloses a paid partnership |
community_id |
Posts to a Community |
edit_options |
Edits an existing post instead of creating one |
Delete a post with DELETE /2/tweets/{id}. The API has no scheduling field, so a scheduled post means storing it and calling the endpoint at the right time.
Step 4: Attach images
Images under 5 MB (JPG, PNG, GIF or WEBP) go up in one request to POST /2/media/upload with media_category set to tweet_image:
curl -X POST https://api.x.com/2/media/upload \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-F "media=@photo.jpg" \
-F "media_category=tweet_image"
The response contains data.id. Pass up to four of them:
curl -X POST https://api.x.com/2/tweets \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Before and after", "media": {"media_ids": ["1880028106020515840", "1880028106020515841"]}}'
Video
Video uses the chunked upload flow with dedicated paths:
POST /2/media/upload/initializewith a JSON body ofmedia_type,total_bytesandmedia_category: "tweet_video". The response has the mediaid.POST /2/media/upload/{id}/appendfor each chunk, withsegment_indexand the bytes. Keep chunks at or under 5 MB (the server maximum is 8 MB).POST /2/media/upload/{id}/finalize.- If the response includes
processing_info, pollGET /2/media/upload?command=STATUS&media_id={id}untilstateissucceeded, waitingcheck_after_secsbetween checks.
The old command=INIT, APPEND and FINALIZE parameters on /2/media/upload are the previous protocol and should not be used. Video length is limited by the posting account, not your API plan: 20 minutes and 8 GB by default, 125 minutes and 16 GB for X Premium or verified accounts. A video that uploads fine can still be rejected with a 403 when attached to a post from an account below that limit.
Rate limits
From the rate limits page, these sit on top of your credit balance:
| Endpoint | Per user | Per app |
|---|---|---|
POST /2/tweets |
100 per 15 minutes | 10,000 per 24 hours |
DELETE /2/tweets/:id |
50 per 15 minutes | Not listed |
POST /2/media/upload |
500 per 15 minutes | 50,000 per 24 hours |
POST /2/media/upload/initialize, append, finalize |
1,875 per 15 minutes | 180,000 per 24 hours |
Every response carries x-rate-limit-limit, x-rate-limit-remaining and x-rate-limit-reset (a Unix timestamp). Exceeding a limit returns 429 until the window resets.
Common errors
| Error | Cause | Fix |
|---|---|---|
| 401 Unauthorized | Expired access token | Refresh with the stored refresh token |
| 403 on a reply | The author has not summoned your account | Only reply where you were mentioned or quoted |
403 on quote_tweet_id |
Quote posts need Enterprise | Post a link to the post instead |
| 403 on a video post | Video longer than the account may post | Trim it, or post from a Premium account |
| 429 Too Many Requests | Rate limit hit | Wait until x-rate-limit-reset |
| Requests blocked, out of credits | Credit balance at zero or below, or spending limit reached | Add credits or raise the limit; auto-recharge fires at most once per 5 minutes |
| No refresh token returned | offline.access not requested |
Add the scope and have the user sign in again |
| Invalid code at token exchange | Code older than 30 seconds | Exchange it immediately in your callback |
What we ran into building this
Taskwind's X connector runs this flow for every connected account:
- Confidential client, Basic auth. We registered a web app, so both the code exchange and every refresh send
Authorization: Basic base64(client_id:client_secret). The body carries only the grant fields. - Five scopes, no more. We request
tweet.read tweet.write users.read media.write offline.access. Leaving outmedia.writebreaks image posts, and leaving outoffline.accessmeans users reconnect every two hours. - Save the new refresh token every time. Each refresh response includes a refresh token, and we store it over the old one along with the new expiry.
- Single-request uploads for images. We send each image to
/2/media/uploadas multipart withmedia_category=tweet_image, collectdata.idfrom each, and stop at four. The chunked flow is only needed for video, which is why Taskwind does not post X video yet. - Ask for the username once. We call
/2/users/meat connection time and keep the username, so we can build the post link from the ID without another paid read on every publish.
The same post through Taskwind
With Taskwind, you connect an X account with X's official sign-in and post through one REST call. Taskwind runs the X app, so you do not need a developer account or credits of your own. Upload images first:
curl -X POST https://taskwind.ai/v1/media \
-H "Authorization: Bearer $TASKWIND_API_KEY" \
-H "Content-Type: image/png" \
--data-binary @chart.png
Then post, now or at a Unix timestamp:
curl -X POST https://taskwind.ai/v1/posts \
-H "Authorization: Bearer $TASKWIND_API_KEY" \
-H "Content-Type: application/json" \
-d '{"content":"Q4 numbers are in.","account_ids":["acc_..."],"media_ids":["med_..."],"scheduled_at":1798000000}'
The response has a targets array with the status, post link and any error per account, and the same call can include LinkedIn, Threads and Bluesky. See the REST API docs.
On X, Taskwind supports text up to 280 characters and up to 4 images. It does not post video, polls, threads, Community posts or replies, does not send or read X DMs, and has no analytics yet. Plans start at $49/month with a 7-day trial (pricing). For a comparison of posting APIs across networks, see the social media posting API guide.
Questions
Can I post with an app-only Bearer token?
No. The Create Post reference only accepts user-context authentication, either an OAuth 2.0 user token with tweet.read, tweet.write and users.read, or an OAuth 1.0a user token. An app-only Bearer token can read public data but cannot post.
Can I post a thread through the X API?
You build a thread by posting each part as a reply to the previous one with reply.in_reply_to_tweet_id, and each part is billed as a separate post. X's docs do not spell out how the February 2026 summoned-reply rule treats replies to your own posts, so test it on your account before you build on it.