# YouTube 关键词搜索 API (youtube.search)

- Canonical page: https://everyinfra.com/youtube-api/search
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "youtube", "action": "search", "params": {...}}
- Price: $0.000778 per call ($0.78 per 1,000 requests); failed calls and empty results are not charged
- Returns: list, default 10, max 50 per call
- 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=search

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| keyword | not declared | yes | not declared | YouTube 视频搜索词，不是频道 handle 或视频 ID。 |
| sort | enum: most_viewed / newest / relevance / top_rated | no | not declared | 视频搜索排序：relevance 相关性、newest 最新发布、most_viewed 播放量、top_rated 评分。 |
| limit | integer (1–50) | no | 10 | 这次调用最多返回的条数，整数，1–50；不传按默认值，实际返回可能少于这个数。超过上限会在扣费前返回 422。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| title | 标题。平台无标题概念时（如纯文本帖）为 null。 |
| text | 正文内容，已去除 HTML 标签，全文返回、不截断（个别平台的列表结果本身只有摘要，以该平台的字段说明为准）。 |
| author_name | 作者昵称（显示名）。 |
| author_username | 作者用户名（@handle），通常可用于拼 URL。 |
| author_id | 作者在原平台的唯一 ID。 |
| author_url | 作者在原平台的主页链接。 |
| like_count | 点赞数。null 表示该平台或该接口不公开此数据，不等于 0。 |
| comment_count | 评论数。null 表示不公开，不等于 0。 |
| view_count | 浏览/播放数。null 表示不公开，不等于 0。 |
| duration | 时长。 |
| posted_at | 发布时间，ISO 8601 格式、UTC 时区（如 2026-08-07T12:34:56+00:00）。平台只给非标准字符串时原样透传，解析前建议做容错。null 表示平台未公开。 |
| thumbnail_url | 缩略图链接，分辨率低于 image_url。 |
| hashtags | 正文里的话题标签数组，按出现顺序；没有时不出现这个字段。 |
| is_comments_disabled | 是否关闭评论。 |
| is_members_only | 是否会员专享视频。 |
| is_paid_partnership | 是否含付费推广。 |
| author_follower_count | 作者粉丝数。null 表示不公开。 |
| author_video_count | 频道视频总数。 |
| author_view_count | 频道总播放量。 |
| author_created_at | platform-native meaning |
| description_links | 视频简介里的链接：text、url。 |
| search_rank | 在这次搜索结果里的名次，从 1 开始。 |
| 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": "search",
  "params": {
    "keyword": "urban gardening tutorial"
  }
}'
```

```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": "search",
        "params": {
            "keyword": "urban gardening tutorial",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

Real response to the example request above, captured 2026-09-26T08:56:04Z. `results` and `count` are real with personal information (names, handles, avatars, profile links, contact details) removed; the list keeps the first 2 of 10. `id`, `billing` and `quota` differ on every call, so only their shape is shown.

```text
{
  "id": "req_…",
  "platform": "youtube",
  "action": "search",
  "results": [
    {
      "id": "SgqP8fgnzgI",
      "url": "https://www.youtube.com/watch?v=SgqP8fgnzgI",
      "title": "Fall Garden Seed Starting: Onions, Tomatoes, Collards & More 🌱 (North Texas Guide)",
      "text": "It's time to start thinking about the fall garden here in North Texas. Starting seeds indoors now gives you a head start on cooler-weather crops and extends your growing season well into autumn.\n\nIn this video, I'm walking you through everything I'm starting right now—from bunchi…",
      "author_name": "•••",
      "author_username": "•••",
      "author_id": "•••",
      "author_url": "https://www.youtube.com/•••",
      "like_count": 867,
      "comment_count": 194,
      "view_count": 7618,
      "duration": "00:42:07",
      "posted_at": "2026-08-17T05:39:08+00:00",
      "platform": "youtube"
    },
    {
      "id": "DZuMFAlLrmE",
      "url": "https://www.youtube.com/watch?v=DZuMFAlLrmE",
      "title": "How to Fill a Raised Garden Bed for FREE!",
      "text": "Instead of buying expensive soil, I filled this garden bed organically with stuff I had lying around!\n\nHere’s the free recipe:\n🟫 Cardboard — weed blocker + worm buffet\n🌿 Old sticks — drainage + spongey structure (the older, the better)\n🍂 Dried leaves — quick compost, full of micr…",
      "author_name": "•••",
      "author_username": "•••",
      "author_id": "•••",
      "author_url": "https://www.youtube.com/•••",
      "like_count": 86115,
      "comment_count": 1232,
      "view_count": 2811422,
      "duration": "00:00:58",
      "posted_at": "2025-06-21T21:47:59+00:00",
      "platform": "youtube"
    }
  ],
  "count": 10,
  "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
