查询单次请求消耗 按请求 ID(响应头 X-Request-Id 的值,REQ- 开头)查询该次请求的实际消耗:token 用量与费用。适用于任务完成后回查单次请求的真实计费,例如视频生成等异步任务的结算核对。
一次请求如果触发了供应商切换,会产生多条记录:失败的尝试已被作废(status 为 upstream_failed、费用为 0),最终成功的那条为 billed。全部返回,按时间升序排列。
在请求头携带 API Key:
Authorization: Bearer sk_live_YOUR_API_KEY
GET /api/business/v1/customer/request-usage
Get actual usage for a single request
Return the ledgers (tokens + cost) produced by one gateway request, identified by the request_id query parameter (the X-Request-Id response header value, REQ-...). Fields match the dashboard ledger view. A request that failed over between providers produces multiple ledgers (voided attempts + the final billed one). API key only.
🔑 Bearer API Key 请求头使用 Authorization: Bearer sk_live_...,也支持 x-api-key。
请求结构 下方内容用于确认方法、地址和鉴权方式,属于 HTTP 结构片段,不是可独立执行示例。
GET https://www.silvamux.com/api/business/v1/customer/request-usage
Authorization: Bearer $SILVAMUX_API_KEY请求参数 参数 类型与位置 必填 说明 Authorizationstring · header 是 Bearer API Key (sk_live_...) X-Organization-Idstring · header 否 Not required for API key auth request_idstring · query 是 Request ID from the X-Request-Id response header (REQ-...)
响应 200OK application/json · CustomerRequestUsageResponse
字段 类型 必填 说明 $schemastring (uri) 否 A URL to the JSON Schema for this object. ledgersarray<CustomerRequestUsageEntry> 是 Ledgers produced by this request, ordered by created_at asc ledgers.cost_pointsstring 是 Cost in points after discount ledgers.created_atstring (date-time) 是 Ledger creation time (RFC3339) ledgers.first_token_latency_msinteger (int64) 是 Time to first token in ms (streamed requests; 0 = unrecorded) ledgers.generated_artifactsinteger (int64) 是 Generated artifact count (video/image async tasks) ledgers.is_streamboolean 是 Whether the request was streamed ledgers.original_coststring 是 Cost in points before discount ledgers.project_namestring 是 Project name ledgers.request_modelstring 是 Model name as supplied in the request ledgers.statusstring 是 Ledger status (billed / upstream_failed / pending) ledgers.tokensRequestTokens 是 — ledgers.tokens.billable_prompt_tokensinteger (int64) 是 Billable prompt tokens (prompt + cache creation) ledgers.tokens.cached_tokensinteger (int64) 是 Cache-read prompt tokens ledgers.tokens.completion_tokensinteger (int64) 是 Completion tokens ledgers.tokens.prompt_tokensinteger (int64) 是 Prompt tokens (uncached) ledgers.tokens.total_tokensinteger (int64) 是 Total tokens ledgers.total_latency_msinteger (int64) 是 Total request latency in ms (0 = unrecorded) request_idstring 是 Gateway request ID (X-Request-Id response header)
defaultError application/problem+json · ErrorModel
字段 类型 必填 说明 $schemastring (uri) 否 A URL to the JSON Schema for this object. detailstring 否 A human-readable explanation specific to this occurrence of the problem. errorsarray<ErrorDetail> 否 Optional list of individual error details errors.locationstring 否 Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id' errors.messagestring 否 Error message text errors.valueany 否 The value at the given location instancestring (uri) 否 A URI reference that identifies the specific occurrence of the problem. statusinteger (int64) 否 HTTP status code titlestring 否 A 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
request_id:必填,响应头 X-Request-Id 的值(REQ- 开头)。只能查询属于该 API Key 所属组织的请求,否则返回 404。 curl "https://www.silvamux.com/api/business/v1/customer/request-usage?request_id=REQ-01M2JBYGGVY77KPRWNZFDFTWZR" \
-H "Authorization: Bearer $SILVAMUX_API_KEY "
# pip install requests
import os
import requests
resp = requests.get(
"https://www.silvamux.com/api/business/v1/customer/request-usage",
params={"request_id": "REQ-01M2JBYGGVY77KPRWNZFDFTWZR"},
headers={"Authorization": f"Bearer {os.environ['SILVAMUX_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json()["ledgers"])
// Node 18+(内置 fetch)
const requestId = "REQ-01M2JBYGGVY77KPRWNZFDFTWZR";
const query = new URLSearchParams({ request_id: requestId });
const resp = await fetch(
`https://www.silvamux.com/api/business/v1/customer/request-usage?${query}`,
{
headers: { Authorization: `Bearer ${process.env.SILVAMUX_API_KEY}` },
},
);
const data = await resp.json();
console.log(data.ledgers);
// 仅依赖标准库
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
url := "https://www.silvamux.com/api/business/v1/customer/request-usage?request_id=REQ-01M2JBYGGVY77KPRWNZFDFTWZR"
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))
}
cURL Python JavaScript Go
响应:
{
"request_id" : "REQ-01M2JBYGGVY77KPRWNZFDFTWZR" ,
"ledgers" : [
{
"request_model" : "deepseek-v4-pro" ,
"project_name" : "Default Project" ,
"status" : "billed" ,
"tokens" : {
"prompt_tokens" : 85 ,
"cached_tokens" : 0 ,
"billable_prompt_tokens" : 85 ,
"completion_tokens" : 10 ,
"total_tokens" : 95
},
"generated_artifacts" : 0 ,
"is_stream" : false ,
"first_token_latency_ms" : 0 ,
"total_latency_ms" : 1358 ,
"original_cost" : "0.001035" ,
"cost_points" : "0.001035" ,
"created_at" : "2026-09-15T11:06:32.861800Z"
}
]
}
字段 说明 request_id查询的请求 ID ledgers该请求产生的全部计费记录,按时间升序 ledgers[].request_model请求时填写的模型名 ledgers[].statusbilled(已计费)/ upstream_failed(上游失败已作废,费用 0)/ pending(待结算)ledgers[].tokenstoken 用量明细 ledgers[].generated_artifacts异步任务产物数(视频/图片) ledgers[].original_cost折前费用 ledgers[].cost_points折后实际扣费
HTTP 状态 错误码 说明 401 INVALID_TOKENAPI Key 缺失或无效 404 REQUEST_USAGE_NOT_FOUND请求 ID 不存在,或不属于该 API Key 的组织 422 — request_id 参数缺失