Skip to content
Request
Response

令牌管理

令牌管理接口用于管理 API 密钥。

接口地址

GET https://ai-tokenhub.com/v1/api-keys
POST https://ai-tokenhub.com/v1/api-keys
PUT https://ai-tokenhub.com/v1/api-keys/{id}
DELETE https://ai-tokenhub.com/v1/api-keys/{id}

API Key 对象

json
{
  "id": "key_xxx",
  "name": "Production Key",
  "key": "tkh_xxxxxxxxxxxx",
  "prefix": "tkh_",
  "status": "active",
  "permissions": {
    "models": ["gpt-4o", "gpt-4o-mini", "claude-3-opus"],
    "ip_whitelist": [],
    "rate_limit": 1000
  },
  "usage": {
    "total_requests": 50000,
    "total_tokens": 1000000,
    "last_used_at": "2024-01-01T12:00:00Z"
  },
  "created_at": "2024-01-01T00:00:00Z",
  "expires_at": null
}

获取密钥列表

bash
curl https://ai-tokenhub.com/v1/api-keys \
  -H "Authorization: Bearer YOUR_API_KEY"

创建密钥

bash
curl -X POST https://ai-tokenhub.com/v1/api-keys \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "New API Key",
    "permissions": {
      "models": ["gpt-4o-mini"],
      "rate_limit": 100
    },
    "expires_at": "2025-12-31T23:59:59Z"
  }'

响应示例

json
{
  "id": "key_xxx",
  "name": "New API Key",
  "key": "tkh_xxxxxxxxxxxx",
  "status": "active",
  "created_at": "2024-01-01T12:00:00Z",
  "expires_at": "2025-12-31T23:59:59Z"
}

更新密钥

bash
curl -X PUT https://ai-tokenhub.com/v1/api-keys/key_xxx \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "inactive",
    "permissions": {
      "models": ["gpt-4o"]
    }
  }'

删除密钥

bash
curl -X DELETE https://ai-tokenhub.com/v1/api-keys/key_xxx \
  -H "Authorization: Bearer YOUR_API_KEY"

轮换密钥

bash
curl -X POST https://ai-tokenhub.com/v1/api-keys/key_xxx/rotate \
  -H "Authorization: Bearer YOUR_API_KEY"

字段说明

字段类型说明
idstring密钥唯一标识
namestring密钥名称
keystring密钥值 (仅创建时返回完整)
prefixstring密钥前缀
statusstring状态 (active/inactive)
permissionsobject权限配置
usageobject使用统计
created_atstring创建时间
expires_atstring过期时间