Network API

X (Twitter) API for Publishing, Social Listening, and Monetization

Ayrshare's API for X (formerly Twitter) enables developers to publish posts, threads, images, videos, and polls via a single REST endpoint. The integration handles scheduling, direct messages, keyword search, social listening, analytics, and monetization.

Your users link their X accounts through an OAuth flow inside your product on your own X developer app, while Ayrshare manages media uploads, threads, Premium checks, and X's ongoing API changes.

An X post composer publishing to the @brightline account with an image and 'Everyone can reply', beside a 128K impressions chart, a poll with 1,204 votes, and a note that the post was approved by the client and scheduled to 3 brand accounts

One integration, 14+ networks, 30M+ API calls a day.

X
Facebook
Instagram
TikTok
Bluesky
YouTube
LinkedIn
Pinterest
Telegram
Reddit
Threads
Snapchat
Google Business
WhatsApp

>99.99%

API uptime

30M+

API calls per day

14+

Social media networks

AI-Native

Native MCP server for any AI agent

>99.99%

API uptime

30M+

API calls per day

14+

Social media networks

AI-Native

Native MCP server for any AI agent

Before you build

What Do You Need to Use the X (Twitter) API?

X sells API access by the request. You sign up in the X Developer Console, create an app, set its permissions, and buy credits before your first call goes through. There's no review queue, but every post, read, and direct message draws down your balance. Each account you post for also needs its own OAuth token. With Ayrshare, you still bring your own X app and credits, but you skip the OAuth flow, media uploads, and error handling, and you get the parts of X that not all social media APIs can offer: direct messages, keyword search, and video monetization. Read why bring-your-own-app matters in Is Your Social Media API Compliant with X's Developer Policies?

Access

An X Developer Console account, an app with user authentication set up, and OAuth tokens for each account. No app review, but X's developer policies apply.

Video monetization

Eligible publishers tag video for X's Amplify pre-roll ads or sponsorship programs in the publish call itself, with no detour through Media Studio. Read how it works, then ask us to enable it.

Direct messages

Read and send X direct messages for every linked account, with conversation history and auto-responses, through the Messaging API. Your X app just needs the direct message permission.

Listening

Search X for keywords and hashtags with advanced operators, and look up any public account's followers and profile, with keyword search on your own X credits.

Linking an X brand or personal account through your own X app on an OAuth connect screen, next to how it works with Ayrshare: bring your own X app keys, pay X directly per request, use the same endpoints as every network, and let Ayrshare track API changes
Proof at scale

Sponsored X Video for the 2026 FIFA World Cup

A broadcaster needed a reliable partner for the biggest event in the world, the 2026 FIFA World Cup. Ayrshare worked with X so the broadcaster could publish, geo-fence, and sponsor clips through the API, with ad creative matched to each clip instantly, all inside a white-label integration.

250M+ Video views and counting

Sponsored clips published through the API during the tournament, with creative matched to each clip the moment it went live.

15 seconds Down from 15 minutes

Processing time per clip, a massive reduction for live-event workflows on the world's biggest stage.

1,000s Clips posted, no issues

Every clip geo-fenced and sponsored via a white-label integration, without a single publishing issue.

Post and Schedule to X (Twitter) in Your Language

Each sample publishes a post with an image now, then schedules a video for later. Same endpoint, same JSON, in Node.js, Python, PHP, Java, Go, Ruby, C#, or plain cURL. Every request that targets X also carries two headers, X-Twitter-OAuth1-Api-Key and X-Twitter-OAuth1-Api-Secret, with your own X developer app's credentials, as the X BYO keys setup guide explains. Add a Profile-Key header to post for one of your users.

# 1. Publish now: a post with an image and a linkcurl -X POST https://api.ayrshare.com/api/post \  -H "Authorization: Bearer $AYRSHARE_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "post": "Our new analytics dashboard is live. https://example.com/blog/analytics",    "platforms": ["twitter"],    "mediaUrls": ["https://example.com/dashboard.jpg"]  }'
# 2. Schedule for later (ISO 8601, UTC)curl -X POST https://api.ayrshare.com/api/post \  -H "Authorization: Bearer $AYRSHARE_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "post": "Friday product drop.",    "platforms": ["twitter"],    "mediaUrls": ["https://example.com/drop.mp4"],    "scheduleDate": "2026-11-06T17:00:00Z"  }'
The fine print

X (Twitter) API Limits: Post Types, Media, and Characters

X's rules in one place. The full list lives in the X media guidelines and the X publishing options.

Post types

7post types

Text, links with an automatic preview, images, video, animated GIFs, polls, and threads.

Accounts

1X app for every profile

Any X account, linked through OAuth on your own X developer app. One app per Ayrshare account covers every user profile you link.

Images

4images per post

JPG, PNG, GIF, or WEBP, up to 5 MB and 8192 x 8192 px. 1200 x 675 px suits a single image.

Video

512 MBper video

MP4 or MOV, up to 140 seconds, at 60 FPS or less, with an aspect ratio between 1:3 and 3:1. Accounts X has approved for longer uploads, such as Premium accounts, can post video up to 4 hours with longVideo.

Characters

280characters per post

Premium accounts can post up to 25,000 characters, and Ayrshare allows it automatically. Alt text runs to 1,000 characters per image.

Threads

Autothread splitting

Set thread to true and Ayrshare splits text over 280 characters into connected posts, keeping sentences whole.

Polls and reply settings

4reply settings

Attach a poll with a duration and options, and limit who can reply.

Scheduling and limits

300API calls per 5 min per profile

Pass a scheduleDate to publish later. Ayrshare sets no X posting cap of its own, so your X app's rate limits and credits decide volume.

Beyond the basic post

Split long text into a numbered thread

Separate posts with blank lines, or let Ayrshare split long text. threadNumber appends 1/3, 2/3, and 3/3, and each entry in twitterOptions.mediaUrls attaches to one post in order, with null to skip one. More in How to Schedule Twitter Threads with the Twitter API.

Skip the setup

Why Use Ayrshare Instead of the X (Twitter) API Directly?

Your product sends one request with your X app's key and secret in two headers and gets back the X post ID and URL. Ayrshare runs the account linking flow, uploads the media, splits threads, and checks Premium entitlements. When X answers with a 402 for empty credits, a 403 for a missing permission or a duplicate post, or a 429 for a rate limit, you get a clear error back. When X changes the API, the fix ships on our side, not in your sprint.

For a step-by-step walkthrough, read How to Post to Twitter (X) with an API.

See the X Publishing Options
  1. Step 1

    One simple endpoint

    Send one POST request with your post, media URLs, and the user's Profile-Key, plus your X app's key and secret in two headers.

  2. Step 2

    We deal with X

    Account linking, media upload, thread splitting, and Premium checks. Ayrshare doesn't store your keys, apart from an encrypted copy while a linking session is open.

  3. Live

    One link, the whole lifecycle

    Get the X post ID and URL right away. The same account link then powers analytics, replies, direct messages, keyword search, and, for eligible publishers, amplify video monetization. No second integration to build.

After you publish

Beyond Posting: The Rest of the X (Twitter) Lifecycle

Replies, direct messages, history, and analytics run through the same account link and credential headers as posting, and draw on the same X credits.

X post analytics for a thread (128K impressions, 4.6K likes, 918 reposts, 1.2K bookmarks) beside a reply thread with a reply sent through the API, a pre-publish check flagging a 294 of 280 character post, and deleting any post in the thread by id

Analytics

Likes, replies, reposts, bookmarks, and impressions per post, plus non-public metrics for posts under 30 days old. Account analytics include followers and Premium status.

Analytics API

Comments

Read replies to a post, reply, and delete your replies.

Engagement API

Messages

Read and send X direct messages for each linked account, with auto-responses. Your X app needs the direct message permission.

Messaging API

History

Pull an account's past posts with analytics, including posts made outside Ayrshare.

History API

Pre-publish checks

Scheduled X posts are checked for media requirements on submit, so a bad video URL fails early.

Validate docs

Not available on X: reviews and boosted ads. See every network you can reach with the same integration on the supported networks page.

Common questions

FAQs About the X (Twitter) API

Yes, you can post to X (Twitter) through an API. Ayrshare's API for X enables developers to publish posts, threads, images, videos, and polls via a single REST endpoint. The integration handles scheduling, direct messages, keyword search, social listening, analytics, and monetization. Start with the X publishing options.

The X (Twitter) API isn't free. X bills every request from prepaid credits, with no free tier for posting, and the minimum credit purchase is $5. Through Ayrshare you still use your own X app and credits, but Ayrshare's plan covers the linking, media, threads, and the other 14+ networks on the same call. Compare Ayrshare plans.

To get a Twitter API key, sign in to the X Developer Console, create an app in the Production environment, set its permissions to read, write, and direct message, and buy credits. The app's API key and secret are what you send to Ayrshare. The X BYO keys setup guide walks through each screen, including the callback URLs.

To post to X with an API, link the X account once, then send a POST /post request with "platforms": ["twitter"], your post text, any media URLs, and your X app's key and secret in two headers. Add scheduleDate to publish later. The tutorial How to Post to Twitter (X) with an API covers the first request and reading analytics back.

The Twitter API allows posting text, images, video, polls, threads, and quote posts, reading posts and metrics, replying, sending direct messages, and searching posts by keyword. Premium accounts add long posts, approved accounts add long video, and eligible publishers can monetize video through Amplify. Through Ayrshare, all of it runs on your own X app and credits. If a call fails on permissions, see X API 403 access tier and scopes.

The X API costs $0.015 per post on pay-per-use pricing, and $0.20 for a post that contains a link. Reading posts costs $0.005 each, and reading your own account's data costs less. X sets a monthly cap of 3 million post reads before Enterprise. Ayrshare's fee is separate and covers every network, so check Ayrshare's plans alongside your X credit budget.

Your Users Are on X (Twitter). Your Product Can Be Too.

Get an API key, link an X account with your own X app credentials, publish your first post, and turn on the other networks with the same call when you need them.