Skip to content
cheapxapi

Twitter API v2, explained.

X API v2 is the current version of X’s developer API, the one formerly called the Twitter API. Requests go to https://api.x.com/2/ with a token from an approved developer app. Reads are billed per resource returned: $0.005 per post and $0.010 per user. X lists v1.1 as legacy.

A post comes back with only id, text and edit_history_tweet_ids unless you ask for more. Add tweet.fields, expansions and user.fields to get dates, metrics and the author.

A v2 request, piece by piece.

Every v2 call is a path under /2/ and an Authorization: Bearer header. Asked for post 20 with no parameters, v2 returns its ID, its text and its edit history, and nothing else.

  • tweet.fields adds fields to the post, such as created_at and public_metrics (counts such as likes and reposts). You can’t ask for part of a field: requesting public_metrics returns all of its counts.
  • expansions=author_id puts the author’s user object in includes.users. The post in data carries only author_id, so your code joins the two.
  • user.fields chooses what that user object carries. Without it, an expanded user has only its ID, name and username.
  • Lists of results page with meta.next_token, which you send back as pagination_token.

On cheapxapi, the same post comes back whole: text, counts, dates and the author’s profile in one object. There are no fields to list and no includes to join.

Official X API, built from X’s fields and expansions docs (not run by us)

curl "https://api.x.com/2/tweets/20" \
  -H "Authorization: Bearer $BEARER_TOKEN"

cheapxapi request

curl "https://api.cheapxapi.com/twitter/tweets?tweet_ids=20" \
  -H "x-api-key: $CHEAPXAPI_KEY"

Response, captured from the live API

{
  "tweets": [
    {
      "type": "tweet",
      "id": "20",
      "url": "https://x.com/jack/status/20",
      "text": "just setting up my twttr",
      "retweetCount": 126282,
      "replyCount": 19260,
      "likeCount": 324577,
      "quoteCount": 8060,
      "createdAt": "Tue Mar 21 20:50:14 +0000 2006",
      "lang": "en",
      "bookmarkCount": 25528,
      "conversationId": "20",
      "author": {
        "type": "user",
        "userName": "jack",
        "id": "12",
        "name": "jack",
        "isBlueVerified": true,
        "description": "no state is the best state",
        "followers": 12439535,
        "following": 3,
        "createdAt": "Tue Mar 21 20:50:14 +0000 2006"
      }
    }
  ],
  "status": "success",
  "msg": "success",
  "code": 0
}

Trimmed to the main fields of the post and its author.

The v2 endpoint map.

The read endpoints most projects start with, what X charges for each at list price, and the cheapxapi endpoint for the same job. Recent search covers the last 7 days, up to 100 posts a request. Full-archive search goes back to 2006, up to 500 posts a request. Each endpoint also has its own rate limit; see X API rate limits.

Swipe the table to see the cheapxapi column.

X API v2 read endpoints, their official list price and the matching cheapxapi endpoint
Jobv2 endpointX chargescheapxapi, $0.0006 a request
Posts by IDGET /2/tweets/:idGET /2/tweets?ids=$0.005 per postGet tweet by ID
Search the last 7 daysGET /2/tweets/search/recent$0.005 per postAdvanced search
Search the full archiveGET /2/tweets/search/all$0.005 per postAdvanced search
Count matching postsGET /2/tweets/counts/recentGET /2/tweets/counts/all$0.005 / $0.010 per requestNo equivalent
A user’s postsGET /2/users/:id/tweets$0.005 per post, $0.001 on your own accountGet user’s latest tweetsGet user’s tweet timeline
Mentions of a userGET /2/users/:id/mentions$0.005 per post, $0.001 on your own accountGet user mentions
User profilesGET /2/users/by/username/:usernameGET /2/users?ids=$0.010 per userGet user profileGet users by IDs
Followers and followingGET /2/users/:id/followersGET /2/users/:id/following$0.010 per user, $0.001 on your own accountGet followersGet followings
Quotes of a postGET /2/tweets/:id/quote_tweets$0.005 per postGet quote tweets
Who reposted a postGET /2/tweets/:id/retweeted_by$0.010 per userGet retweeters
A list and its postsGET /2/lists/:idGET /2/lists/:id/tweetsGET /2/lists/:id/members$0.005 per list, $0.005 per post, $0.010 per memberGet list tweetsGet list members
CommunitiesGET /2/communities/:id$0.005 per communityGet community
Trends for a locationGET /2/trends/by/woeid/:id$0.010 per requestGet trends
SpacesGET /2/spaces/:idGET /2/spaces/search$0.005 per SpaceNo equivalent
Reading DMsGET /2/dm_events$0.010 per DM event, user token onlyNo equivalent

X bills a read per resource it returns, so each row is priced by what the endpoint returns. Rates from X’s developer pricing page; X’s Developer Console shows the current ones. Bookmarks, DMs, the home timeline and /2/users/me act for a signed-in user and need a user token rather than the app’s Bearer token. On cheapxapi, a request returns up to 20 posts, 100 followers or 20 profiles by ID; the full list is in the API reference.

A first script: a user’s latest posts.

On v2 this job takes two calls. GET /2/users/by/username/:username turns the screen name into an ID. GET /2/users/:id/tweets then returns the posts, with tweet.fields and expansions for anything beyond the text.

The script below takes the screen name and prints each post’s time, likes, views and text. We ran both versions on @NASA with MAX_PAGES = 2: 40 posts from 2 requests, which cost $0.0012. The same 40 posts and the user lookup cost $0.21 at X’s list price.

Python needs pip install requests. Save the Node.js version as posts.mjs; it needs Node 18 or later. Both read your key from CHEAPXAPI_KEY. Reposts come back as posts whose text starts with RT; the original post is in retweeted_tweet.

import os, time, requests

API = "https://api.cheapxapi.com/twitter/user/last_tweets"
HEADERS = {"x-api-key": os.environ["CHEAPXAPI_KEY"]}
USER = "NASA"   # screen name without the @
MAX_PAGES = 2   # 20 posts a page, one billed request each

cursor, pages, posts = None, 0, []
while pages < MAX_PAGES:
    params = {"userName": USER}
    if cursor:
        params["cursor"] = cursor
    res = requests.get(API, headers=HEADERS, params=params, timeout=75)
    if res.status_code == 429:  # not billed; wait and ask for the same page again
        time.sleep(int(res.headers.get("retry-after", "1")))
        continue
    res.raise_for_status()
    page = res.json()
    pages += 1
    posts += page["data"]["tweets"]
    if not page["has_next_page"] or not page["next_cursor"]:
        break
    cursor = page["next_cursor"]
    time.sleep(0.5)

for post in posts:
    # author, created time and metrics come with every post: no fields or expansions to ask for
    text = " ".join(post["text"].split())[:70]
    print(f'{post["createdAt"][4:16]}  {post["likeCount"]:>7} likes  {post["viewCount"] or 0:>9} views  {text}')
print(f"{len(posts)} posts by @{posts[0]['author']['userName']} from {pages} requests")

What common jobs cost.

v2 has no subscription and no ongoing free tier. You buy credits, and each post, user or follower it returns is billed. X says it normally won’t charge twice for the same resource within one UTC day.

Pay-per-usage accounts are capped at 3 million post reads per billing cycle; past that, X points to its Enterprise plan. Whether there is any free way in is covered in Is the X API free?

Swipe the table to see every job.

List price of three common jobs on the official X API v2, cheapxapi and other providers
ProviderRead 100,000 postsLook up 1,000 profilesRead 100,000 followers
Official X API v2$500.00$10.00$1,000.00
cheapxapi$3.00$0.60$0.60
twitterapis.com$4.00$0.80$1.14
GetXAPI$5.00$1.00Not published
SocialData$20.00$0.20$20.00
Sorsa$199 monthly plan$2.00$2.00Not published
Apify Tweet Scraper V2$40.00Not publishedNot published

List prices. X’s figures are from its developer pricing page; the other providers’ are from their own pricing pages, with sources in our comparison. cheapxapi assumes full pages at $0.0006 a request; see pricing. Moving code over from v2: cheapxapi vs the official X API.

Get your API key

Tokens, v1.1 and api.twitter.com.

Tokens. Public data (posts, profiles, search) works with the app’s Bearer token, and rate limits then count per app. Acting for a user, or reading their bookmarks and DMs, needs a user token from OAuth 2.0 or OAuth 1.0a, and limits count per user. Getting both is covered in how to get an X API key.

v1.1. X lists v1.1 as legacy, with limited support and minimal updates, and says new features ship on v2. Start new code on v2.

api.twitter.com. X’s docs use api.x.com in every example. In our test, a request without a token to /2/users/by/username/NASA got the same 401 Unauthorized from both hosts. Use api.x.com.

Questions.

What is the Twitter API v2?

It is the current version of X’s developer API, the one formerly called the Twitter API. Requests go to https://api.x.com/2/ with a token from an approved developer app, and reads are billed per resource returned: $0.005 per post and $0.010 per user. X lists v1.1 as legacy with limited support and tells new projects to use v2.

Why does a v2 request return only id and text?

Because those are the defaults. A post lookup returns id, text and edit_history_tweet_ids unless you ask for more. Add tweet.fields (created_at, public_metrics and so on) for more about the post, expansions=author_id to get the author in includes.users, and user.fields to choose what that author object carries.

What is the difference between api.twitter.com and api.x.com?

X’s documentation uses https://api.x.com/2/ in every example. In our test, both hosts answered the same token-less request with the same 401 Unauthorized response. Use api.x.com, the host the docs use.

Is the Twitter API v2 free?

No. There is no ongoing free tier: you buy credits and each read is billed. X is rolling out a one-time $20 credit that arrives after your first credit purchase. Pay-per-usage accounts are capped at 3 million post reads per billing cycle.

How much does the X API v2 cost?

$0.005 per post read, $0.010 per user or follower read and $0.001 per resource when you read your own account through your own app. Reading 100,000 posts costs $500.00. On cheapxapi it is $3.00, at $0.0006 per request with up to 20 posts a request.

How many results does a v2 request return?

Recent search returns up to 100 posts a request and full-archive search up to 500. Post and user lookup take up to 100 IDs. Rate limits, mostly counted per 15 minutes, are separate from billing.