APIs API Keys 管理 模块 API 文档
基础信息
- Base URL:
/api/admin - 认证方式: JWT Bearer Token
数据库表
api_keys— AI API Keys 表bills— 账单表users— 用户表
接口列表
1. 获取 API Keys 列表
GET /api/admin/api-keys
Query 参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| bill_id | string | 选填 | 账单ID |
| provider | string | 选填 | 供应商(openai/anthropic 等) |
| is_active | boolean | 选填 | 是否有效(未撤销) |
响应:
[{
"id": "string",
"bill_id": "string",
"bill_name": "string",
"owner_id": "string",
"owner_nickname": "string",
"owner_type": "user|bill",
"provider": "openai|anthropic|...",
"model": "gpt-4o|claude-3-5-sonnet-...",
"api_key_encrypted": "sk-...",
"is_shared": 0|1,
"priority": 1,
"expires_at": "ISO8601",
"revoked_at": "ISO8601|null",
"created_at": "ISO8601"
}]
2. 创建 API Key
POST /api/admin/api-keys
请求体:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| bill_id | string | 必填 | 所属账单ID |
| provider | string | 必填 | 供应商(openai/anthropic 等) |
| api_key | string | 必填 | API Key 明文(加密存储) |
| model | string | 选填 | 指定模型(如 gpt-4o) |
| expires_at | string | 选填 | 过期时间 ISO8601 |
| is_shared | boolean | 选填 | 是否共享给账单成员(默认 false) |
| priority | integer | 选填 | 优先级(默认 1) |
响应: {"success": true, "id": "string"}
3. 撤销 API Key
PUT /api/admin/api-keys/:id/revoke
说明: 将指定 API Key 标记为已撤销(revoked_at = now),撤销后该 Key 无法再使用
响应: {"success": true}
注意: 撤销操作不可逆,API Key 的 revoked_at 会被永久记录
POST/admin/api-keys
**说明**:新增 API Key。Key 存入前会 Base64 加密。
**请求参数**:
- `provider`(必填):供应商(如 deepseek/openai)
- `api_key`(必填):Key 明文(加密存储)
- `model`:模型名
- `bill_id`:关联账单 ID
- `owner_id`:拥有者用户 ID
- `owner_type`:拥有者类型(user/admin,默认为 user)
- `is_shared`:是否共享(0/1)
- `priority`:优先级(默认 100)
- `expires_at`:过期时间(可选)
**响应**:
{ success: true, id: "key_id" }
---
DELETE/admin/api-keys/:id
**说明**:删除指定 API Key。
**响应**:
{ success: true }