# YouTube Format stream URL API (youtube.stream_url)

- Canonical page: [https://everyinfra.com/en/youtube-api/stream_url](https://everyinfra.com/en/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 | A YouTube video link (watch?v=, youtu.be, shorts and live links work). |
| itag | integer | yes | not declared | Which format: YouTube's format number, an integer from 1 to 9999, taken from the `itag` of `video_formats` or `media_links` (140 is m4a audio). A video without that format returns an empty result. A value that is not recognized returns 422 and is not charged. |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | The record's unique ID on the platform. Unique only within one platform; IDs can repeat across platforms. |
| itag | YouTube format ID. |
| url | Link to the record on the platform. |
| mime_type | File type and codec, e.g. `audio/mp4; codecs="mp4a.40.2"`. |
| quality_label | Resolution label, e.g. `720p`; null for audio-only formats. |
| content_length | File size in bytes. |
| expires_at | When the playback URLs expire (ISO 8601, UTC), about 6 hours after they are issued. |
| expires_in_seconds | Seconds left until the playback URLs expire. |
| platform | Source platform identifier, the same as platform in the request (for example 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
