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

What X (Twitter) supports here
PublishingYes
SchedulingYes
CommentsYes
Direct messagesYes
MentionsYes
ReviewsNo
AnalyticsYes

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.

platform_data options for X (Twitter)
KeyTypeWhat it does
long_postbooleanRaise the limit from 280 to 25,000 (X Premium accounts).
reply_settingsfollowing | mentionedUsers | subscribers | verifiedWho can reply. Leave out to let everyone reply.
in_reply_to_tweet_idstringPublish as a reply to this post (reply_to means the same).
auto_populate_reply_metadatabooleanWith a reply: add the @mentions of the post replied to.
exclude_reply_user_idsstring[]With a reply: user ids to leave out of those @mentions.
made_with_aibooleanLabels the post as AI-generated.
paid_partnershipbooleanDiscloses branded content.
geo_place_idstringX place id to attach a location.
community_idstringPost into an X Community the account belongs to.
for_super_followers_onlybooleanOnly super followers see it.
nullcastbooleanPromoted-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.

Connection error codes for X (Twitter)
CodeMeaning
byok.credentials_invalidThe workspace's own X app keys were refused by X.
byok.app_access_deniedThe workspace's X app does not have the access this needs (for example no user authentication or no paid tier).
account.already_linkedThe 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_limitNo 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)

Webhook events and their payloads

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.

  1. developer.x.com → Projects & Apps → create an app inside a Project.
  2. User authentication settings: OAuth 2.0, type Web App, permissions Read and write and Direct message.
  3. Add the Callback address below and your website URL, Terms and Privacy URLs.
  4. 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.read
  • tweet.write
  • tweet.moderate.write
  • users.read
  • offline.access
  • media.write
  • dm.read
  • dm.write
  • like.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)

  1. No review: X sells access instead. X bills every read and write to the developer account that owns the app.
  2. 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.

Other platforms

Free to start

Your next post can go everywhere at once.

No card. Connect a profile, send a post, see it land.