# Bilibili Media download links API (bilibili.media_links)

- Canonical page: [https://everyinfra.com/en/bilibili-api/media_links](https://everyinfra.com/en/bilibili-api/media_links?utm_medium=ai_doc&utm_campaign=page_md)
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "bilibili", "action": "media_links", "params": {...}}
- Price: $0.000792 per call ($0.79 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=bilibili&action=media_links

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| url | not declared | yes | not declared | The video the part belongs to: a Bilibili video link such as `https://www.bilibili.com/video/<BV ID>`, or the BV ID itself. Anything else returns 422 and is not charged. |
| cid | not declared | yes | not declared | The numeric ID of the part, taken from the `cid` of a `video_parts` row. A video with a single part still needs its one `cid`. A value that is not all digits 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. |
| video_id | BV number of the video. |
| url | Link to the record on the platform. |
| aid | The video's numeric av ID (popular); it names the same video as the BV ID in id. |
| cid | Part ID (video_parts): the numeric ID Bilibili assigns to each part of a video. |
| quality_id | Code of the highest quality in this response (media_links), such as 32; up to 480P without logging in. |
| quality | Quality name, such as 480P (media_links: the highest quality in this response; each entry of video_streams: that stream's quality). |
| available_qualities | Every quality the video has (media_links), as an array: id is the quality code, quality is its name. It does not mean all were returned this time; video_streams shows which were. |
| duration_seconds | Duration in seconds. null for content that is not video or audio. |
| duration_sec | Video length in seconds, the same value as duration_seconds (both names are returned); on video_parts it is the length of that one part, elsewhere a multi-part video gives the total of all parts. |
| video_streams | List of video streams (DASH, .m4s, picture only with no sound, to be merged with an audio stream): id (quality code), quality (quality name, up to 480P without login), codecs (avc1 / hev1 / av01), width, height, frame_rate, bandwidth, url, backup_urls. The links expire after about 120 minutes, see streams_expire_at; send the Referer request header when downloading, see streams_referer. |
| audio_streams | List of audio streams (DASH, .m4s, mp4a): id, codecs, bandwidth, url, backup_urls. Expiry time and Referer requirement are the same as for video_streams. |
| mp4_segments | Addresses of the whole mp4 (media_links). A few older videos have no DASH streams and come as one mp4 instead; then this field is present and video_streams and audio_streams are not. Each entry has order, duration_seconds, size (bytes), url and backup_urls. |
| streams_expire_at | Time when the stream URLs expire (ISO, the earliest of all the links; about 120 minutes after the call). After that, call video again to get new URLs. |
| streams_referer | Value of the Referer request header that must be sent when downloading the stream URLs (without it the request gets a 403). |
| 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": "bilibili",
  "action": "media_links",
  "params": {
    "url": "https://www.bilibili.com/video/BV1xx411c7mD",
    "cid": "62131"
  }
}'
```

```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": "bilibili",
        "action": "media_links",
        "params": {
            "url": "https://www.bilibili.com/video/BV1xx411c7mD",
            "cid": "62131",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

No real sample for these example parameters yet: structure only, every value is a placeholder (…).

```text
{
  "id": "req_…",
  "platform": "bilibili",
  "action": "media_links",
  "results": {
    "id": …,
    "video_id": …,
    "url": …,
    "aid": …,
    "cid": …,
    "quality_id": …,
    "quality": …,
    "available_qualities": …,
    "duration_seconds": …,
    "duration_sec": …,
    "video_streams": …,
    "audio_streams": …,
    "mp4_segments": …,
    "streams_expire_at": …,
    "streams_referer": …,
    "platform": …
  },
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## Also

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