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

# API 令牌管理

> 通过用户管理 API 管理自己的 API 令牌。

用户管理 API 适合自动化脚本或内部控制台集成。日常创建和删除 API 令牌，优先使用 [AIOHub API 令牌管理](https://api.aiohub.org/console/token)。

<Note>管理 API 与模型调用 API 分开鉴权。通过控制台调用时可使用当前登录会话；脚本调用时使用管理访问令牌，并带上对应的 `New-Api-User` 请求头。模型调用使用的 `sk-` API 令牌不能作为管理凭证。</Note>

## 获取 API 令牌列表

```text theme={"system"}
GET /api/token/
```

返回当前用户可管理的 API 令牌列表。列表中的 `key` 字段可能是脱敏值。

## 创建 API 令牌

```text theme={"system"}
POST /api/token/
```

```json theme={"system"}
{
  "name": "codex",
  "remain_quota": 0,
  "expired_time": -1,
  "unlimited_quota": true,
  "model_limits_enabled": false,
  "model_limits": "",
  "group": "auto",
  "cross_group_retry": true,
  "allow_ips": ""
}
```

<ParamField path="name" type="string" required>
  API 令牌名称。建议按用途命名，例如 `claude-code`、`codex`、`cherry-studio`。
</ParamField>

<ParamField path="remain_quota" type="integer">
  API 令牌可用额度。设置 `unlimited_quota` 为 `true` 时，此字段不限制 API 令牌。
</ParamField>

<ParamField path="expired_time" type="integer">
  Unix 时间戳。`-1` 表示不过期。
</ParamField>

<ParamField path="unlimited_quota" type="boolean">
  是否不限制 API 令牌额度。账户总余额仍会正常扣费。
</ParamField>

<ParamField path="model_limits_enabled" type="boolean">
  是否启用模型白名单限制。
</ParamField>

<ParamField path="model_limits" type="string">
  模型白名单。启用模型限制时填写。
</ParamField>

<ParamField path="group" type="string">
  API 令牌所属分组。多个分组用逗号分隔，例如 `codex,codex-passthrough`。
</ParamField>

<ParamField path="cross_group_retry" type="boolean">
  是否允许跨分组重试。通常与 `auto` 或多分组 API 令牌一起使用。
</ParamField>

<ParamField path="allow_ips" type="string">
  允许使用该 API 令牌的来源 IP 列表。留空表示不限制。
</ParamField>

## 查询 API 令牌

```text theme={"system"}
GET /api/token/{id}
```

<ParamField path="id" type="integer" required>
  API 令牌 ID。
</ParamField>

## 复制完整 API 令牌

```text theme={"system"}
POST /api/token/{id}/key
```

返回你自己的完整 API 令牌值。只在受信任环境中调用，不要把结果暴露给页面脚本、日志或其他不可信环境。

## 更新 API 令牌

```text theme={"system"}
PUT /api/token/
```

请求体使用与创建 API 令牌相同的字段，并包含目标 API 令牌 ID。只切换启用/禁用状态时，可使用 `status_only`。

## 删除 API 令牌

```text theme={"system"}
DELETE /api/token/{id}
```

删除后，该 API 令牌无法继续调用模型 API。已经发出的请求不一定会被立即中断。

## 搜索 API 令牌

```text theme={"system"}
GET /api/token/search?keyword=claude
```

<ParamField path="keyword" type="string">
  按 API 令牌名称搜索。
</ParamField>

## 使用边界

* 只记录和操作你自己的 API 令牌。
* 不要用管理 API 文档推断管理员接口；管理员能力不属于公开文档范围。
* 自动化脚本应先处理登录态过期、403 权限不足和 429 频率限制。
