查询用量
返回指定时间段内、该 API Key 所属项目的消耗汇总:总额与按模型分项。消耗数据自动限定到 Key 所属的项目,不能跨项目查询。
在请求头携带 API Key:
Authorization: Bearer sk_live_YOUR_API_KEY
GET/api/business/v1/customer/usage
查询用量
返回 [from, to) 时间范围内、API Key 所属项目的消耗汇总(总额与按模型分项)。 时间范围以 UTC 为准;消耗自动限定到 Key 所属项目,不能跨项目查询。
🔑Bearer API Key请求头使用 Authorization: Bearer sk_live_...,也支持 x-api-key。
请求结构
下方内容用于确认方法、地址和鉴权方式,属于 HTTP 结构片段,不是可独立执行示例。
GET https://www.silvamux.com/api/business/v1/customer/usage
Authorization: Bearer $SILVAMUX_API_KEY
请求参数
| 参数 | 类型与位置 | 必填 | 说明 |
|---|
from | string (date-time) · query | 是 | 起始时间(RFC3339,包含)。 |
to | string (date-time) · query | 是 | 结束时间(RFC3339,不包含);from 必须早于 to。 |
响应
200时间范围内的用量汇总。
application/json · CustomerUsageReportResponse
| 字段 | 类型 | 说明 |
|---|
by_model | array<CustomerUsageModelBreakdown> | 按模型分项,按 cost_points 降序。 |
by_model.billable_prompt_tokens | integer (int64) | 计费输入 token(prompt + cache creation)。 |
by_model.cache_creation_tokens | integer (int64) | 缓存写 token。 |
by_model.cache_explicit_read_tokens | integer (int64) | 显式缓存读 token。 |
by_model.cached_tokens | integer (int64) | 缓存读 token。 |
by_model.completion_tokens | integer (int64) | 输出 token。 |
by_model.cost_points | string | 折后消耗(points)。 |
by_model.generated_artifacts | integer (int64) | 异步任务产物数(视频/图片)。 |
by_model.model | string | 聚合键:请求时填写的 model(历史行回退配置模型 ID)。 |
by_model.original_cost | string | 折前消耗(points)。 |
by_model.prompt_tokens | integer (int64) | 输入 token(未命中缓存)。 |
by_model.request_count | integer (int64) | 计费请求数。 |
by_model.total_tokens | integer (int64) | 总 token。 |
from | string (date-time) | 汇总起始(RFC3339,包含)。 |
project_id | string | 该 API Key 绑定的项目。 |
to | string (date-time) | 汇总结束(RFC3339,不包含)。 |
totals | CustomerUsageTotals | 全部模型的汇总用量。 |
totals.billable_prompt_tokens | integer (int64) | 计费输入 token(prompt + cache creation)。 |
totals.cache_creation_tokens | integer (int64) | 缓存写 token。 |
totals.cache_explicit_read_tokens | integer (int64) | 显式缓存读 token。 |
totals.cached_tokens | integer (int64) | 缓存读 token。 |
totals.completion_tokens | integer (int64) | 输出 token。 |
totals.cost_points | string | 折后总消耗(points)。 |
totals.generated_artifacts | integer (int64) | 异步任务产物数(视频/图片)。 |
totals.original_cost | string | 折前总消耗(points)。 |
totals.prompt_tokens | integer (int64) | 输入 token(未命中缓存)。 |
totals.request_count | integer (int64) | 计费请求数。 |
totals.total_tokens | integer (int64) | 总 token。 |
defaultRFC 7807 problem+json 错误(Business API 形态)。
application/problem+json · BusinessError
| 字段 | 类型 | 说明 |
|---|
detail | string | 错误详情。 |
errors | array<object> | 字段级错误明细(422 校验失败时返回)。 |
errors.location | string | 出错位置(如 query.request_id)。 |
errors.message | string | 错误信息。 |
errors.value | any | 出错字段的值。 |
instance | string | 本次错误出现的 URI。 |
status | integer | HTTP 状态码。 |
title | string | 错误摘要。 |
type | string | 错误类型标识(含错误码)。 |
from、to:必填,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"
# pip install requests
import os
import requests
resp = requests.get(
"https://www.silvamux.com/api/business/v1/customer/usage",
params={
"from": "2026-07-08T00:00:00Z",
"to": "2026-07-09T00:00:00Z",
},
headers={"Authorization": f"Bearer {os.environ['SILVAMUX_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json()["totals"])
// Node 18+(内置 fetch)
const from = "2026-07-08T00:00:00Z";
const to = "2026-07-09T00:00:00Z";
const query = new URLSearchParams({ from, to });
const resp = await fetch(
`https://www.silvamux.com/api/business/v1/customer/usage?${query}`,
{
headers: { Authorization: `Bearer ${process.env.SILVAMUX_API_KEY}` },
},
);
const data = await resp.json();
console.log(data.totals);
// 仅依赖标准库
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
url := "https://www.silvamux.com/api/business/v1/customer/usage?from=2026-07-08T00:00:00Z&to=2026-07-09T00:00:00Z"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SILVAMUX_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
响应:
{
"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 |