WEIR

Get a Tweet by URL via API: X Link to JSON (2026)

Turn any x.com or twitter.com link into the post's text, author, likes and views as JSON: a tested id regex, one real call and what X's own API charges.


Published · Updated · 6 min read

Cover image: The id is in the link

To get a tweet by URL, send the digits after /status/ in the link, its post id, to a post-lookup API. From ChatGPT or Claude, paste the whole link instead: an MCP tool reads the id for you.

This guide is for developers and AI users with an X (Twitter) link who want its text, author, likes, views and replies. You get a tested regex, real calls with their costs, and the edge cases. We run Weir, the API in the examples.

curl https://api.weirapp.io/v1/x/posts/2123110241130729542 \
  -H "Authorization: Bearer $WEIR_API_KEY"

Every post link carries its id: the digits after /status/. The domain, username and ending change, but that part doesn't.

We ran this Python function on every link shape below on 18 November 2026:

import re

STATUS = re.compile(r"/status(?:es)?/(\d{1,19})(?!\d)")

def post_id(link):
    """The post id in an X (Twitter) link, or None."""
    link = link.strip()
    if re.fullmatch(r"\d{1,19}", link):  # already an id
        return link
    match = STATUS.search(link)
    return match.group(1) if match else None

print(post_id("https://x.com/NASA/status/2123110241130729542?s=20"))  # 2123110241130729542

Here is what it returned for each shape people paste:

Link shape Example post_id() returns
Standard x.com/NASA/status/2123110241130729542 The id
Old domains twitter.com/…, mobile.twitter.com/… The id
No username x.com/i/web/status/2123110241130729542 The id
Share tracking …/status/2123110241130729542?s=20&t=AbC123 The id
Photo or video view …/2123110241130729542/photo/1, /video/1 The id
Embed fixers fxtwitter.com, vxtwitter.com, fixupx.com The id
X Article x.com/i/article/2122648611703881728 None
Profile x.com/NASA None

The same regex in JavaScript:

const postId = (link) => link.match(/\/status(?:es)?\/(\d{1,19})(?!\d)/)?.[1] ?? null;

Step 2: Turn the tweet URL into JSON with one call

Send the id to Weir's GET /v1/x/posts/{id}, never the whole link. We ran the curl at the top on 18 November 2026 at 19:59 UTC, and this is its data object, trimmed:

{
  "id": "2123110241130729542",
  "text": "After nearly 50 years, Voyager 1 has traveled more than one light-day from Earth. …",
  "createdAt": "2026-11-18T17:45:01.000Z",
  "conversationId": "2123110241130729542",
  "inReplyToId": null,
  "author": { "username": "NASA", "verified": true, "followersCount": 92224746 },
  "likeCount": 2566,
  "replyCount": 87,
  "viewCount": 185372,
  "media": [{ "type": "photo", "url": "https://pbs.twimg.com/media/HXbNgxfW4AAVZCh.jpg?name=orig" }]
}

It cost 2 credits: 1 for the call and 1 for the post. Our tweet JSON example explains every field.

What it costs: 2 credits a lookup; 5,000 credits a month are free; the $5 pack buys 25,000.

The same lookup in Python, with post_id() from step 1:

import json, os, urllib.request

def get_post(link):
    pid = post_id(link)  # from step 1
    if pid is None:
        raise ValueError("no post id in " + link)
    req = urllib.request.Request(
        "https://api.weirapp.io/v1/x/posts/" + pid,
        headers={"Authorization": "Bearer " + os.environ["WEIR_API_KEY"]},
    )
    with urllib.request.urlopen(req, timeout=30) as res:
        return json.load(res)["data"], res.headers["x-credits-charged"]

post, credits = get_post("https://x.com/NASA/status/2123110241130729542/photo/1?s=20")
print(post["author"]["username"], post["likeCount"], post["viewCount"], credits, "credits")

Our run at 20:07 UTC printed:

NASA 2566 185372 2 credits

ChatGPT and Claude can't open x.com links on their own: in our test, x.com sent their fetchers an error. Connect Weir's MCP server, and its get_x_post tool takes the whole link, reads the digits after /status/ and returns the post for 2 credits.

How is this post doing? https://x.com/NASA/status/2123110241130729542
AI chat: a pasted NASA post link answered with the post's text, likes, reposts, replies, views and bookmarks
get_x_post read this link on 18 November 2026 for 2 credits

Ask next for the replies, the thread or the author, and the assistant calls get_x_replies, get_x_thread or get_x_user.

As of October 2026, ChatGPT Business, Enterprise/Edu and Pro can add custom MCP servers on the web, Pro with read tools only. Claude can on every plan, Free included. Our setup guides cover ChatGPT and Claude.

X's API also takes only the numeric id, at GET /2/tweets/:id. You need a developer account, an app and its bearer token.

curl "https://api.x.com/2/tweets/2123110241130729542?tweet.fields=created_at,public_metrics" \
  -H "Authorization: Bearer $X_BEARER_TOKEN"

We have no X key. Without one, this call got a 401 on 18 November 2026 and a made-up path got a 404, so the path is real.

  • $0.005 per post read on pay-per-use, says X's pricing page, as of 18 November 2026. Repeat reads in one UTC day bill once.
  • Three fields by default: id, text and edit_history_tweet_ids, per X's fields guide. Add tweet.fields for dates and counts.
  • The author may cost extra. X plans to bill expanded objects from 22 November 2026, making a post plus its author $0.015.

Unofficial embed endpoints exist too, but X doesn't document them, and they break without notice. See our X API curl examples and the X API price index.

What deleted posts, replies and Article links return

Here is our run of the most common odd case, a deleted post:

Terminal: a NASA link reduced to its id, a 200 that cost 2 credits, and a free 404 for a deleted post
Our calls on 18 November 2026: the miss cost nothing
  • Deleted, protected or hidden posts: 404 with "X post not found.", and no charge. Weir can't tell you which it was.
  • A reply: you get the reply. inReplyToId is its parent, and conversationId is the thread's first post.
  • The whole conversation: GET /v1/x/posts/{id}/thread gives the author's thread, and /replies gives the replies.
  • A quote post: the quoted post sits in quotedPost. /v1/x/posts/{id}/quotes lists posts quoting one.
  • An X Article link: x.com/i/article/… holds the Article's own id. Send it to GET /v1/x/articles/{id}, or get_x_article_by_id, for 2 credits.
  • Many links: GET /v1/x/posts?ids= takes up to 100 ids, comma-separated with no spaces, for 101 credits at most. Misses land in meta.notFound for free, and our hydration guide has a script.

If the lookup doesn't work

  • 404 "No endpoint matches this path": you sent the link in the URL. Send the id.
  • A different id in JavaScript: you parsed it as a number. Keep it a string.
  • 402: you're out of credits. Free ones return on the 1st of the month, UTC.
  • 429: wait the seconds in Retry-After, then try again.

When not to use Weir

  • You need data licensed by X, or X's exact v2 JSON. Use GET /2/tweets/:id.
  • You need to post, like or reply. Weir is read-only.
  • You need counts to the minute. Weir's copy of a post can be an hour old.

Weir reads public data only and isn't licensed by X, so access can change.

FAQ

How do I get the tweet ID from a URL?

Take the digits after /status/. In x.com/NASA/status/2123110241130729542?s=20, the id is 2123110241130729542. The rule holds for twitter.com, mobile and fxtwitter links. Keep it as a string, since a JavaScript number rounds it.

How do I turn a tweet URL into JSON?

Pull the id out of the link and send it to a post-lookup endpoint. Weir's GET /v1/x/posts/{id} returns the text, author, counts and media for 2 credits. X's GET /2/tweets/:id returns little beyond the id and text until you add fields.

Sources

Checked 18 November 2026 unless noted: