Twitter Video Download API: Get the MP4 URL (2026)
Send a post ID to a Twitter video download API and read the MP4 link in the reply. Real NASA output, a Python save script and the price per post.
Tarun Khatri
Published · Updated · 7 min read
A Twitter video download API is a post lookup: send the post ID and read the MP4 link in media.
This guide is for you if your app needs the file behind a video, GIF or photo in an X (Twitter) post. You get a real NASA call, a Python save script and the price. We run Weir, the API in the examples.
curl https://api.weirapp.io/v1/x/posts/2110094874024219133 \
-H "Authorization: Bearer $WEIR_API_KEY"
- Get a keySign up free, no card.
- Look up the postOne GET with the post ID.
- Read mediaCheck type, then take url.
- Save the fileStream the url to disk.
Step 1: Call the Twitter video download API
Sign up for a free key and set WEIR_API_KEY. Your post ID is the digits after /status/ in the post's link.
We ran the curl command on 30 October 2026, on a NASA post from 13 October. Add -i to see the header x-credits-charged: ours said 2, one credit for the call and one for the post. Trimmed, the reply was:
{
"data": {
"id": "2110094874024219133",
"url": "https://x.com/NASA/status/2110094874024219133",
"media": [
{
"id": "2110094814733651969",
"type": "video",
"url": "https://video.twimg.com/amplify_video/2110094814733651969/vid/avc1/1920x1080/Iw3FOQxVrNtU6UEJ.mp4?tag=16",
"previewImageUrl": "https://pbs.twimg.com/amplify_video_thumb/2110094814733651969/img/mi2EnXdCG2jxU1NW.jpg"
}
]
}
}
The url is the file: a 1920x1080 MP4 that opened for us with no login. The previewImageUrl is the poster frame.
Do you use an AI agent with Weir's MCP server? Paste this for the same link at the same 2 credits:
Use Weir's get_x_post on https://x.com/NASA/status/2110094874024219133 and give me the direct MP4 link.
The tool takes a status link, while the REST endpoint takes digits only.
Step 2: Read media for video, GIF and photo posts
media is a list, so one post can hold several files. Check type, then take url. We called three NASA posts and saved every file:
type |
url is |
previewImageUrl |
We saved |
|---|---|---|---|
video |
the highest-bitrate MP4 | a poster frame | 2.5 MB MP4 |
animated_gif |
an MP4 | null |
119 KB MP4 |
photo |
the image file | null |
4 JPEGs |
- A GIF is an MP4. X served ours as an MP4 file, so convert it if you need a
.gif. - Photos come as given. Four photos gave four
pbs.twimg.comlinks. Use eachurlas returned. urlcan benull. Weir's reference says that happens when X offers only a stream. Skip those items.- Nested posts keep their own files. Per the reference, look in
quotedPost.mediaandretweetedPost.media.
Our tweet JSON guide covers the other fields.
Step 3: Save the file with Python
This script uses only the standard library, so it runs in your agent's sandbox with no pip:
import json, os, shutil, sys, urllib.request
post_id = sys.argv[1]
url = f"https://api.weirapp.io/v1/x/posts/{post_id}"
req = urllib.request.Request(url, headers={"Authorization": "Bearer " + os.environ["WEIR_API_KEY"]})
post = json.load(urllib.request.urlopen(req, timeout=60))["data"]
for n, item in enumerate(post["media"], 1):
if item["url"] is None: # stream only: no file to save
continue
ext = item["url"].split("?")[0].rsplit(".", 1)[-1] # mp4 or jpg
name = f"{post_id}_{n}.{ext}"
with urllib.request.urlopen(item["url"], timeout=60) as src, open(name, "wb") as out:
shutil.copyfileobj(src, out) # copies in chunks
print("saved", name, os.path.getsize(name), "bytes")
Save it as download_media.py, then run python download_media.py 2110094874024219133:
saved 2110094874024219133_1.mp4 2451219 bytes
The same script saved the GIF and the four photos. With requests, stream one link like this:
import requests
def save(url, name):
with requests.get(url, stream=True, timeout=60) as r:
r.raise_for_status()
with open(name, "wb") as f:
for chunk in r.iter_content(chunk_size=1 << 20):
f.write(chunk)
Save the file, not the link, because we can't say how long X keeps a URL working.
For a whole account's media, see our Twitter image search guide.
Does Twitter have an API for video? X's route and Weir's
Yes. X's API v2 sells post reads on pay-per-use credits. Add two query fields to your post lookup and each video lists its variants:
curl "https://api.x.com/2/tweets/2110094874024219133?expansions=attachments.media_keys&media.fields=type,url,variants" \
-H "Authorization: Bearer $X_BEARER_TOKEN"
Per X's reference, each variant has a bit_rate, a content_type and a url. The type can be video/mp4 or application/x-mpegURL, a common label for an HLS playlist. We did not call X's API ourselves, so test a live reply.
To pick the biggest MP4 yourself:
def best_mp4(media):
mp4s = [v for v in media.get("variants", []) if v.get("content_type") == "video/mp4"]
return max(mp4s, key=lambda v: v.get("bit_rate") or 0)["url"] if mp4s else None
Weir applies that rule for you.
HLS (.m3u8) is a playlist, not a video file. RFC 8216 describes a text file that lists media segments, so one GET cannot save it. Tools such as ffmpeg can join the segments, but Weir returns no playlist.
Pick X's API for variants and Weir for one ready MP4 (both as of 30 October 2026):
| Need | X API v2 | Weir |
|---|---|---|
| Video file | You pick from variants |
media[].url, one MP4 |
| Other bit rates, HLS | Yes | No |
| Price per post | $0.005 | 2 credits |
| Rate limit | 450 per 15 min, per app | 30 a minute, free key |
How much does a Twitter video downloader API cost?
X's pricing page lists $0.005 per post read. It bills repeat reads of a post within a UTC day once, as a soft guarantee. Weir charged us 2 credits again for a second lookup of the same post, so cache what you reuse.
At the $5 pack a credit costs $0.0002, so 1,000 posts cost:
The batch call, GET /v1/x/posts?ids=, takes up to 100 ids. We sent four, one made up. It cost 4 credits (1 for the call, 1 for each of 3 posts), and the made-up id came back free in meta.notFound.
The 5,000 free monthly credits cover about 2,500 single lookups, or 4,950 posts at 100 ids per call. Any $5 pack raises the 30-a-minute limit to 120. Price your own volume with the X API cost calculator.
If it doesn't work
- 404
not_found. The post doesn't exist, was deleted or isn't public. We asked for a made-up id and paid nothing. - 400
bad_request. REST ids are digits only, so strip a status link down to its digits. - 429
rate_limit_exceeded. Wait for theRetry-Afterseconds, then retry. It costs you nothing. - 503
source_unavailable. X was unreachable. We got several on 30 October, retried, and paid nothing. - 402. You're out of credits, and retrying won't help.
The 404 body:
{ "error": { "code": "not_found", "message": "X post not found.", "retryable": false } }
Is it OK to download videos from X?
X's terms, effective 9 October 2026, say a user keeps their rights to what they post, and that "your incorporated audio, photos, and videos are considered part of the Content". To reproduce, distribute or publicly display X content you must use X's interfaces and instructions, except as its terms permit, or it is "strictly prohibited".
A video on X is still the creator's work. Save only what you have the right to use, and ask permission before you reuse one. The rest depends on X's terms, copyright law and your country.
Weir returns only the link X already serves publicly, and it can't read protected posts. It isn't licensed by X, so access can change. This isn't legal advice, and our guide to scraping and the law goes deeper.
When not to use Weir
- You need every bit rate or the HLS stream. Weir sends one MP4 per video. Use X's API with
variants. - Bulk volume is the whole job. TwitterAPI.io lists $0.15 per 1,000 tweets, below our $5 and $20 packs, as of 30 October 2026.
- You need a contract with X. Use X's official API and its pay-per-use plan.
FAQ
Does Twitter have an API?
Yes. X (Twitter) sells API v2 on pay-per-use credits, at $0.005 a post read as of October 2026. Its post lookup returns video files when you ask for media.fields=variants. Weir is a separate, read-only API.
How to use Twitter API to get a video link?
Create an app in X's Developer Console, buy credits, and send your bearer token to GET /2/tweets/{id} with the two query fields above. Our X API key guide has the console steps.
Is there a Twitter video downloader API free of charge?
Not from X, whose pricing page lists no free tier for reads. Weir gives 5,000 free credits a month with no card, about 2,500 lookups. Both return links, so your code saves the files, and our X API pricing guide has X's full rates.
What is a Twitter downloader API?
It takes a post ID or link and returns the address of the video, GIF or photo, not the file. Your code then downloads that address. Compare price, limits and error codes first.
Can a Twitter video download API get GIFs and photos too?
Yes. X types them animated_gif and photo. A GIF comes back as an MP4 link and a photo as an image link. We saved one of each on 30 October 2026.
Sources
Every link below was checked on 30 October 2026.
- X API, Get Post by ID (media fields and variants): https://docs.x.com/x-api/posts/get-post-by-id
- X API pay-per-usage pricing: https://docs.x.com/x-api/getting-started/pricing
- X API rate limits: https://docs.x.com/x-api/fundamentals/rate-limits
- X Terms of Service, effective 9 October 2026: https://x.com/en/tos
- RFC 8216, HTTP Live Streaming, section 2: https://www.rfc-editor.org/rfc/rfc8216
- ffmpeg formats, HLS demuxer: https://ffmpeg.org/ffmpeg-formats.html
- TwitterAPI.io pricing: https://twitterapi.io/pricing
- Weir getXPost and getXPosts references: https://docs.weirapp.io/reference/x/getXPost and https://docs.weirapp.io/reference/x/getXPosts
- Weir billing and tiers: https://docs.weirapp.io/billing
- Our live calls to Weir's API on 30 October 2026: three post lookups, a batch lookup, a missing id and the get_x_post tool