---
name: tkkit-open-api
description: >-
  Integrate with TKKIT Open API v1: TikTok live discovery & room viewer counts,
  Android 4-mode search & native filters, user profiles & follower/following relations,
  watermark-free media extraction/download, post stats & paginated comments,
  Outlook verification code retrieval, and API key quota checks. Use whenever the user
  asks to call, integrate, script, or debug TKKIT Open API endpoints.
---

# TKKIT Open API v1 — Agent Integration Skill

Canonical machine-readable endpoint catalog for **TKKIT Open API v1** at `https://tikkit.mdclaw.ai`.

## Base URL & Authentication

- **Base URL**: `https://tikkit.mdclaw.ai`
- **API Key Format**: `tk_live_<32-char-base64url>` (read from environment variable `TKKIT_API_KEY`; NEVER hardcode secrets into source files or client bundles).
- **Auth Headers** (either works on all authenticated endpoints):
  - `Authorization: Bearer $TKKIT_API_KEY`
  - `X-API-Key: $TKKIT_API_KEY`
- **Public Health Check**: `GET /api/v1/health` requires **no** API key and consumes 0 quota.
- **Key Self-Check**: Call `GET /api/v1/me` first to verify key validity, active tier, remaining daily quota, and per-minute rate limit.

## Response Envelope & Standard Headers

All JSON endpoints return a consistent wrapper:

```json
{
  "success": true,
  "data": {},
  "request_id": "uuid",
  "usage": { "quota": 5000, "used": 12, "remaining": 4988, "reset_at": "2026-11-25T16:00:00.000Z", "units": 1 }
}
```

- Failed requests return `success: false` with `error: { code, message }` and matching HTTP 4xx/5xx status.
- Batch endpoints (`/api/v1/live/counts`, `/api/v1/posts/stats`) return HTTP `200` with `data.partial: true` when individual items fail; always inspect each item's `error` field instead of assuming all items succeeded.

### Standard Response Headers

| Header | Description | Example |
| --- | --- | --- |
| `X-Request-Id` | 每次请求的唯一 UUID，排查问题与工单对齐时请提供该值。 | `9d0b4b0e-2f1b-4b6d-a9f5-8b1d6c4a2e10` |
| `X-Quota-Limit` | 当前账号今日有效 API 调用总额度。 | `5000` |
| `X-Quota-Used` | 当前账号今日已累计使用的调用次数。 | `12` |
| `X-Quota-Remaining` | 今日剩余可用调用次数。 | `4988` |
| `X-Quota-Reset` | 下次额度重置时间（UTC；北京时间次日 0 点即 UTC 当日 16:00）。 | `2026-11-25T16:00:00.000Z` |
| `X-RateLimit-Limit` | 每分钟请求上限；0 表示当前密钥不限速。 | `120` |
| `X-RateLimit-Remaining` | 当前分钟窗口剩余请求数。 | `118` |
| `X-RateLimit-Reset` | 当前分钟窗口重置的 UTC 时间。 | `2026-11-25T10:15:00.000Z` |
| `Server-Timing` | 网关分段耗时追踪（auth_db / admission / business / api_total 等，单位 ms）。 | `auth;dur=12.40, business;dur=320.15, api_total;dur=341.02` |

## Quotas & Rate Limits

- Daily quotas accumulate per **Beijing Time natural day (UTC+8)** and reset at `00:00` CST (`16:00:00Z` UTC). All keys under one account share the account daily quota.
- When `429` (`QUOTA_EXCEEDED`, `KEY_QUOTA_EXCEEDED`, `RATE_LIMITED`) is returned, respect the `Retry-After` response header (seconds) before retrying.

| Tier | Daily Quota | Rate Limit | Max Active Keys |
| --- | --- | --- | --- |
| 免费版 (`free`) | 100 次/天 | 30 次/分钟 | 2 把 |
| 专业版 (`pro`) | 5,000 次/天 | 120 次/分钟 | 10 把 |
| 企业版 (`enterprise`) | 50,000 次/天 | 600 次/分钟 | 50 把 |

## Critical Workflows & Implementation Rules

1. **Async Live Discovery Workflow** (`POST /api/v1/live/discovery/tasks`):
   - Returns HTTP `202` with `data.task.id`. Max **3** active (`queued` / `running`) tasks per account.
   - Send `Idempotency-Key` header on task creation to safely retry network errors without creating duplicate tasks.
   - Poll `GET /api/v1/live/discovery/tasks/{taskId}/results?cursor=<next_cursor>&limit=100&order=asc` incrementally, and check `GET /api/v1/live/discovery/tasks/{taskId}` for overall status (`completed`, `partial`, `failed`, `cancelled`).
   - Stop polling only when `status` is terminal AND `has_more === false`. Use `DELETE /api/v1/live/discovery/tasks/{taskId}` to cancel early.
2. **Android Search & Native Filters**:
   - Fetch `GET /api/v1/search/filters` first to discover valid integer/string filter codes for `kind=user` and `kind=video`.
   - `min_followers` / `max_followers` only apply to `kind=user` and exclude users whose follower count is unknown (`unknown_followers`).
3. **Watermark-Free Media Download**:
   - Do **not** fetch `media[].url` directly from unauthenticated scripts without TikTok CDN cookies — it often returns HTTP 403.
   - Always download via `GET /api/v1/posts/media/download?url=<item_id>&index=<n>` (or `media[].download_url`) with your `TKKIT_API_KEY` header; the gateway relays with valid session cookies and auto-retries expired signatures.
4. **Paginated Comments & Relations**:
   - Comments (`POST /api/v1/posts/comments`): start with `cursor: 0`, pass back `data.cursor` while `data.has_more === true`, and deduplicate by `cid`.
   - User profiles & relations: preserve leading `@` for numeric-only TikTok usernames.
5. **Outlook Verification Codes**:
   - Call `GET /api/v1/email/accounts` to list authorized mailboxes (`max 20`), then poll `GET /api/v1/email/codes?email=...`. Default `sync=1` has an 8-second upstream throttle; pass `sync=0` for cache-only reads.
6. **Cache Bypass**:
   - Pass header `X-Cache-Force: 1` on `/api/v1/users/profile` (60s cache), `/api/v1/users/relations` (15s cache), `/api/v1/live/counts` (10s cache), and `/api/v1/posts/media` (5m cache) when fresh upstream reads are required.

## Endpoints Reference

<!-- Group: 账户与系统 -->
### 查询额度与用量 (`GET /api/v1/me`)

- **Supported Methods**: `GET`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 0 点（计入每日调用次数）
- **Cache**: 实时计算
- **Summary**: 校验当前 API Key 的有效性，返回密钥信息、所属套餐、今日实时消耗与可用端点列表。

**Parameters**: None.

**Response Fields**:

- `data.key` (`object`): 当前密钥 ID、名称、脱敏前缀、状态、到期时间与最近使用时间。
- `data.owner` (`object`): 密钥归属用户 ID、昵称、邮箱、有效套餐（free / pro / enterprise）。
- `data.quota` (`object`): 每日总额度 daily_limit、已用 used、剩余 remaining、UTC 重置时间 reset_at 与每分钟限速。
- `data.today` (`object`): 今日用户总请求、本密钥成功/失败/拒绝次数、累计点数与平均耗时。
- `data.endpoints` (`array`): 当前版本开放的端点摘要清单。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/me" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```

### 网关健康检查 (`GET /api/v1/health`)

- **Supported Methods**: `GET`
- **Authentication**: None (public endpoint)
- **Billing**: 0 点（无需鉴权）
- **Cache**: no-store
- **Summary**: 检测 API 网关与服务器当前时间戳；无需传递 API Key，不消耗每日调用额度。

**Parameters**: None.

**Response Fields**:

- `success` (`boolean`): 服务健康状态，正常固定返回 true。
- `service` (`string`): 服务标识，固定为 "tkkit-api"。
- `version` (`string`): 当前 API 版本号 "v1"。
- `time` (`string`): 服务端当前 UTC ISO-8601 时间戳。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/health" \
```

<!-- Group: 搜索与筛选 -->
### Android 关键词搜索 (`POST /api/v1/search`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 按实际读取页数计点（pages_fetched）
- **Cache**: 不缓存（实时请求）
- **Summary**: 按关键词搜索 TikTok 用户、直播、视频和图文。用户搜索支持原生粉丝档位与自定义粉丝上下限；视频搜索支持排序、类别与发布时间筛选。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `keyword` | `body` | `string` | Yes | 1–200 字符，禁止控制字符 | 搜索关键词；GET 请求时作为 query 参数传递。 |
| `kind` | `body` | `string` | No | default: `user`; enum: `user`, `live`, `video`, `photo` | 搜索对象类型：用户（user）、直播（live）、视频（video）或图文（photo）。 |
| `pages` | `body` | `integer` | No | default: `1`; 1–1000 | 连续翻页读取的最大页数，实际消耗点数等于 pages_fetched。 |
| `filters` | `body` | `object` | No | — | 原版筛选对象（GET 请求传 JSON 字符串）。kind=user 支持 follower_number (0–4)、profile_type (0–3)、preference (0–1)；kind=video 支持 sort / category / publish_date。 |
| `min_followers` | `body` | `integer` | No | ≥ 0，仅 kind=user | 按已读取结果做自定义最低粉丝数过滤（含边界），粉丝数未知记录会被排除。 |
| `max_followers` | `body` | `integer` | No | ≥ min_followers，仅 kind=user | 按已读取结果做自定义最高粉丝数过滤（含边界）。 |

**Response Fields**:

- `data.kind` (`string`): 本次搜索类型（user / live / video / photo）。
- `data.count` (`integer`): 过滤后实际返回的记录条数。
- `data.pages_fetched` (`integer`): 本次实际请求的上游页数（计费点数依据）。
- `data.has_more` (`boolean`): 上游是否还有更多分页。
- `data.users / rooms / posts` (`array`): 按 kind 分别返回用户、直播间或作品对象数组。
- `data.candidate_count / unknown_followers` (`integer`): 仅 kind=user 返回：过滤前候选数与粉丝未知被排除人数。

**Endpoint Errors**:

- `INVALID_SEARCH` (HTTP 400): 关键词为空/超长、页数越界或筛选编号非法。
- `ANDROID_SEARCH_BUSY` (HTTP 503): 搜索服务繁忙，请稍后重试。
- `ANDROID_SEARCH_UNAVAILABLE` (HTTP 503): 搜索服务暂时不可用，请联系管理员。
- `ANDROID_SEARCH_TIMEOUT` (HTTP 504): 搜索请求超时（90 秒），请稍后重试。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/search" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"keyword":"cooking","kind":"user","pages":2,"filters":{"follower_number":2,"profile_type":0,"preference":0},"min_followers":1000,"max_followers":10000}'
```

### 获取搜索筛选项 (`GET /api/v1/search/filters`)

- **Supported Methods**: `GET`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 0 点（计入每日调用次数）
- **Cache**: 实时读取
- **Summary**: 拉取当前 Android 用户和视频搜索支持的原版筛选组、编号（code）与中文标签。

**Parameters**: None.

**Response Fields**:

- `data.user` (`object`): 用户搜索筛选字典，含 follower_number、profile_type、preference 的标题及 code/label 选项。
- `data.video` (`object`): 视频搜索筛选字典，含 sort、category、publish_date 的 code/label 选项。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/search/filters" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```

<!-- Group: 用户与关系 -->
### 查询用户资料 (`POST /api/v1/users/profile`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 1 点
- **Cache**: 60 秒内存缓存
- **Summary**: 通过 @用户名、数字 UID 或 MS4w 开头的 sec_uid 查询 TikTok 账号资料、粉丝数、关注数、获赞与作品数。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `target` | `body` | `string` | Yes | 1–512 字符 | 目标账号标识：@用户名、纯数字 UID 或 MS4w... sec_uid；纯数字用户名请务必保留前导 @。 |
| `X-Cache-Force` | `header` | `string` | No | default: `0`; enum: `1` | 传 1 时跳过 60 秒内存缓存直接回源刷新。 |

**Response Fields**:

- `data.user.uid / sec_uid` (`string`, nullable): 账号唯一数字 UID 与加密 sec_uid。
- `data.user.username / nickname` (`string`, nullable): handle 用户名与显示昵称。
- `data.user.signature / avatar_url` (`string`, nullable): 个性签名与 HTTPS 头像地址。
- `data.user.follower_count / following_count` (`integer`, nullable): 粉丝数与关注数；上游未下发时返回 null。
- `data.user.like_count / aweme_count` (`integer`, nullable): 总获赞数与作品总数。
- `data.cached` (`boolean`): 本次结果是否命中 60 秒内存缓存。

**Endpoint Errors**:

- `INVALID_TARGET` (HTTP 400): 用户名、UID 或 sec_uid 格式不正确。
- `ANDROID_PROFILE_MISMATCH` (HTTP 502): 上游返回的资料与请求目标不一致。
- `ANDROID_PROFILE_TIMEOUT` (HTTP 504): 资料后端响应超时（65 秒）。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/users/profile" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"target":"@ankoru5"}'
```

### 查询关注 / 粉丝列表 (`POST /api/v1/users/relations`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 按实际翻页数计点（至少 1 点）
- **Cache**: 15 秒内存缓存
- **Summary**: 读取指定目标账号的公开粉丝列表或关注列表，自动按 UID 去重并返回分页记录与终止原因。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `target` | `body` | `string` | Yes | — | 目标账号 @用户名、数字 UID 或 sec_uid。 |
| `kind` | `body` | `string` | Yes | enum: `followers`, `following` | 查询方向：followers（粉丝列表）或 following（关注列表）。 |
| `pages` | `body` | `integer` | No | default: `1`; 1–10 | 最多连续抓取的页数，计费点数等于实际抓取页数。 |
| `count` | `body` | `integer` | No | default: `20`; 1–50 | 期望每页返回的用户数。 |
| `X-Cache-Force` | `header` | `string` | No | enum: `1` | 传 1 时跳过 15 秒内存缓存。 |

**Response Fields**:

- `data.user_id / sec_user_id` (`string`): 解析出的目标账号 UID 与 sec_uid。
- `data.total / raw_count / unique_count` (`integer`): 账号总关系数、原始拉取总数与 UID 去重后数量。
- `data.has_more / stop_reason` (`boolean / string`): 达到页数上限时是否仍有续页依据，以及停止原因（如 page_limit / no_more）。
- `data.pages` (`array`): 每页的原始数量、去重后新增数量、游标和 TikTok 返回的 has_more。
- `data.users` (`array`): 去重后的关联用户列表，包含粉丝数、地区、关注状态等。

**Endpoint Errors**:

- `INVALID_TARGET` (HTTP 400): 目标账号标识格式错误。
- `INVALID_KIND` (HTTP 400): kind 必须为 following 或 followers。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/users/relations" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"target":"@abdullah.chamkani80","kind":"followers","pages":2,"count":1}'
```

<!-- Group: 直播数据 -->
### 批量查询直播间在线人数 (`POST /api/v1/live/counts`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 按传入 room_id 个数计点
- **Cache**: 10 秒内存缓存
- **Summary**: 通过 Android 批量接口查询 1–50 个直播间的实时在线人数、累计观看、开播状态与主播昵称。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `room_ids` | `body` | `string[] \| string` | Yes | 1–50 个，每个为 1–25 位纯数字 | 直播间 room_id 数组；GET 请求可传逗号分隔字符串或重复多个 room_ids 参数。 |
| `room_id` | `body` | `string` | No | — | 单房间查询简写字段，与 room_ids 二选一即可。 |
| `X-Cache-Force` | `header` | `string` | No | enum: `1` | 传 1 时绕过 10 秒内存缓存直接回源。 |

**Response Fields**:

- `data.results` (`array`): 按入参顺序返回每个房间：room_id、live、online、total_viewers、status、title、anchor、nickname、started_at、cached、error。
- `data.count / live / cached / invalid` (`integer`): 返回总数、开播中数量、命中缓存条数与格式非法条数。
- `data.partial` (`boolean`): 存在部分房间上游拉取异常时为 true（仍返回 HTTP 200）。

**Endpoint Errors**:

- `MISSING_ROOM_IDS` (HTTP 400): 未提供有效的 room_ids 或 room_id。
- `BATCH_TOO_LARGE` (HTTP 413): 单次请求超过 50 个 room_id 上限。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/live/counts" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"room_ids":["7704642891406265110"]}'
```

### 创建直播间发现任务 (`POST /api/v1/live/discovery/tasks`)

- **Supported Methods**: `POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 0 点（受并发任务数限制）
- **Cache**: 异步队列（单用户最多 3 个并发任务）
- **Summary**: 提交异步直播间扫描任务，按人数门槛、分类和代理抓取合格直播间；支持游标增量 Pull 与逐房间 Webhook Push。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `proxy_id` | `body` | `string` | No | — | 管理员启用的代理配置 ID；与内联 proxy 对象二选一。 |
| `target_count` | `body` | `integer` | No | default: `100`; 1–1000 | 期望采集到的合格直播间数量上限，达到后自动结束。 |
| `min_viewers` | `body` | `integer` | No | default: `1000`; 0–1000000000 | 合格直播间最低在线人数门槛。 |
| `max_viewers` | `body` | `integer` | No | ≥ min_viewers | 可选最高在线人数上限。 |
| `categories` | `body` | `string[]` | No | default: `["all"]` | 扫描分类列表，支持 all（须单独使用）、top_live 或 game:<游戏名>（最多 21 项）。 |
| `timeout_seconds` | `body` | `integer` | No | default: `900`; 30–3600 | 任务最大运行时长预算（秒）。 |
| `pages_per_category` | `body` | `integer` | No | default: `5`; 1–20 | 每个分类最多向后扫描的页数。 |
| `freshness_seconds` | `body` | `integer` | No | default: `120`; 30–300 | 快照结果新鲜度有效期（秒）。 |
| `webhook_url / webhook_secret` | `body` | `string` | No | HTTPS 白名单主机；secret ≥ 16 字符 | 可选逐房间推送接收地址及签名密钥；自动兼容飞书/Lark 机器人地址。 |
| `Idempotency-Key` | `header` | `string` | No | 1–128 字符 | 幂等请求键；同键同配置重放返回 replayed: true，不同配置返回 409。 |

**Response Fields**:

- `data.task.id` (`string`): 任务唯一 UUID，用于后续查询进度、增量拉取或取消。
- `data.task.status` (`string`): 初始状态 queued，随后变为 running / completed / partial / failed / cancelled。
- `data.replayed` (`boolean`): 是否命中了 Idempotency-Key 幂等重放。
- `data.webhook_secret` (`string`): 仅开启 Webhook 时返回实际生效的签名密钥。

**Endpoint Errors**:

- `INVALID_PROXY_ID` (HTTP 400): 指定的 proxy_id 未启用或不存在。
- `INVALID_WEBHOOK` (HTTP 400): Webhook 非 HTTPS 或不在管理员允许的白名单主机内。
- `IDEMPOTENCY_CONFLICT` (HTTP 409): 相同 Idempotency-Key 传入了不同的请求参数。
- `TOO_MANY_TASKS` (HTTP 429): 当前账号进行中的发现任务已达 3 个上限。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/live/discovery/tasks" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"proxy_id":"my-proxy","target_count":100,"min_viewers":1000,"categories":["all"],"timeout_seconds":900,"pages_per_category":5}'
```

### 查询发现任务进度 (`GET /api/v1/live/discovery/tasks/{taskId}`)

- **Supported Methods**: `GET`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 0 点
- **Cache**: 实时读取（含自动过期检查）
- **Summary**: 读取指定直播间发现任务的当前运行状态、已扫描页数、合格房间计数与 Webhook 投递统计。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `taskId` | `path` | `string` | Yes | — | 创建任务时返回的 task.id。 |

**Response Fields**:

- `data.status / reason` (`string`): 任务状态及结束原因（target_reached / deadline_reached / user_cancelled）。
- `data.discovered_total / qualified_count` (`integer`): 累计发现与满足人数门槛的合格房间数。
- `data.progress` (`object`): 当前页数、重试次数与跳过分类数等执行进度。
- `data.delivery` (`object`): Webhook 逐房间投递汇总（total / sent / pending / failed）。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/live/discovery/tasks/{taskId}" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```

### 游标增量拉取结果 (`GET /api/v1/live/discovery/tasks/{taskId}/results`)

- **Supported Methods**: `GET`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 0 点
- **Cache**: 实时查询
- **Summary**: 按 sequence 游标增量拉取任务已发现的合格直播间快照，支持正序边抓边取与倒序从最新回溯。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `taskId` | `path` | `string` | Yes | — | 任务 UUID。 |
| `cursor` | `query` | `integer` | No | default: `0`; ≥ 0 | 上次响应返回的 next_cursor，首次拉取传 0。 |
| `limit` | `query` | `integer` | No | default: `20`; 1–100 | 单次拉取返回的最大合格房间数。 |
| `order` | `query` | `string` | No | default: `asc`; enum: `asc`, `desc` | 排序方向：asc 从旧到新，desc 从最新往前翻。 |

**Response Fields**:

- `data.results` (`array`): 合格直播间列表，含 sequence、room_id、username、viewer_count、observed_at、valid_until。
- `data.next_cursor` (`integer`): 下一页拉取游标。
- `data.has_more` (`boolean`): 当前是否还有更多未拉取结果。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/live/discovery/tasks/{taskId}/results?cursor=0&limit=20&order=asc" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```

### 取消发现任务 (`DELETE /api/v1/live/discovery/tasks/{taskId}`)

- **Supported Methods**: `DELETE`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 0 点
- **Cache**: 即时生效
- **Summary**: 立即终止指定直播间发现任务，释放账号租约并保留已采集到的历史结果。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `taskId` | `path` | `string` | Yes | — | 要取消的任务 ID。 |

**Response Fields**:

- `data.status` (`string`): 更新为 "cancelled"。
- `data.reason` (`string`): 固定记录为 "user_cancelled"。

**Example Request**:

```bash
curl -X DELETE "https://tikkit.mdclaw.ai/api/v1/live/discovery/tasks/{taskId}" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```

<!-- Group: 作品与媒体 -->
### 批量查询作品统计 (`POST /api/v1/posts/stats`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 按去重后作品条数计点
- **Cache**: 5 分钟 KV 缓存
- **Summary**: 批量查询 TikTok 视频或图文作品的点赞、评论、播放、分享、作者、封面与音乐信息，单次最多 10 条。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `urls` | `body` | `string[] \| string` | Yes | 1–10 条，支持完整链接、短链 ID 或纯数字 item_id | 作品链接数组；GET 请求可传逗号分隔字符串或多个 urls 参数。 |
| `url` | `body` | `string` | No | — | 单条作品简写参数，与 urls 二选一。 |

**Response Fields**:

- `data.results` (`array`): 每条作品统计：item_id、source (embed/ssr)、author、likes、comments、plays、shares、is_slideshow、cover、error。
- `data.count / cached / partial` (`integer / boolean`): 返回条数、命中缓存条数与是否包含单条失败。

**Endpoint Errors**:

- `MISSING_URLS` (HTTP 400): 未提供有效的 urls 或 url 参数。
- `BATCH_TOO_LARGE` (HTTP 413): 单次请求超过 10 条作品上限。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/posts/stats" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"urls":["https://www.tiktok.com/@user/video/7650064071173393685"]}'
```

### 解析无水印媒体直链 (`POST /api/v1/posts/media`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 1 点
- **Cache**: 5 分钟 KV 缓存
- **Summary**: 解析单个视频或图文作品的无水印原片直链（多码率清晰度）或高清原图列表，附带经 API 代理转发的稳定 download_url。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `url` | `body` | `string` | Yes | — | TikTok 作品链接或 15–25 位纯数字作品 ID（兼容 id 字段）。 |
| `X-Cache-Force` | `header` | `string` | No | enum: `1` | 直链过期时传 1 强制重新解析签名直链与会话 Cookie。 |

**Response Fields**:

- `data.type / media_count` (`string / integer`): 媒体类型（video / photo）与文件数量。
- `data.media` (`array`): 素材列表：kind、index、format、quality、width、height、url、filename、download_url。
- `data.media[].download_url` (`string`): 指向 /api/v1/posts/media/download 的代理下载地址，需带 API Key 访问。

**Endpoint Errors**:

- `MISSING_URL` (HTTP 400): 缺少作品链接或作品 ID。
- `INVALID_ITEM_URL` (HTTP 400): 无法从输入内容中解析出有效作品 ID。
- `POST_NOT_ACCESSIBLE` (HTTP 404): 作品不存在、已删除或设为私密。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/posts/media" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://www.tiktok.com/@alice/video/7650064071173393685"}'
```

### 代理下载媒体二进制流 (`GET /api/v1/posts/media/download`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 1 点
- **Cache**: 签名失效自动刷新重试
- **Summary**: 将无水印视频或图集原图通过 API 网关携带会话 Cookie 与代理中转成附件二进制流下载；签名过期自动重试。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `url` | `query` | `string` | Yes | — | TikTok 作品链接或作品 ID（兼容 id 字段）。 |
| `index` | `query` | `integer` | No | default: `0`; 0 ≤ index < media_count | 对应 /api/v1/posts/media 返回的 media 数组下标（兼容参数 i）。 |

**Response Fields**:

- `Content-Type` (`header`): 媒体真实 MIME / 格式类型，如 video/mp4 或 image/jpeg。
- `Content-Disposition` (`header`): 附件下载文件名（UTF-8 编码兼容）。
- `X-Media-Source` (`header`): 本次流下载所经通道来源（relay / direct）。

**Endpoint Errors**:

- `INVALID_MEDIA_INDEX` (HTTP 400): index 必须是从 0 开始的整数。
- `MEDIA_INDEX_OUT_OF_RANGE` (HTTP 400): index 超出了该作品实际包含的媒体文件总数。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/posts/media/download?url=7650064071173393685&index=0" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```

### 获取作品评论列表 (`POST /api/v1/posts/comments`)

- **Supported Methods**: `POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 每次翻页 1 点
- **Cache**: 实时分页
- **Summary**: 按游标翻页抓取作品公开评论正文、点赞数、回复数与评论者信息；适合互动洞察与舆情采集。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `url` | `body` | `string` | Yes | — | TikTok 作品链接或纯数字作品 ID。 |
| `cursor` | `body` | `integer` | No | default: `0`; ≥ 0 | 分页游标；首次传 0，下一页传入上次返回的 data.cursor。 |
| `count` | `body` | `integer` | No | default: `20`; 1–50 | 每页期望返回评论条数。 |

**Response Fields**:

- `data.item_id` (`string`): 解析出的作品 ID。
- `data.cursor / has_more / total` (`integer / boolean`): 下一页游标、是否还有更多评论与总评论数。
- `data.comments` (`array`): 评论对象列表，含 cid、user、nickname、user_id、text、likes、replies、created。

**Endpoint Errors**:

- `INVALID_ITEM_URL` (HTTP 400): url 无法解析出有效 TikTok 作品 ID。
- `COMMENTS_SCHEMA` (HTTP 502): 上游评论返回结构发生变更或不可解析。

**Example Request**:

```bash
curl -X POST "https://tikkit.mdclaw.ai/api/v1/posts/comments" \
  -H "Authorization: Bearer $TKKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"7650064071173393685","cursor":0,"count":20}'
```

<!-- Group: 邮箱接码 -->
### 列出已授权接码邮箱 (`GET /api/v1/email/accounts`)

- **Supported Methods**: `GET`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 1 点
- **Cache**: 实时读取
- **Summary**: 返回当前 TKKIT 账号下已通过微软委托授权绑定的自有 Outlook / Hotmail 邮箱清单，绝不返回任何 Token。

**Parameters**: None.

**Response Fields**:

- `data.accounts` (`array`): 已授权邮箱列表，含 id、email、display_name、provider、status、last_error、last_synced_at。
- `data.limit` (`integer`): 单账号允许绑定的最大邮箱数上限（20）。

**Endpoint Errors**:

- `EMAIL_NOT_CONFIGURED` (HTTP 503): 服务端尚未配置 MS_GRAPH_CLIENT_ID。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/email/accounts" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```

### 读取邮箱验证码 (`GET /api/v1/email/codes`)

- **Supported Methods**: `GET / POST`
- **Authentication**: Required (`Authorization: Bearer` or `X-API-Key`)
- **Billing**: 1 点
- **Cache**: 8 秒同步节流
- **Summary**: 按已授权邮箱地址读取收件箱与垃圾箱最近提取出的安全验证码；默认触发同步（带 8 秒微软 Graph 节流）。

**Parameters**:

| Name | In | Type | Required | Default / Constraints | Description |
| --- | --- | --- | --- | --- | --- |
| `email` | `query` | `string` | Yes | — | 当前 TKKIT 账号下已授权的 Outlook / Hotmail 邮箱地址。 |
| `since_minutes` | `query` | `integer` | No | default: `15`; 1–1440 | 检索时间窗口（分钟）。 |
| `limit` | `query` | `integer` | No | default: `3`; 1–20 | 最多返回的验证码邮件条数。 |
| `folder` | `query` | `string` | No | default: `all`; enum: `all`, `inbox`, `junkemail` | 邮件目录筛选：全部（all）、收件箱（inbox）或垃圾箱（junkemail）。 |
| `sync` | `query` | `boolean \| 0 \| 1` | No | default: `1`; enum: `1`, `0` | 传 1 时先同步微软邮箱（受 8 秒节流保护），传 0 仅读取本地已入库缓存。 |

**Response Fields**:

- `data.latest` (`object`, nullable): 最新一条解析到的验证码对象，含 code、subject、from、received_at、folder。
- `data.codes` (`array`): 时间窗口内命中的多条验证码记录列表。
- `data.sync` (`object`): 本次是否实际拉取微软 Graph（fetched）、synced_at 与新增入库条数 stored。

**Endpoint Errors**:

- `MISSING_EMAIL` (HTTP 400): 缺少 email 参数。
- `EMAIL_ACCOUNT_NOT_FOUND` (HTTP 404): 该邮箱尚未在当前账号下授权。
- `EMAIL_AUTH_REQUIRED` (HTTP 409): 邮箱 Refresh Token 已失效，需回控制台重新授权。
- `EMAIL_GRAPH_RATE_LIMITED` (HTTP 503): 微软 Graph API 临时限流。

**Example Request**:

```bash
curl -X GET "https://tikkit.mdclaw.ai/api/v1/email/codes?email=you%40outlook.com&since_minutes=15&limit=3&folder=all&sync=1" \
  -H "Authorization: Bearer $TKKIT_API_KEY"
```


## Common Error Codes

| Code | HTTP Status | Description |
| --- | --- | --- |
| `MISSING_API_KEY` | 401 | 未在请求头提供 Authorization: Bearer 或 X-API-Key。 |
| `INVALID_API_KEY_FORMAT` | 401 | 密钥格式不符合 tk_live_ 前缀规范。 |
| `INVALID_API_KEY` | 401 | API Key 不存在或已被删除。 |
| `API_KEY_REVOKED` | 401 | 密钥已在工作台或后台停用。 |
| `API_KEY_EXPIRED` | 401 | 密钥已超过设置的到期时间。 |
| `API_DISABLED` | 403 | 账号每日额度被管理员设为 0。 |
| `API_KEY_DISABLED` | 403 | 当前密钥的每日上限被设为 0。 |
| `QUOTA_EXCEEDED` | 429 | 今日账号总调用额度已耗尽，北京时间次日 0 点重置。 |
| `KEY_QUOTA_EXCEEDED` | 429 | 单把密钥配置的每日独立上限已耗尽。 |
| `RATE_LIMITED` | 429 | 超过每分钟并发限速，请读取 Retry-After 秒数后退避重试。 |
| `INVALID_JSON` | 400 | POST 请求体不是合法的 JSON 对象。 |
| `INVALID_REQUEST` | 400 | 包含未知字段或整数参数超出合法范围。 |
| `PAYLOAD_TOO_LARGE` | 413 | JSON 请求体体积超过 64KB 上限。 |
| `BATCH_TOO_LARGE` | 413 | 批量请求条目数超过上限（直播 50 间 / 作品 10 条）。 |
| `UPSTREAM_BLOCKED` | 502 | 上游接口触发风控拦截，可配置或切换代理 relay 重试。 |
| `UPSTREAM_TIMEOUT` | 504 | 上游数据源响应超时，请稍后重试。 |
| `INTERNAL_ERROR` | 500 | 服务端内部处理异常，请携带 X-Request-Id 联系技术支持。 |
