客户查询 API

客户可通过 API Key(sk_live_ 开头)程序化查询组织余额与项目消耗,无需登录态。所有接口仅接受 API Key 鉴权,消耗数据自动限定到该 Key 所属的项目。

鉴权

在请求头携带 API Key:

Authorization: Bearer sk_live_YOUR_API_KEY

API Key 在控制台「API Keys」页面创建,绑定到某个组织与项目。查询消耗时只能看到该 Key 所属项目的数据,不能跨项目查询;余额为组织级。

查询余额

GET https://www.silvamux.com/api/business/v1/customer/balance

返回当前组织余额。

curl https://www.silvamux.com/api/business/v1/customer/balance \
  -H "Authorization: Bearer $SILVAMUX_API_KEY"

响应:

{
  "balance_points": "42.5"
}
字段 说明
balance_points 当前余额(points)

查询消耗

GET https://www.silvamux.com/api/business/v1/customer/usage?from={from}&to={to}

返回指定时间段内、该 API Key 所属项目的消耗汇总:总额与按模型分项。

  • fromto:RFC3339 时间,左闭右开 [from, to)from 必须早于 to
  • 时间范围以 UTC 为准。
curl "https://www.silvamux.com/api/business/v1/customer/usage?from=2026-07-08T00:00:00Z&to=2026-07-09T00:00:00Z" \
  -H "Authorization: Bearer $SILVAMUX_API_KEY"

响应:

{
  "from": "2026-07-08T00:00:00Z",
  "to": "2026-07-09T00:00:00Z",
  "project_id": "PROJ-1",
  "totals": {
    "cost_points": "1.5",
    "prompt_tokens": 100,
    "cached_tokens": 0,
    "billable_prompt_tokens": 100,
    "completion_tokens": 50,
    "cache_creation_tokens": 0,
    "total_tokens": 150,
    "generated_artifacts": 0,
    "request_count": 2
  },
  "by_model": [
    {
      "model": "deepseek-v4-pro@tune",
      "cost_points": "1.5",
      "prompt_tokens": 100,
      "cached_tokens": 0,
      "billable_prompt_tokens": 100,
      "completion_tokens": 50,
      "cache_creation_tokens": 0,
      "total_tokens": 150,
      "generated_artifacts": 0,
      "request_count": 2
    }
  ]
}
字段 说明
project_id 该 API Key 绑定的项目
totals 时间范围内所有模型的汇总
by_model 按模型分项,按 cost_points 降序

错误处理

HTTP 状态 错误码 说明
401 INVALID_TOKEN API Key 缺失或无效
400 INVALID_FROM_DATETIME from 缺失或格式非 RFC3339
400 INVALID_TO_DATETIME to 缺失或格式非 RFC3339
400 INVALID_TIME_RANGE from 不早于 to

通用错误处理见 错误处理