# YouTube 作品下载链接 API (youtube.media_links)

- Canonical page: [https://everyinfra.com/youtube-api/media_links](https://everyinfra.com/youtube-api/media_links?utm_medium=ai_doc&utm_campaign=page_md)
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "youtube", "action": "media_links", "params": {...}}
- Price: $0.000556 per call ($0.56 per 1,000 requests); failed calls and empty results are not charged
- Returns: single object
- Mode: sync; add "mode": "async" for slow tasks

## Health

- Live health (24h percent, hourly and daily trends): https://api.everyinfra.com/api/v1/social/availability?platform=youtube&action=media_links

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| url | not declared | yes | not declared | YouTube 视频链接（watch?v=、youtu.be、shorts、live 链接都行）。返回全部格式和各自的播放地址；地址大约 6 小时后失效，过期后重新取。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| title | 标题。平台无标题概念时（如纯文本帖）为 null。 |
| author_name | 作者昵称（显示名）。 |
| author_id | 作者在原平台的唯一 ID。 |
| duration | 时长。 |
| view_count | 浏览/播放数。null 表示不公开，不等于 0。 |
| is_live | 是不是正在直播。 |
| thumbnail_url | 缩略图链接，分辨率低于 image_url。 |
| available_qualities | 这条视频有的清晰度，如 1080p、720p。 |
| formats | 声音和画面在同一个文件里的格式，数组，每项有 itag、mime_type、quality_label、bitrate、width、height、fps、content_length、audio_quality 等；media_links 的每项另有播放地址 url，video_formats 的没有。 |
| adaptive_formats | 声音和画面分开的格式，数组，每项的键同 formats；只有画面的 has_audio 是 false，只有声音的 has_video 是 false。 |
| hls_manifest_url | HLS 清单地址，直播时才有，否则是 null。 |
| dash_manifest_url | DASH 清单地址，没有是 null。 |
| expires_at | 播放地址的失效时间（ISO 8601，UTC），取到后大约 6 小时。 |
| expires_in_seconds | 距离播放地址失效还有多少秒。 |
| platform | 数据来源平台标识，与请求里的 platform 一致（如 xiaohongshu、tiktok）。 |

## Example

```bash
curl -X POST 'https://api.everyinfra.com/api/v1/social' \
  -H "Authorization: Bearer $EVERYINFRA_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "platform": "youtube",
  "action": "media_links",
  "params": {
    "url": "https://www.youtube.com/watch?v=aqz-KE-bpKQ"
  }
}'
```

```python
import os
import requests

response = requests.post(
    "https://api.everyinfra.com/api/v1/social",
    headers={"Authorization": f"Bearer {os.environ['EVERYINFRA_API_KEY']}"},
    json={
        "platform": "youtube",
        "action": "media_links",
        "params": {
            "url": "https://www.youtube.com/watch?v=aqz-KE-bpKQ",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

Real response to the example request above, captured 2026-11-21T07:24:23Z. `results` and `count` are real with personal information (names, handles, avatars, profile links, contact details) removed. `id`, `billing` and `quota` differ on every call, so only their shape is shown.

```text
{
  "id": "req_…",
  "platform": "youtube",
  "action": "media_links",
  "results": {
    "id": "aqz-KE-bpKQ",
    "title": "Big Buck Bunny 60fps 4K - Official Blender Foundation Short Film",
    "author_name": "B•••r",
    "author_id": "•••",
    "duration": "00:10:35",
    "view_count": 23573023,
    "is_live": false,
    "thumbnail_url": "https://i.ytimg.com/vi/aqz-KE-bpKQ/sddefault.jpg",
    "available_qualities": [
      "2160p60",
      "1440p60",
      "1080p60"
    ],
    "adaptive_formats": [
      {
        "itag": 315,
        "url": "https://rr2---sn-o097znsl.googlevideo.com/videoplayback?expire=1795267484&ei=PEcBa4biA82Xt7EPpLyZmAc&ip=23.132.180.66&id=o-ADhlDg2wJ_uvkAHxlqRbrJ7fISvLf89SyWlWX__cM369&itag=315&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&cps=853&met=1795245884%2C&mh=aP&mm=18%2C26&mn=sn-o09…",
        "type": "video",
        "mime_type": "video/webm; codecs=\"vp09.00.51.08\"",
        "container": "webm",
        "codecs": "vp09.00.51.08",
        "has_video": true,
        "has_audio": false,
        "quality": "hd2160",
        "quality_label": "2160p60",
        "width": 3840,
        "height": 2160,
        "fps": 60,
        "bitrate": 26523399,
        "average_bitrate": 17174188,
        "content_length": 1362269481,
        "duration_ms": 634566
      },
      {
        "itag": 401,
        "url": "https://rr2---sn-o097znsl.googlevideo.com/videoplayback?expire=1795267484&ei=PEcBa4biA82Xt7EPpLyZmAc&ip=23.132.180.66&id=o-ADhlDg2wJ_uvkAHxlqRbrJ7fISvLf89SyWlWX__cM369&itag=401&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&cps=853&met=1795245884%2C&mh=aP&mm=18%2C26&mn=sn-o09…",
        "type": "video",
        "mime_type": "video/mp4; codecs=\"av01.0.13M.08\"",
        "container": "mp4",
        "codecs": "av01.0.13M.08",
        "has_video": true,
        "has_audio": false,
        "quality": "hd2160",
        "quality_label": "2160p60",
        "width": 3840,
        "height": 2160,
        "fps": 60,
        "bitrate": 17443607,
        "average_bitrate": 8981827,
        "content_length": 712445280,
        "duration_ms": 634566
      },
      {
        "itag": 308,
        "url": "https://rr2---sn-o097znsl.googlevideo.com/videoplayback?expire=1795267484&ei=PEcBa4biA82Xt7EPpLyZmAc&ip=23.132.180.66&id=o-ADhlDg2wJ_uvkAHxlqRbrJ7fISvLf89SyWlWX__cM369&itag=308&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&cps=853&met=1795245884%2C&mh=aP&mm=18%2C26&mn=sn-o09…",
        "type": "video",
        "mime_type": "video/webm; codecs=\"vp09.00.50.08\"",
        "container": "webm",
        "codecs": "vp09.00.50.08",
        "has_video": true,
        "has_audio": false,
        "quality": "hd1440",
        "quality_label": "1440p60",
        "width": 2560,
        "height": 1440,
        "fps": 60,
        "bitrate": 13250294,
        "average_bitrate": 5967715,
        "content_length": 473363704,
        "duration_ms": 634566
      }
    ],
    "expires_at": "2026-11-21T13:24:44+00:00",
    "expires_in_seconds": 21540,
    "platform": "youtube"
  },
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## Also

- Capability catalog (no key): https://api.everyinfra.com/api/v1/social/catalog?platform=youtube
- OpenAPI: https://everyinfra.com/openapi.json · Agents guide: https://everyinfra.com/agents.md
