-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Implement cost management and budget control features at the API Key level.
Requirements
Budget System
- One-time quota allocation (non-periodic)
- Real-time cost calculation based on
models.inputPriceandmodels.outputPrice - API Key level budget management
Alert Thresholds (Configurable)
| Threshold | Notify | Action |
|---|---|---|
| 80% | API Key Owner | Warning |
| 90% | API Key Owner | Warning |
| 95% | API Key Owner + Admin | Urgent Warning |
| 100% | API Key Owner + Admin | Warning + Soft Limit |
Soft Limit Strategy
- At 100%: Reject new requests, allow in-progress requests to complete
- Alert debounce: Same threshold alert interval ≥ 1 hour (configurable)
Database Changes
api_keystable: Addbudget_limit,budget_used,budget_alert_thresholds,owner_emailcompletionstable: Addcalculated_costembeddingstable: Addcalculated_cost
API Endpoints
GET /api/admin/costs/overview- Cost overviewGET /api/admin/costs/by-key- Group by API KeyGET /api/admin/costs/by-model- Group by modelPUT /api/admin/apiKey/:id/budget- Set budget
概要
实现 API Key 级别的成本管理和预算控制功能。
需求
预算系统
- 一次性额度分配(非周期性)
- 基于
models.inputPrice和models.outputPrice实时计算成本 - API Key 级别的预算管理
告警阈值(可配置)
| 阈值 | 通知对象 | 行为 |
|---|---|---|
| 80% | API Key 所有者 | 预警 |
| 90% | API Key 所有者 | 预警 |
| 95% | API Key 所有者 + 管理员 | 紧急预警 |
| 100% | API Key 所有者 + 管理员 | 预警 + 软限制 |
软限制策略
- 100% 时:拒绝新请求,允许进行中的请求正常完成
- 告警防抖:同一阈值告警间隔 ≥ 1小时(可配置)
数据库变更
api_keys表新增:budget_limit,budget_used,budget_alert_thresholds,owner_emailcompletions表新增:calculated_costembeddings表新增:calculated_cost
API 端点
GET /api/admin/costs/overview- 成本总览GET /api/admin/costs/by-key- 按 API Key 分组GET /api/admin/costs/by-model- 按模型分组PUT /api/admin/apiKey/:id/budget- 设置预算
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request