APIs API Keys 管理 模块 API 文档

基础信息


数据库表


接口列表

1. 获取 API Keys 列表

GET /api/admin/api-keys

Query 参数:

参数类型必填说明
bill_idstring选填账单ID
providerstring选填供应商(openai/anthropic 等)
is_activeboolean选填是否有效(未撤销)

响应:

[{
  "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_idstring必填所属账单ID
providerstring必填供应商(openai/anthropic 等)
api_keystring必填API Key 明文(加密存储)
modelstring选填指定模型(如 gpt-4o)
expires_atstring选填过期时间 ISO8601
is_sharedboolean选填是否共享给账单成员(默认 false)
priorityinteger选填优先级(默认 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 }