YouTube Download API: Pick a Format, Get a Stream
YouTube is the one platform where "give me the video" is not enough. One watch URL hides a stack of renditions, 144p up to 2160p, plus an audio track. So the FastSaver API splits YouTube into two calls: list the formats, then request the one you picked.
auth
Send your key as an X-Api-Key header on both calls. Keys come from api.fastsaver.io; key handling is in the getting started guide.
step 1: list formats
curl "https://api.fastsaver.io/v1/youtube/info?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dxyz" \
-H "X-Api-Key: YOUR_KEY"
{
"ok": true,
"title": "desk setup tour",
"author": "some channel",
"thumbnail": "https://…/hq.jpg",
"duration": 734,
"formats": [
{ "type": "video", "format": "2160p", "filesize": 812449102 },
{ "type": "video", "format": "1080p", "filesize": 133956977 },
{ "type": "video", "format": "720p", "filesize": 61531585 },
{ "type": "audio", "format": "audio", "filesize": 3968982 }
]
}
Only formats the upload actually has appear here. An old 480p video lists no 2160p, and that is correct. Show the list with filesizes, or pick in code: highest video for archiving, audio for a music feature.
step 2: request your pick
curl -X POST "https://api.fastsaver.io/v1/youtube/download" \
-H "X-Api-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{ "url": "https://www.youtube.com/watch?v=xyz", "format": "720p" }'
{
"ok": true,
"download_url": "https://…",
"filename": "desk-setup-tour-720p.mp4"
}
format is one of 144p, 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p or audio. A format this video does not have is rejected. That is why you list first.
In JavaScript and Python it is the same two requests:
const headers = { 'X-Api-Key': process.env.FASTSAVER_KEY };
const info = await (await fetch(
'https://api.fastsaver.io/v1/youtube/info?url=' + encodeURIComponent(link),
{ headers }
)).json();
const dl = await (await fetch('https://api.fastsaver.io/v1/youtube/download', {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({ url: link, format: '720p' })
})).json();
headers = {'X-Api-Key': os.environ['FASTSAVER_KEY']}
info = requests.get(base + '/v1/youtube/info', params={'url': link}, headers=headers).json()
dl = requests.post(base + '/v1/youtube/download', json={'url': link, 'format': '720p'}, headers=headers).json()
audio is m4a
Pass format: "audio" and step 2 returns the audio on its own, an m4a file. It plays in every music app and on every phone. Need a literal mp3? Convert the m4a yourself with ffmpeg; the API does not re-encode. The no-code version is the YouTube to mp3 guide.
streaming the file
GET the download_url with redirects enabled and stream the body to disk or to your user. Do not buffer a 2160p file in memory. Raise the read timeout; the transfer takes as long as the file is big. Call step 2 when the user clicks, not for every quality up front. Use the link promptly instead of storing it.
errors
{ "ok": false, "detail": "fetch.failed" }
- 401: missing or wrong key.
- 400: bad url, or no credits left.
- 429: too many requests this minute. Wait, then retry.
- fetch.failed: private, deleted or age-gated video. Not retryable.
Shorts, youtu.be links and plain watch links all go through the same two calls. Playlists and live streams do not. The Shorts guide covers the consumer side.
credits and pricing
Every key starts with 1,000 free credits; paid plans from $9/month on the pricing page. One-off download? The web downloader is the same two-step engine with the quality grid as buttons.
frequently asked questions
- Why does YouTube need two API calls when other platforms need one?
- One watch URL maps to many renditions. /v1/youtube/info lists what exists with filesizes; /v1/youtube/download returns the one you picked. A TikTok has one file, so it is one call.
- How do I get just the audio? Is it mp3?
- Pass format "audio" to the download endpoint. You get an m4a file, not mp3. It plays everywhere; convert it with ffmpeg if you truly need mp3.
- Which format values does the download endpoint accept?
- 144p, 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p and audio. Anything else is rejected, and so is a quality this video never had. Check the info response first.
- Do YouTube Shorts and youtu.be links work?
- Yes. Shorts URLs and youtu.be short links go through the same info-then-download flow as a regular watch URL. Playlists and live streams do not.