账单用量分析(Beta)
Beta: This endpoint is currently in beta and may be unstable. Request/response schemas and behavior may change without notice.
Get aggregated usage analytics for the authenticated user with breakdowns by date, model, and API key. This endpoint provides summary views of your API usage, ideal for dashboards and usage monitoring. Data is cached for 10 minutes.
查询参数
您可以使用以下任一方式指定分析的时间段:- lookback:相对时间段,例如 “7d”(7 天)、“30d”(30 天),最长 “90d”(90 天)
- startDate 和 endDate:以
YYYY-MM-DD格式自定义日期范围。如果提供其中之一,则两者都必填。
响应字段
lookback
查询所使用的 lookback 时间段。以 “Nd” 格式(如 “7d”)或 “startDate:endDate” 格式返回。byDate
所请求时间段内的每日用量合计。- date:以
YYYY-MM-DD格式的日期 - USD:当天以 USD 计的总用量
- DIEM:当天以 DIEM 计的总用量
byModel
按模型划分的用量细分,按总支出降序排序。- modelName:模型的显示名称(例如 “GLM 5”)
- unitType:消耗的单位类型(tokens、images、chars、minutes、seconds)
- modelType:模型类型(LLM、IMAGE、TTS、ASR、VIDEO),或 null
- totalUsd:此模型上花费的总 USD
- totalDiem:此模型上花费的总 DIEM
- totalUnits:此模型消耗的总单位数
- breakdown:按类型划分的用量细分数组(仅在存在多种类型时出现)。每个条目包含:
- type:Token 类型(例如 “Input”、“Output”、“Cache Read”、“Cache Write”)
- usd:此细分的 USD 金额
- diem:此细分的 DIEM 金额
- units:此细分的单位数量
byModelDaily
前 8 个模型的每日图表数据。每个条目包含 “date”(时间戳)以及以模型名称为键、DIEM 用量为值的数据。topModels
按用量排序的前 8 个模型名称数组,用于图表图例。byKey
按 API 密钥划分的用量细分,按总支出降序排序。- apiKeyId:API 密钥 ID,如果用量来自 Web 应用则为 null
- description:API 密钥描述或 “Web App”
- totalUsd:通过此密钥花费的总 USD
- totalDiem:通过此密钥花费的总 DIEM
- totalUnits:通过此密钥消耗的总单位数
byKeyDaily
前 8 个 API 密钥的每日图表数据。每个条目包含 “date”(时间戳)以及以密钥描述为键、DIEM 用量为值的数据。topKeyNames
按用量排序的前 8 个 API 密钥描述数组,用于图表图例。使用示例
授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
查询参数
Lookback period for usage data. Format: number followed by "d" (e.g., "7d", "30d"). Maximum: 90d
^[1-9]\d*d$"7d"
Start date for filtering records (YYYY-MM-DD). If provided, endDate is also required.
^\d{4}-\d{2}-\d{2}$"2024-01-01T00:00:00.000Z"
End date for filtering records (YYYY-MM-DD). If provided, startDate is also required.
^\d{4}-\d{2}-\d{2}$"2024-01-31T00:00:00.000Z"
响应
Successful response with aggregated usage analytics
Aggregated usage analytics response with breakdowns by date, model, and API key
The lookback period used for the query. Either "Nd" format or "startDate:endDate" format.
"7d"
Daily usage totals for the requested period
Usage breakdown by model, sorted by total spend (highest first)
Daily chart data for top 8 models. Each entry has "date" (timestamp) plus model names as keys.
Names of the top 8 models by usage (for chart legends)
Usage breakdown by API key, sorted by total spend (highest first)
Daily chart data for top 8 API keys. Each entry has "date" (timestamp) plus key descriptions as keys.
Descriptions of the top 8 API keys by usage (for chart legends)