# 抖音 音乐搜索 API (douyin.music_search)

- Canonical page: https://everyinfra.com/douyin-api/music_search
- Endpoint: POST /api/v1/social with {"platform": "douyin", "action": "music_search", "params": {...}}
- Price: $0.008 per call ($8 per 1,000 requests); failed and empty results are not charged
- Returns: list, one page of 10 per call (limit is ignored; pass the top-level next_page_token from the response as page_token for the next page)
- Pagination: pass next_page_token back as page_token for the next page, other params unchanged; one call per page, tokens last 24 hours
- Mode: sync; add "mode": "async" for slow tasks

找配乐时先用音乐搜索：`keyword` 填歌名、歌手或原声名，例如 周杰伦，返回抖音音乐库里的音乐和原声。每行带 `id`、标题、作者、时长、封面、播放地址 `audio_url`，以及用这段音乐发过的作品数 `use_count`，可以直接按使用量比较候选。

一页固定 10 首，最后一页可能不足，传大的 `limit` 也不会多给，要更多只能翻页。`tags` 是标签数组，没有标签时是空数组而不是 null。封面在 `cover_image_url`，是音乐封面。`lyric_url` 平台给了才有，`audio_url` 可能会过期。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| keyword | not declared | yes | not declared | 音乐关键词：歌名、歌手或原声名，例如 周杰伦；返回抖音音乐库里的音乐和原声。 |
| page_token | not declared | no | not declared | 翻页令牌。不传是第 1 页；之后把上一页响应里的 next_page_token 原样传回取下一页，其余参数不变。每页最多 10 首、算一次调用；令牌 24 小时内有效；翻到底时没有 next_page_token。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| title | 标题。平台无标题概念时（如纯文本帖）为 null。 |
| author_name | 作者昵称（显示名）。 |
| duration_seconds | 时长，单位秒。非视频/音频内容为 null。 |
| duration_sec | 视频时长（秒）。 |
| use_count | 用这段音乐发过的作品数（music_search、music_detail），即抖音音乐页上的「N 人使用」。 |
| cover_image_url | 封面图链接：search / user_posts 是作品封面，music_search / music_detail 是音乐封面，billboard_topic_hot 是话题配图。 |
| audio_url | 音频地址：transcript 是视频音轨（mp3），music_search、music_detail 是这段音乐的播放地址；可能会过期。 |
| lyric_url | 歌词文件链接（music_search、music_detail，平台给了才有）。 |
| tags | 标签数组。无标签时为空数组，不是 null。 |
| next_page_token | 翻页令牌（search / user_posts / comments / comment_replies / billboard_video_hot / billboard_low_fan_explosion / billboard_high_completion / billboard_account_search / music_search / billboard_rise_list / billboard_topic_hot）：作为下一次请求的 page_token 原样传回取下一页（其余参数不变，24 小时内有效）；同一页每行的值相同，响应顶层也有同一个 next_page_token。没有该字段即到底。评论翻页逐页覆盖全部顶层评论。 |
| 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": "douyin",
  "action": "music_search",
  "params": {
    "keyword": "美食"
  }
}'
```

```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": "douyin",
        "action": "music_search",
        "params": {
            "keyword": "美食",
        },
    },
    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": "douyin",
  "action": "music_search",
  "results": [
    {
      "id": …,
      "url": …,
      "title": …,
      "author_name": …,
      "duration_seconds": …,
      "duration_sec": …,
      "use_count": …,
      "cover_image_url": …,
      "audio_url": …,
      "lyric_url": …,
      "tags": …,
      "next_page_token": …,
      "platform": …
    }
  ],
  "next_page_token": …,
  "pagination": { … },
  "count": …,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 搜到音乐之后怎么读单首的详情？

把结果行里的 `id` 作为音乐详情的音乐 ID 传回去。搜索结果已经带了 `use_count`、`audio_url` 和 `lyric_url`，只要这些的话不用再调详情；详情那一页返回同一首的同一批字段，但没有标签。比较使用量时，直接用结果行里的 `use_count` 排序。

### 一页只有 10 首，传大 `limit` 能多拿一些吗？

不能。`limit` 能传，但对这个接口不起作用，每页固定 10 首，最后一页可能更少。想要更多结果就翻页，每页算一次调用。

### `tags` 是空的，说明没取到数据吗？

不是出错。没有标签时 `tags` 是空数组，不是 null，所以可以直接遍历，不必先判空。标签只有搜索这一页返回，音乐详情那一页没有这个字段。

## Also

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