Platforms / X (Twitter)
X (Twitter) API
Post tweets and threads with media, manage the replies to your posts, read mentions and send DMs on X.
At a glance
- Platform id
twitter- Connects
- account
- Sign-in
- OAuth: the user approves on the platform's own page
- Post types
- Text · Thread (up to 25 text-only follow-ups) · Reply · Images (up to 4) · Video · GIF
Capabilities
| Publishing | Yes |
|---|---|
| Scheduling | Yes |
| Comments | Yes |
| Direct messages | Yes |
| Mentions | Yes |
| Reviews | No |
| Analytics | Yes |
Required on every post
- Text or media.
Options
Send these in platform_data.twitter on the post, or flat in a target's own platform_data (the target's keys win). See Publishing.
| Key | Type | What it does |
|---|---|---|
long_post | boolean | Raise the limit from 280 to 25,000 (X Premium accounts). |
reply_settings | following | mentionedUsers | subscribers | verified | Who can reply. Leave out to let everyone reply. |
in_reply_to_tweet_id | string | Publish as a reply to this post (reply_to means the same). |
auto_populate_reply_metadata | boolean | With a reply: add the @mentions of the post replied to. |
exclude_reply_user_ids | string[] | With a reply: user ids to leave out of those @mentions. |
made_with_ai | boolean | Labels the post as AI-generated. |
paid_partnership | boolean | Discloses branded content. |
geo_place_id | string | X place id to attach a location. |
community_id | string | Post into an X Community the account belongs to. |
for_super_followers_only | boolean | Only super followers see it. |
nullcast | boolean | Promoted-only post that does not appear on the timeline. |
Limits
- 280 characters (25,000 with long_post), counted X's way: every link counts 23 and wide characters such as CJK and emoji count 2.
- Up to 4 images, or one video (MP4, up to 512 MB and 140 seconds), or one GIF on its own; never a mix.
- Threads hold up to 25 text-only follow-ups, each within the same limit.
- This server caps each account at 25 posts an hour and 50 a day.
Text over the limit fails validation before anything is sent. The caps of this server are explained in Rate limits.
Good to know
- Thread follow-ups go in the post's top-level segments. If a follow-up fails, the posts already on X stay and the thread stops there; deleting the post removes only the first tweet.
- X has no edit for apps: delete the post and publish a new one.
- Replies are listed from the last 7 days only. Hiding works only in conversations your own post started; deleting works only on your own replies.
- DMs are text only and reach only people who accept DMs from the account. X returns the last 30 days of DMs. X sends no webhooks for replies or DMs: the inbox polls.
- X access tokens last 2 hours and renew on their own. Accounts connected before tweet.moderate.write and like.write were added must reconnect to use them.
- When X's monthly write quota of the app is spent, X answers 402 and the API returns 402 platform.twitter.usage_capped.
Publish with the API
curl https://api.zaynstack.com/v1/posts \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{
"text": "Hello from SocialWire",
"media": [{ "type": "image", "source_type": "url", "source": "https://example.com/file.jpg" }],
"targets": [{ "account_id": "<X (Twitter) account id>" }],
"publish_now": true
}'An operation X (Twitter) cannot do answers 501 resource.not_supported. Agents can do the same through the MCP server.
Connection errors
A connection that fails comes back to your redirect_uri with status=error, error=<code> and error_description, or as the error of the connect call. All codes: Connect accounts.
| Code | Meaning |
|---|---|
byok.credentials_invalid | The workspace's own X app keys were refused by X. |
byok.app_access_denied | The workspace's X app does not have the access this needs (for example no user authentication or no paid tier). |
account.already_linked | The brand already holds a different account on this platform, or the account belongs to another brand while lock_accounts_to_brand is on. |
billing.brands_limit | No brand_id was sent, so a new brand was needed, and the plan has no room for another brand. |
Webhook events
Every platform sends the post.* and account.* events. X (Twitter) also sends:
comment.received(replies, from polling)mention.received(from polling)dm.received(from polling)
Not supported yet
- A separate X app per brand: X app keys are set per workspace.
- Editing posts.
- Media in thread follow-ups.
Developer setup (self-hosting)
Only the operator of this server does this, once. Users then just click Connect.
- developer.x.com → Projects & Apps → create an app inside a Project.
- User authentication settings: OAuth 2.0, type Web App, permissions Read and write and Direct message.
- Add the Callback address below and your website URL, Terms and Privacy URLs.
- Put the OAuth 2.0 client ID and secret into X_CLIENT_ID / X_CLIENT_SECRET, or let each workspace paste its own X app keys in Settings.
- Callback address
https://api.zaynstack.com/api/connect/x/callback- Webhook address
https://api.zaynstack.com/api/hooks/x- Server variables
X_CLIENT_ID, X_CLIENT_SECRET- Developer console
- X (Twitter) developer console
Permissions requested
tweet.readtweet.writetweet.moderate.writeusers.readoffline.accessmedia.writedm.readdm.writelike.write
When a reconnect grants fewer permissions than before, an account.updated event with change permissions_reduced is sent. Accounts connected before a permission was added keep working but must reconnect to use the features it unlocks.
Before anyone can connect (review)
- No review: X sells access instead. X bills every read and write to the developer account that owns the app.
- Reading replies, mentions and DMs needs paid X access; the free X tier only posts. With workspace keys in Settings, usage is billed to that workspace's X account.
Typical wait: None (paid). Until then the app works for your own accounts and the testers you add in the console.