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.
Weir Team
Published · Updated · 6 min read
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"
Step 1: Get the tweet ID from any X link
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 |
- Keep the id as text. Modern ids pass 2^53, so a JavaScript number rounds them.
- The id is also a timestamp. Our tweet ID to date tool reads the time, and our snowflake ID guide shows the math.
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
Step 3: Or paste the link into ChatGPT, Claude or Cursor
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

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.
Twitter API: get a tweet from a link with X's own endpoint
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,textandedit_history_tweet_ids, per X's fields guide. Addtweet.fieldsfor 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:

- Deleted, protected or hidden posts:
404with "X post not found.", and no charge. Weir can't tell you which it was. - A reply: you get the reply.
inReplyToIdis its parent, andconversationIdis the thread's first post. - The whole conversation:
GET /v1/x/posts/{id}/threadgives the author's thread, and/repliesgives the replies. - A quote post: the quoted post sits in
quotedPost./v1/x/posts/{id}/quoteslists posts quoting one. - An X Article link:
x.com/i/article/…holds the Article's own id. Send it toGET /v1/x/articles/{id}, orget_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 inmeta.notFoundfor 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 inRetry-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.
Why can't ChatGPT open my x.com link?
x.com refuses the fetchers that AI apps use. In our October 2026 test, it sent ChatGPT's an error instead of the post. Connect an MCP server that reads X, such as Weir, and paste the link again, or paste the post's text.
Sources
Checked 18 November 2026 unless noted:
- X API pricing: https://docs.x.com/x-api/getting-started/pricing
- X API post lookup: https://docs.x.com/x-api/posts/get-post-by-id and https://docs.x.com/x-api/posts/lookup/introduction
- X API fields: https://docs.x.com/x-api/fundamentals/fields
- X docs pull request #520, expansion billing, open and planned for 22 November 2026: https://github.com/xdevplatform/docs/pull/520
- OpenAI Help, custom MCP servers in ChatGPT (October 2026): https://help.openai.com/en/articles/12584461
- Anthropic, custom connectors: https://support.claude.com/en/articles/11175166-get-started-with-custom-connectors-using-remote-mcp
- Weir reference and freshness: https://docs.weirapp.io/reference/x/getXPost, https://docs.weirapp.io/reference/x/getXPosts, https://docs.weirapp.io/reference/x/getXArticleById and https://docs.weirapp.io/response-shapes
- Our calls, 18 November 2026 (UTC): NASA's post by curl and Python, 2 credits each; two 404s, free; get_x_post on the same link, 2 credits