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

# 管理 API 密钥

> 管理 API 密钥是专门用于 ARouter 管理员操作的独立凭证 — 用于创建、列出和删除 API 密钥。不能用于 LLM 推理。

ARouter 使用两种具有不同权限的 API 密钥类型：

| 密钥类型          | 前缀             | 用途                          |
| ------------- | -------------- | --------------------------- |
| **标准 API 密钥** | `lr_live_...`  | LLM 推理，所有 `/v1/*` 端点        |
| **管理 API 密钥** | `lr_admin_...` | 密钥管理，仅限 `/api/v1/keys/*` 端点 |

管理密钥不能调用 `/v1/chat/completions` 或其他推理端点。标准密钥不能管理其他密钥。

## 创建管理 API 密钥

1. 前往 [ARouter 控制台](https://arouter.ai/keys)
2. 点击**新建密钥**
3. 选择**管理密钥**类型
4. 复制密钥 — 仅显示一次

## 使用场景

管理密钥专为以下场景设计：

* **CI/CD 流水线** — 在部署时轮换应用密钥
* **密钥配置服务** — 为每个用户或租户创建密钥
* **管理脚本** — 审计或清理未使用的密钥
* **Terraform / 基础设施即代码** — 管理密钥生命周期

## 密钥管理端点

所有管理端点都需要管理 API 密钥：

### 列出密钥

```bash theme={null}
curl https://api.arouter.ai/api/v1/keys \
  -H "Authorization: Bearer lr_admin_xxxx"
```

```json theme={null}
{
  "data": [
    {
      "hash": "abc123...",
      "name": "production-app",
      "label": "Production",
      "created_at": "2026-01-01T00:00:00Z",
      "last_used_at": "2026-04-01T12:00:00Z",
      "usage": {"prompt_tokens": 1500000, "completion_tokens": 450000, "cost": 12.50},
      "limit_usd": 100.0,
      "rate_limit": {"requests_per_minute": 100}
    }
  ]
}
```

### 创建密钥

```bash theme={null}
curl -X POST https://api.arouter.ai/api/v1/keys \
  -H "Authorization: Bearer lr_admin_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "staging-app",
    "label": "Staging",
    "limit_usd": 25.0,
    "allowed_models": ["openai/gpt-5.4", "anthropic/claude-sonnet-4.6"]
  }'
```

**响应：**

```json theme={null}
{
  "key": "lr_live_xxxx...",
  "hash": "def456...",
  "name": "staging-app"
}
```

<Note>
  `key` 值**仅在创建时返回一次**。请安全存储 — 之后无法再次获取。
</Note>

### 更新密钥

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/{key_hash} \
  -H "Authorization: Bearer lr_admin_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "Staging (v2)",
    "limit_usd": 50.0
  }'
```

### 删除密钥

```bash theme={null}
curl -X DELETE https://api.arouter.ai/api/v1/keys/{key_hash} \
  -H "Authorization: Bearer lr_admin_xxxx"
```

```json theme={null}
{"deleted": true, "hash": "def456..."}
```

***

## 密钥对象参考

| 字段                               | 类型               | 说明                      |
| -------------------------------- | ---------------- | ----------------------- |
| `hash`                           | `string`         | 唯一密钥标识符（可安全存储，不是密钥本身）   |
| `name`                           | `string`         | 供您参考的内部名称               |
| `label`                          | `string`         | 控制台中显示的标签               |
| `created_at`                     | `string`         | ISO 8601 创建时间戳          |
| `last_used_at`                   | `string`         | ISO 8601 最后使用时间戳        |
| `usage.prompt_tokens`            | `integer`        | 累计提示 token              |
| `usage.completion_tokens`        | `integer`        | 累计补全 token              |
| `usage.cost`                     | `number`         | 累计费用（美元）                |
| `limit_usd`                      | `number\|null`   | 消费限额。`null` = 不限制       |
| `rate_limit.requests_per_minute` | `integer\|null`  | 每分钟请求数限制。`null` = 不限制   |
| `allowed_models`                 | `string[]\|null` | 模型白名单。`null` = 允许所有模型   |
| `allowed_providers`              | `string[]\|null` | 服务商白名单。`null` = 允许所有服务商 |

***

## 自动密钥轮换

请参阅 [API 密钥轮换](/zh/guides/administration/api-key-rotation) 获取使用管理密钥进行零停机密钥轮换的完整指南。

## 相关文档

* [密钥管理](/zh/guides/key-management) — 从控制台管理密钥
* [API 密钥轮换](/zh/guides/administration/api-key-rotation) — 自动轮换策略
* [护栏](/zh/guides/features/guardrails) — 为密钥设置限制和策略
