# youtube download api: video up to 4k, audio - fastsaver api

youtube download api. POST /youtube/download returns a download_url for 144p-2160p video or audio, valid 5 minutes. 15 credits a call, 25 for 1440p and 2160p.

> source: https://api.fastsaver.io/docs/youtube/download

`POST https://api.fastsaver.io/v1/youtube/download` - a direct link to the file

one POST turns a youtube video into a direct link to the file. pick a quality from 144p to 2160p, or audio only. the `download_url` needs no api key, so you can hand it straight to your user.

returns a `download_url` to the file itself. open it within 5 minutes. 1440p and 2160p cost 25 credits instead of 15 - they are bigger files and heavier to prepare.

Credits: 15 credits, 25 for 1440p and 2160p. A failed call costs 0.1 credit.
Every request carries `X-Api-Key`.

## Parameters

- `url` (string, required) - youtube video url (example: `https://www.youtube.com/watch?v=6dG1WWjew8s`)
- `format` (string, required) - audio, mp3, m4a, 144p, 240p, 360p, 480p, 720p, 1080p, 1440p or 2160p (example: `720p`)

## Request

```http
POST https://api.fastsaver.io/v1/youtube/download
Content-Type: application/json

{
  "url": "https://www.youtube.com/watch?v=6dG1WWjew8s",
  "format": "2160p"
}
```

## Response

```json
{
  "ok": true,
  "video_id": "6dG1WWjew8s",
  "duration": 577,
  "filename": "THE POWER OF TESTOSTERONE - LITVINOV FIT (2160p, av1, youtube).mp4",
  "download_url": "https://api.fastsaver.io/v1/tunnel?id=UJLUoLGd1m2t1ScSTW1Lw...",
  "thumbnails": {
    "low": "https://i.ytimg.com/vi/6dG1WWjew8s/mqdefault.jpg",
    "max": "https://i.ytimg.com/vi/6dG1WWjew8s/maxresdefault.jpg"
  }
}
```

## Errors

| status | detail | when | credits |
|---|---|---|---|
| 400 | `Invalid format, available formats: audio, 144p, 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p` | `format` is not one of the values above. nothing is charged. | 0 |
| 400 | `Insufficient credits. Please top up to your account.` | the balance is below the price of this format. | 0 |
| 400 | `download.failed` | the link has no youtube video id, or we could not get the file. | 0.1 |
| 400 | `fetch.timeout` | the file was not ready within 30 seconds. | 0.1 |
| 404 | `tunnel.not_found` | you opened a 1440p or 2160p `download_url` after 10 minutes. other links answer 403 or 410 when opened late or too often. call the endpoint again. | 0 |

## Limits

- `download_url` works for 5 minutes and opens up to 3 times. open it right away; after that, call the endpoint again.
- the file streams from the start: there is no `Range` and no resume, and `Content-Length` is usually missing. download it in one GET, not with a segmented downloader.
- `audio`, `mp3` and `m4a` ask for the same thing: the audio track as an mp3.
- if a video has no file at the quality you asked for, you get the next lower one. for video, `filename` usually names the quality you got.
- `duration` can be `null`.
- we wait up to 30 seconds for the file. a slower one fails with `fetch.timeout`.

## See also

- [youtube info](https://api.fastsaver.io/docs/youtube/info) - every format with its file size, before you pick one
- [youtube audio to your bot](https://api.fastsaver.io/docs/youtube/audio-tg-bot) - a telegram `file_id` instead of a file
- [credits](https://api.fastsaver.io/docs/credits) - what every call costs
- [errors](https://api.fastsaver.io/docs/errors) - every status code and what to do about it
