Every photo, video and GIF, by API.
A post’s files are listed in extendedEntities.media. For a video or GIF, take the video/mp4 variant with the highest bitrate; for a photo, add ?name=orig to the image URL. To collect a whole account, search from:account filter:media and download each file.
On @GIPHY since 1 January 2025 that took 6 requests ($0.0036) and saved 82 files. The downloads themselves are not billed. The official X API charges $0.005 for each post it returns.
The video links in one post.
Get tweets by ID returns a post with its media attached. The number after /status/ in an x.com link is the ID. One request costs $0.0006.
This post holds one video. Its variants are an .m3u8 playlist for streaming players and five MP4 files of the same clip, from 320 × 400 up to 2160 × 2700. Each MP4 carries its bitrate, so the largest number is the best copy.
Request
curl "https://api.cheapxapi.com/twitter/tweets?tweet_ids=1963997578376462829" \
-H "x-api-key: $CHEAPXAPI_KEY"Response, captured from the live API
{
"status": "success",
"msg": "success",
"code": 0,
"tweets": [
{
"type": "tweet",
"id": "1963997578376462829",
"url": "https://x.com/GIPHY/status/1963997578376462829",
"createdAt": "Fri Sep 05 16:08:06 +0000 2025",
"extendedEntities": {
"media": [
{
"type": "video",
"id_str": "1963997501775634432",
"media_url_https": "https://pbs.twimg.com/amplify_video_thumb/1963997501775634432/img/lMviN2aFoNLK9Um2.jpg",
"original_info": { "height": 3218, "width": 2574 },
"video_info": {
"aspect_ratio": [1287, 1609],
"duration_millis": 15000,
"variants": [
{
"content_type": "application/x-mpegURL",
"url": "https://video.twimg.com/amplify_video/1963997501775634432/pl/OPlsKcLmH4bDEh2j.m3u8?tag=21"
},
{
"bitrate": 632000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/amplify_video/1963997501775634432/vid/avc1/320x400/o4OjwPa68qIOOWu0.mp4?tag=21"
},
{
"bitrate": 950000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/amplify_video/1963997501775634432/vid/avc1/480x600/lxwoWI6sf_Q1MqJc.mp4?tag=21"
},
{
"bitrate": 2176000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/amplify_video/1963997501775634432/vid/avc1/720x900/JpYBpieLzz24pW37.mp4?tag=21"
},
{
"bitrate": 10368000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/amplify_video/1963997501775634432/vid/avc1/1080x1350/ZE4Q8vQvgBXZl1lo.mp4?tag=21"
},
{
"bitrate": 25128000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/amplify_video/1963997501775634432/vid/avc1/2160x2700/ydW4Wru5nsSFDoxf.mp4?tag=21"
}
]
}
}
]
}
}
]
}Trimmed to the media fields; the text, counts and author are left out. The media_url_https of a video is its preview image, not the video.
Which URL to download.
| type | File in | Take | What we saw |
|---|---|---|---|
| photo | media_url_https | Add ?name=orig. Without it you can get a smaller copy. | 1200 × 960 as given, 1350 × 1080 with ?name=orig, the size in original_info. |
| video | video_info.variants | The video/mp4 variant with the highest bitrate. The .m3u8 entry is a streaming playlist. | Five MP4s from 320 × 400 to 2160 × 2700 on the post above. |
| animated_gif | video_info.variants | The only variant: an MP4 file, bitrate 0. | All 76 GIFs in our run came as MP4. |
Read extendedEntities, not entities.
Posts also have an entities.media list, but it is often empty. On @github’s latest 20 posts with media, 11 had nothing there, and one post carried three photos. extendedEntities.media listed every file each time.
The best MP4 can be smaller than the upload.
original_info gives the size that was uploaded, not the size you can download. One video in our run was 1080 × 1080 in original_info; its best MP4 was 720 × 720. Read the size from the variant URL if it matters.
Download an account’s media.
Set USER and, if you want a date limit, SINCE. The script searches from:USER filter:media with advanced search, keeps each file once by its media ID, saves it to USER_media/ and writes media.csv with the type, size, date, post link and source URL of every file.
We ran both versions on @GIPHY with SINCE set to 1 January 2025. Each found 82 posts in 6 requests ($0.0036) and saved 82 files: 76 GIFs, 3 videos and 3 photos, 18 MB in all.
For one kind of file, swap the filter: filter:images returned only photos and filter:native_video only videos when we tried them. For a date range or keywords, see searching by date and the search API guide. For the posts’ text and counts as well, use the full export.
Python needs pip install requests. Save the Node.js version as download_media.mjs; it needs Node 18 or later. Both read your key from CHEAPXAPI_KEY and pause half a second between requests, inside the free plan’s 2 a second. MAX_PAGES caps the bill. Posts and their media belong to the people who posted them; download what you have the right to use.
import csv, os, pathlib, time, requests
API = "https://api.cheapxapi.com/twitter/tweet/advanced_search"
HEADERS = {"x-api-key": os.environ["CHEAPXAPI_KEY"]}
USER = "GIPHY" # screen name without the @
SINCE = "2025-01-01" # oldest day to include; "" for the whole account
MAX_PAGES = 50 # hard stop on billed requests (about 20 posts each)
OUT = pathlib.Path(f"{USER}_media")
def best_file(media):
"""Photos: the original size. Videos and GIFs: the highest-bitrate MP4."""
if media["type"] == "photo":
return media["media_url_https"] + "?name=orig"
mp4 = [v for v in media["video_info"]["variants"] if v["content_type"] == "video/mp4"]
return max(mp4, key=lambda v: v.get("bitrate", 0))["url"]
query = f"from:{USER} filter:media" + (f" since:{SINCE}" if SINCE else "")
items, cursor, pages = {}, None, 0 # media id -> row; a post or page can repeat
while pages < MAX_PAGES:
params = {"query": query, "queryType": "Latest", **({"cursor": cursor} if cursor else {})}
res = requests.get(API, headers=HEADERS, params=params, timeout=75)
if res.status_code == 429: # not billed: wait and ask again
time.sleep(int(res.headers.get("retry-after", "1")))
continue
res.raise_for_status()
pages += 1
page = res.json()
for post in page["tweets"]:
for media in (post.get("extendedEntities") or {}).get("media", []):
items.setdefault(media["id_str"], {
"post_id": post["id"], "created_at": post["createdAt"], "type": media["type"],
"width": media["original_info"]["width"], "height": media["original_info"]["height"],
"url": best_file(media), "post_url": post["url"],
})
if not page.get("has_next_page") or not page.get("next_cursor"):
break
cursor = page["next_cursor"]
time.sleep(0.5)
OUT.mkdir(exist_ok=True)
for media_id, row in items.items():
ext = ".mp4" if row["type"] != "photo" else pathlib.Path(row["url"].split("?")[0]).suffix
row["file"] = f"{row['post_id']}_{media_id}{ext}"
target = OUT / row["file"]
if not target.exists(): # files come from X's CDN, not the API, so they are not billed
file = requests.get(row["url"], timeout=120)
file.raise_for_status()
target.write_bytes(file.content)
with open(OUT / "media.csv", "w", newline="", encoding="utf-8") as f:
out = csv.DictWriter(f, fieldnames=["file", "type", "width", "height", "created_at", "post_url", "url"])
out.writeheader()
out.writerows({k: row[k] for k in out.fieldnames} for row in items.values())
kinds = {t: sum(r["type"] == t for r in items.values()) for t in ("photo", "video", "animated_gif")}
print(f"{len(items)} files {kinds} from {pages} requests, saved in {OUT}/")What it costs.
You pay to list the posts, not to download the files. cheapxapi bills each request, and a request returns up to 20 posts. X bills $0.005 for each post it returns and has no separate line for the media that comes with it.
On X, add expansions=attachments.media_keys and media.fields=variants to get the MP4 links, and filter a search with has:media, has:images or has:video_link next to another term such as from:.
| Posts with media | 1,000 | 10,000 | 100,000 |
|---|---|---|---|
| cheapxapi | $0.03 | $0.30 | $3.00 |
| Official X API | $5.00 | $50.00 | $500.00 |
| Other providers | 100,000 posts |
|---|---|
| cheapxapi | $3.00 |
| twitterapis.com | $4.00 |
| GetXAPI | $5.00 |
| SocialData | $20.00 |
| Sorsa$199 monthly plan | $2.00 |
| Apify Tweet Scraper V2 | $40.00 |
List prices for posts from search. X’s figures are from its developer documentation and pricing page; the other providers’ are from their own pricing pages, with sources in our comparison. cheapxapi assumes full pages of 20 at $0.0006 a request; our run averaged fewer (82 posts in 6 requests). See pricing.
Get your API keyQuestions.
How do I get the video URL of a tweet with an API?
Look the post up by ID (GET /twitter/tweets?tweet_ids=...) and read extendedEntities.media. For a video, video_info.variants lists an .m3u8 streaming playlist and several MP4 files; the video/mp4 entry with the highest bitrate is the best quality. The URL points at video.twimg.com and downloads like any file.
How do I download all videos and photos from an X account?
Search from:username filter:media, page through the results, and download the files each post lists. Use filter:images for photos only or filter:native_video for videos only. The scripts on this page do it and write a CSV of what they saved; on @GIPHY since 1 January 2025 that was 82 files from 6 requests.
Does the official X API give video download links?
It returns them in the media object: request expansions=attachments.media_keys with media.fields=variants, and each variant has bit_rate, content_type and url. X bills every post it returns at $0.005; its pricing page has no separate line for reading media. To list an account's media, combine from: with has:media, has:images or has:video_link; X does not accept those operators on their own.
Why does a GIF download as an MP4 file?
X serves GIFs as MP4 video. A post with a GIF has type animated_gif and a single MP4 variant with bitrate 0; all 76 GIFs in our run looked like that. Convert the MP4 yourself if you need a .gif file.
Are the media downloads billed?
No. cheapxapi bills the API requests that list the posts, $0.0006 each for about 20 posts. The photos and videos come straight from X's file servers (pbs.twimg.com and video.twimg.com), which are not part of the API.