# TikTok 音乐搜索 API (tiktok.music_search)

- Canonical page: https://everyinfra.com/tiktok-api/music_search
- Endpoint: POST /api/v1/social with {"platform": "tiktok", "action": "music_search", "params": {...}}
- Price: $0.000806 per call ($0.81 per 1,000 requests); failed and empty results are not charged
- Returns: list, one page of up to 20 per call; the number of rows varies from page to page and a short page is not the end (limit is ignored; pass the top-level next_page_token from the response as page_token for the next page; no next_page_token means the end)
- 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

TikTok 音乐搜索按 `keyword` 在 TikTok 音乐库里找歌，歌名、歌手或原声名都可以，返回曲名、歌手、专辑、时长、用过这首音乐的视频数 `use_count`、是否原声 `is_original`、是否商用曲库 `is_commercial`，以及试听链接。它回答「有没有这首歌、它在 TikTok 上被用了多少次」，适合做视频前挑配乐，或者查一首歌的专辑和发行日期。

搜的是音乐库，不是视频；要读用了某首歌的视频，把结果里的 `id` 交给「用某音乐的视频」那一页。榜单那一页只给整榜 50 首，没有 `keyword`，想找榜上没有的歌，用这一页。每页约 20 首，条数不固定，翻页令牌 24 小时内有效。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| keyword | not declared | yes | not declared | 歌名、歌手或原声名，如 taylor swift；搜的是 TikTok 音乐库，不是视频。 |
| page_token | not declared | no | not declared | 翻页令牌：把上一次响应里的 next_page_token 原样传回，拿下一页；不传从第一页开始。令牌 24 小时有效，每页算一次调用。每页最多 20 首。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| title | 标题。平台无标题概念时（如纯文本帖）为 null。 |
| author_name | 评价人名字（shop_product_reviews），平台已打码，如 n**h。 |
| album | 专辑名（music_search / music_chart）；原声、没登记专辑的没有这个字段。 |
| duration_seconds | 时长，单位秒。非视频/音频内容为 null。 |
| duration_sec | platform-native meaning |
| use_count | 用过这首音乐的视频数（music_search / music_chart）。 |
| is_original | platform-native meaning |
| is_commercial | 是否 TikTok 商用曲库里的音乐（music_search / music_chart）。 |
| released_at | 音乐发行日期（music_search / music_chart）；原声、没登记发行日期的没有这个字段。 |
| cover_image_url | 视频封面图链接（带签名，会过期）。 |
| audio_url | 试听音频链接（music_search / music_chart），多为 60 秒片段，带签名、会过期。 |
| next_page_token | platform-native meaning |
| 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": "tiktok",
  "action": "music_search",
  "params": {
    "keyword": "coffee"
  }
}'
```

```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": "tiktok",
        "action": "music_search",
        "params": {
            "keyword": "coffee",
        },
    },
    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": "tiktok",
  "action": "music_search",
  "results": [
    {
      "id": …,
      "url": …,
      "title": …,
      "author_name": …,
      "album": …,
      "duration_seconds": …,
      "duration_sec": …,
      "use_count": …,
      "is_original": …,
      "is_commercial": …,
      "released_at": …,
      "cover_image_url": …,
      "audio_url": …,
      "next_page_token": …,
      "platform": …
    }
  ],
  "next_page_token": …,
  "pagination": { … },
  "count": …,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### `keyword` 可以填什么？

填歌名、歌手或原声名，例如 taylor swift，示例用的是 coffee。它搜的是 TikTok 音乐库，不是视频，返回的是歌曲，不是视频文案。

### 搜出好几首同名的歌，怎么挑？

先对曲名和歌手，再比 `use_count`，它是用过这首音乐的视频数，数值大说明在 TikTok 上被拿去做视频的次数多。拿不准时先听 `audio_url` 的试听片段，多为 60 秒，链接带签名、会失效，不要长期保存。

### `is_original` 和 `is_commercial` 有什么区别？

`is_original` 标这首是不是原声，`is_commercial` 标它是不是在 TikTok 商用曲库里，是两个独立的判断。没登记专辑的歌没有 `album`，没登记发行日期的歌没有 `released_at`，解析时按字段缺失处理。

## Also

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