> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keyapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 鉴权方式

> KeyAPI API 的请求认证方式。

## API Key

每一次 KeyAPI API 请求都必须携带 API Key。你可以在 [dashboard](https://keyapi.ai/app/dashboard) 中找到自己的 API Key。

<Warning>请妥善保管 API Key。不要把它暴露在前端代码或公开仓库中。</Warning>

## Bearer Authentication

KeyAPI 使用 **Bearer authentication**。请在 `Authorization` header 中传入你的 API Key。

<CodeGroup>
  ```bash cURL theme={null}
  curl -H "Authorization: Bearer YOUR_API_KEY" \
    "https://api.keyapi.ai/v1/tiktok/influencer/detail?unique_id=karladelatorre97"
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      "https://api.keyapi.ai/v1/tiktok/influencer/detail",
      params={"unique_id": "karladelatorre97"},
      headers={"Authorization": "Bearer YOUR_API_KEY"},
  )
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch(
    "https://api.keyapi.ai/v1/tiktok/influencer/detail?unique_id=karladelatorre97",
    {
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
    },
    }
  );
  ```
</CodeGroup>

## Response Envelope

所有接口都会返回一致的 JSON envelope：

```json theme={null}
{
  "code": 0,
  "message": "success",
  "data": { ... }
}
```

| 字段        | 类型              | 说明                  |
| --------- | --------------- | ------------------- |
| `code`    | integer         | `0` 表示成功，非 0 表示业务错误 |
| `message` | string          | 可读的状态说明             |
| `data`    | object \| array | 接口返回的数据主体           |

## Error Responses

| HTTP Status | 含义                     |
| ----------- | ---------------------- |
| `400`       | 请求参数无效                 |
| `401`       | API Key 缺失或无效          |
| `402`       | 余额或 credits 不足，需要充值或升级 |
| `403`       | 当前 API Key 无权访问该接口     |
| `429`       | 请求过于频繁，已触发限流           |
| `500`       | 服务端内部错误                |
