Skip to content

按插件用量汇总 API ​

GET /my/billing/usage-by-app:按 OAuth 插件汇总的模型用量(净消耗、调用次数、最近使用时间与事件级明细),服务于 Driver 桌面壳「按插件用量」卡片与网页端积分页「按插件」视图(issue #1966)。

源码:apps/backend/src/routes/my-billing.ts、apps/backend/src/services/billing-usage-by-app.ts、RPC read_billing_usage_by_app


认证 ​

仅两种身份可访问,其余(插件 token、API Key 等)一律 403 forbidden:

  • JWT 用户会话(网页端):默认统计本人默认个人团队;可传 teamId 指定本人为 accepted 成员的团队,非本人团队返回 404 team_not_found。
  • 官方 Host 委托 OAuth token(Driver 桌面壳,scope oauth:delegate):强制统计 token 用户的默认个人团队,客户端白名单(OAUTH_DELEGATION_HOST_CLIENT_IDS)fail-closed。

响应设置 Cache-Control: no-store。


请求 ​

GET /my/billing/usage-by-app?from=<RFC3339>&to=<RFC3339>&appId=<uuid>&cursor=<cursor>&limit=50&teamId=<uuid>
参数必填说明
from / to否RFC3339 时间窗,左闭右开;缺省为最近 30 天(to=now、from=to-30d)
appId否只统计指定插件(uuid 小写)
cursor否下一页游标(响应 nextCursor 原样回传;base64url)
limit否明细每页条数,1-100,默认 50
teamId否仅 JWT 可用:指定统计团队(须为本人 accepted 成员)

窗口超过 366 天返回 422 usage_range_too_large;参数非法返回 400 invalid_query。

响应 ​

json
{
  "success": true,
  "data": {
    "teamId": "…",
    "from": "2026-09-24T00:00:00Z",
    "to": "2026-10-24T00:00:00Z",
    "apps": [
      {
        "appId": "…", "appName": "示例插件", "appMode": "development",
        "chargedMilliCredits": 4, "refundedMilliCredits": 0,
        "netMilliCredits": 4, "callCount": 1, "lastUsedAt": "2026-10-23T12:00:00+00:00"
      }
    ],
    "totals": { "chargedMilliCredits": 4, "refundedMilliCredits": 0, "netMilliCredits": 4, "callCount": 1 },
    "items": [
      {
        "transactionId": "…", "appId": "…", "createdAt": "2026-10-23T12:00:00+00:00",
        "transactionType": "model_usage", "sourceType": "billing_usage_event",
        "chargedMilliCredits": 4, "refundedMilliCredits": 0,
        "modelId": "glm-4.7", "executionPath": "model-gateway:/v1/chat/completions",
        "eventId": "…"
      }
    ],
    "nextCursor": null
  }
}
  • 金额单位毫积分(1 credit = 1000 milli-credit);netMilliCredits = charged - refunded,可为负。
  • apps 按 oauthAppId 聚合一行;appMode:development(窗口内全部为开发态 token 调用)/ mixed / public。appMode、eventId 为网页端扩展键,Driver 客户端忽略。
  • totals 与 apps 同口径(受 appId 筛选影响);items 为事件级明细,createdAt 降序游标分页。

错误 ​

状态码code场景
400invalid_query时间/UUID/limit/cursor 非法,或含未知查询参数
403forbidden插件 token、API Key 等非 JWT/OAuth 身份;OAuth 非官方 Host 白名单
404team_not_found无默认个人团队,或 JWT 指定的 teamId 非本人成员
422usage_range_too_large时间窗超过 366 天
503unavailable数据面暂时不可用

错误体统一为 { "error": { "code": "…" } }。

相关 ​

  • 积分明细(来源插件列/模型/token 展示)与结算字段补记见 docs/features/billing/usage-attribution.md。

AI Workflow Editor