How to Post to X Automatically With the API
Register an app in the X developer portal, authorise the account with OAuth, then send a POST request to the v2 create-post endpoint with your text. Since 6 February 2026 this is reported to be pay-per-use with prepaid credits, so you should price and rate-limit your code before it runs on a schedule.
Quick steps
- Create an X developer app. Register a project and app in the X developer portal, enable user authentication and set a callback URL you control.
- Fund pay-per-use credits. Add prepaid credits and confirm the current per-post pricing on the platform, since plain and URL posts are priced differently.
- Authorise with OAuth. Send the user through the OAuth 2.0 authorisation code flow with PKCE, then store the access and refresh tokens encrypted.
- Send a test post. POST a JSON body with a text field to the create-post endpoint from an account you own and read the full response.
- Queue and schedule. Store posts in a table with a publish time, and run a worker each minute that sends due posts one at a time.
- Handle 429 and duplicate errors. Back off on 429, hash recent text to avoid the 403 duplicate error, and check recent posts before retrying a timed-out request.
- Monitor tokens and balance. Refresh tokens before expiry, flag accounts that need reconnecting, and alert yourself before prepaid credits run out.
What the API actually does for you
The X API v2 lets an app create a post on behalf of a user who has authorised it. You send a JSON body with a text field to the create-post endpoint, and X returns the new post's ID or an error. That is all it does. It does not schedule, queue, retry sensibly, pick times or write anything for you.
So "post automatically" really means two jobs: a thin client that talks to X, and your own system that decides what to post and when. A cron job, a database table of pending posts and a worker are usually enough for the second part. If you only need to queue posts you already wrote, check first whether native scheduling covers you; our guide on how to schedule posts on X explains what the composer already does without any code.
Also keep the 280-character standard limit in mind. X Premium accounts are reported to be able to write longer posts, so confirm on the platform before relying on that. Links, emoji and media are counted in particular ways, covered in our X post character limit guide.
What it costs in 2026
Reported by several third-party sources, and to be confirmed on the X developer portal before you build: since 6 February 2026 the X API v2 is pay-per-use with prepaid credits. Creating a plain post is reported at about $0.015, and a post containing a URL at about $0.20. The old free tier of 500 posts a month is reported to have closed to new developers on that date.
The gap between those two numbers matters more than either one. A link post costs many times more than a text post, so a bot that attaches a URL to every post will spend very differently from one that posts text and puts the link elsewhere. Decide early which of your posts really need a link.
Because credits are prepaid, you can get a hard stop when the balance hits zero. Log every create-post call with its cost class (plain or URL), track the balance in your own dashboard, and alert yourself well before it runs out. A silent failure at the wrong moment looks the same as an outage to your audience.
Set up OAuth and send your first post
Create a project and app in the X developer portal, enable user authentication, and set a callback URL you control. For posting on behalf of users, OAuth 2.0 with the authorisation code flow and PKCE is the usual route. Request the scopes needed to read the user, write posts and keep a refresh token. Check the current scope names in the official docs.
Your app redirects the user to X, they approve, and X sends a code to your callback. You exchange the code for an access token and a refresh token. Store both encrypted, never in plain text or in your repository, and never ask for the user's password. Access tokens are short-lived, so your worker must refresh them before they expire.
Then send the request: a POST to the create-post endpoint with a bearer access token and a JSON body such as {"text": "Hello"}. Test it on an account you own first, and read the response body, not just the status code. Errors from X contain a title and detail that tell you what went wrong.
Rate limits, 429s and duplicate rejects
The create-post limits are reported at about 100 posts per 15 minutes per user and 10,000 per 24 hours per app. Confirm the current numbers on the platform. For a single brand account you will rarely get near them. A multi-account tool can, particularly if a bug causes a retry loop.
An HTTP 429 means you are rate limited. Do not retry immediately. Read the reset information in the response headers, wait until then, and use exponential backoff with a cap. Put a queue between your scheduler and the API so a burst of due posts is spread out rather than fired together.
X also rejects duplicate text with a 403 error. This catches people who retry a post that actually went through, or who re-post the same line on a schedule. Keep a hash of recent post text per account and check it before sending. If a request times out, look up the account's recent posts before retrying so you do not double-post or trip the duplicate error.
Handle token failures and bad inputs
When posts that worked yesterday start returning 401 or 403 after a change, the usual cause is a revoked or expired access token. Users can remove your app from their X settings at any time. Treat this as a normal state: mark the account as disconnected, stop its queue, and prompt the owner to reconnect through OAuth.
A 403 can also be the duplicate error described above, so read the error detail before assuming the token is dead. Build a small mapping from error type to action: refresh the token, back off, skip the post, or alert a human. Failed posts should never silently vanish from your queue.
Validate input before you call X. Count characters the way X does, since links are normalised and emoji can count as more than one. If you write long threads, our free thread splitter shows where to break text. If you attach media, upload it first and reference it in the post, as described in how to add images to scheduled X posts.
Designing the scheduler around the API
A reliable setup has four parts. A table holds posts with account, text, status and publish time. A worker wakes every minute and selects due posts. A sender calls X and records the returned post ID. A reconciler marks posts failed after a set number of attempts and surfaces them for a human.
Use a lock or an atomic status change from pending to sending so two workers never grab the same post. Store times in UTC and convert to the user's timezone only in the interface. Daylight-saving shifts are a classic cause of posts landing an hour off.
For timing, you can start from the general pattern in our best time to post on X guide and then replace it with your own engagement data once you have some. Whatever you pick, keep the schedule configurable rather than hard-coded.
When to buy a tool instead of building
Building makes sense when posting is a feature of your own product, when you need custom logic, or when you want full control of data. It stops making sense when you are building the same queue, token refresh and error handling that every scheduler already has, just to publish a few posts a day.
Count the hidden work: OAuth maintenance, reconnect flows, monitoring, the pay-per-use balance, API changes and support when a post fails at 8 a.m. If the real goal is a steady presence on X rather than owning the infrastructure, a tool is usually the cheaper use of your time.
If you write your own posts and only need them queued, use X's native scheduler or a general scheduling tool. Our overview of how to auto post on X (Twitter) compares the routes. A tool that writes the posts for you is a different category, which is the next section.
Where AutoPostMode fits, and where it does not
AutoPostMode is not a scheduler for posts you write from scratch, and it has no bulk CSV upload or calendar for your own drafts. It is an AI content autopilot for X and LinkedIn. It researches articles from the last 24 hours in up to five niches you choose, writes a separate post per network in your tone, and an AI judge scores each draft out of 20 with a pass mark of 14. Every number in a post must appear in the source article.
It then makes an image card, PDF carousel or short video and publishes at your times. It starts in Approve mode, where you approve, edit or skip every post, and you can switch an account to Auto at any point. It connects through official X sign-in (OAuth), never sees your password, and encrypts tokens at rest.
Its credits mirror the API's cost shape: a normal X post uses 1 credit and a post containing a link uses 12. Credits are used only when X confirms the post is live, so failed, skipped or rejected posts are free. Basic is $29/month with 300 credits and no link posts, Pro is $59/month with 525 credits and 15 link posts a month, and Agency is $99/month with 940 credits. There is a 3-day free trial on one X account with a card required.
Questions
Is the X API free for posting in 2026?
Not for new developers, according to consistent third-party reports. The old free tier of 500 posts a month is reported to have closed to new developers on 6 February 2026, with the API moving to pay-per-use prepaid credits. Pricing and access can change, so confirm the current terms in the X developer portal before you build.
How much does it cost to post to X with the API?
Reported figures are about $0.015 for a plain post and about $0.20 for a post containing a URL. These come from third-party sources, so check the developer portal for current pricing. Because links cost far more, decide which posts truly need a URL before automating at volume.
Why does X return a 403 when I post?
Most often it is a duplicate: X rejects text identical to a recent post. A 403 or 401 after earlier success can also mean the access token was revoked or expired, so the account must be reconnected. Read the error detail in the response body to tell which case you have.
What should I do when I get HTTP 429?
It means you are rate limited. Stop sending, wait until the reset time given in the response headers, then resume with exponential backoff. Reported create-post limits are about 100 per 15 minutes per user and 10,000 per 24 hours per app; confirm current numbers on the platform.
Can AutoPostMode post my own pre-written posts?
No. AutoPostMode is an autopilot that researches fresh articles, writes posts in your tone and publishes them, not a scheduler for posts you write yourself. You can edit any draft and run it in Approve mode, but for queuing your own text, use X's native scheduler or a general scheduling tool.
Facts and prices checked 30 November 2026. Platform rules and vendor plans change, so confirm on the platform or vendor site before you rely on a limit or price.
Disclosure: AutoPostMode is our product. More guides: How often to post on X and LinkedIn, Best Time to Post on X: How to Find Yours, How to Schedule Twitter (X) Posts: Native, Free and Automated, How to Add Images to Scheduled X Posts, How to Auto Post on X (Twitter): Three Safe Ways. All how-to guides.