查询用量

返回指定时间段内、该 API Key 所属项目的消耗汇总:总额与按模型分项。消耗数据自动限定到 Key 所属的项目,不能跨项目查询。

鉴权

在请求头携带 API Key:

Authorization: Bearer sk_live_YOUR_API_KEY

接口

GET/api/business/v1/customer/usage

查询用量

Return aggregated usage (totals + per-model) for the API key's project over a time range. API key only.

Bearer API Key请求头使用 Authorization: Bearer sk_live_...,也支持 x-api-key。

请求结构

下方内容用于确认方法、地址和鉴权方式,属于 HTTP 结构片段,不是可独立执行示例。

HTTP
GET https://www.silvamux.com/api/business/v1/customer/usage
Authorization: Bearer $SILVAMUX_API_KEY

请求参数

参数类型与位置必填说明
Authorizationstring · headerBearer API Key (sk_live_...)
X-Organization-Idstring · headerNot required for API key auth
fromstring · queryRFC3339 start time (inclusive)
tostring · queryRFC3339 end time (exclusive)

响应

200OK

application/json · BillingUsageReportResponse

字段类型必填说明
$schemastring (uri)A URL to the JSON Schema for this object.
by_modelarray<UsageReportModelBreakdown>Per-model breakdown, ordered by cost_points desc
by_model.billable_prompt_tokensinteger (int64)Summed billable prompt tokens
by_model.cache_creation_tokensinteger (int64)Summed cache creation tokens
by_model.cache_explicit_read_tokensinteger (int64)Summed explicit cache read tokens
by_model.cached_tokensinteger (int64)Summed cached tokens
by_model.completion_tokensinteger (int64)Summed completion tokens
by_model.cost_pointsstringTotal cost in points (after discount)
by_model.generated_artifactsinteger (int64)Summed generated artifacts
by_model.modelstringAggregation key: user-supplied request_model, falling back to the configured model ID for legacy rows
by_model.original_coststringTotal cost in points before discount
by_model.prompt_tokensinteger (int64)Summed prompt tokens
by_model.request_countinteger (int64)Number of billed requests
by_model.total_tokensinteger (int64)Summed total tokens
fromstring (date-time)Report start (RFC3339, inclusive)
project_idstringProject filter ('' means org-wide)
tostring (date-time)Report end (RFC3339, exclusive)
totalsUsageReportTotals
totals.billable_prompt_tokensinteger (int64)
totals.cache_creation_tokensinteger (int64)
totals.cache_explicit_read_tokensinteger (int64)
totals.cached_tokensinteger (int64)
totals.completion_tokensinteger (int64)
totals.cost_pointsstringTotal cost in points (after discount)
totals.generated_artifactsinteger (int64)
totals.original_coststringTotal cost in points before discount
totals.prompt_tokensinteger (int64)
totals.request_countinteger (int64)
totals.total_tokensinteger (int64)

defaultError

application/problem+json · ErrorModel

字段类型必填说明
$schemastring (uri)A URL to the JSON Schema for this object.
detailstringA human-readable explanation specific to this occurrence of the problem.
errorsarray<ErrorDetail>Optional list of individual error details
errors.locationstringWhere the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id'
errors.messagestringError message text
errors.valueanyThe value at the given location
instancestring (uri)A URI reference that identifies the specific occurrence of the problem.
statusinteger (int64)HTTP status code
titlestringA short, human-readable summary of the problem type. This value should not change between occurrences of the error.
typestring (uri)A URI reference to human-readable documentation for the error.;默认值:about:blank

参数

  • 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 状态错误码说明
401INVALID_TOKENAPI Key 缺失或无效
400INVALID_FROM_DATETIMEfrom 缺失或格式非 RFC3339
400INVALID_TO_DATETIMEto 缺失或格式非 RFC3339
400INVALID_TIME_RANGEfrom 不早于 to