# YouTube 单个格式的播放地址 API (youtube.stream_url)

- Canonical page: [https://everyinfra.com/youtube-api/stream_url](https://everyinfra.com/youtube-api/stream_url?utm_medium=ai_doc&utm_campaign=page_md)
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "youtube", "action": "stream_url", "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=stream_url

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| url | not declared | yes | not declared | YouTube 视频链接（watch?v=、youtu.be、shorts、live 链接都行）。 |
| itag | integer | yes | not declared | 要哪个格式：YouTube 的格式编号，整数，取 video_formats 或 media_links 返回的 itag（如 140 是 m4a 声音）。这条视频没有这个格式时返回空。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| itag | YouTube 的格式编号。 |
| url | 该记录在原平台上的可访问链接。 |
| mime_type | 文件类型和编码，如 audio/mp4; codecs="mp4a.40.2"。 |
| quality_label | 清晰度，如 720p；只有声音的格式是 null。 |
| content_length | 文件大小，字节。 |
| 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": "stream_url",
  "params": {
    "url": "https://www.youtube.com/watch?v=aqz-KE-bpKQ",
    "itag": 140
  }
}'
```

```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": "stream_url",
        "params": {
            "url": "https://www.youtube.com/watch?v=aqz-KE-bpKQ",
            "itag": 140,
        },
    },
    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": "stream_url",
  "results": {
    "id": "aqz-KE-bpKQ",
    "itag": 140,
    "url": "https://rr3---sn-a5mlrnll.googlevideo.com/videoplayback?expire=1795267486&ei=PkcBa5HjJICYsfIPpPrFgAQ&ip=189.105.112.160&id=o-AKzweXFGKFKKShSKTD0ht1qQzT4IlKQB_0u_qwlpFEe3&itag=140&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&cps=847&met=1795245886%2C&mh=aP&mm=18%2C29&mn=sn-a…",
    "mime_type": "audio/mp4; codecs=\"mp4a.40.2\"",
    "content_length": 10271496,
    "expires_at": "2026-11-21T13:24:46+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
