查询消费用量
- 逐条返回每次调用的扣费明细
- 可下钻到模型、Key、请求 ID
- 汇总统计用 /api/log/self/stat
认证
账户相关接口走 New-API 的管理通道,需要系统访问令牌,与调用模型的 API Key 不是一回事。在控制台「个人设置 → 安全设置 → 系统访问令牌」生成,请求头写成 Authorization: Bearer YOUR_ACCESS_TOKEN。
当前登录用户的 ID。值必须与令牌所属用户一致,否则返回 401。
Account endpoints use New API's management channel and need a system access token, which is not the same as a model API key. Create one under Settings → Security → System access tokens and send it as Authorization: Bearer YOUR_ACCESS_TOKEN.
The signed-in user's ID. It must match the token's owner or the request returns 401.
查询参数
页码,从 1 开始。
每页条数,超过 100 会被截为 100。
日志类型。1 充值、2 消费、3 管理、4 系统、5 退款。查消费明细传 2。
开始时间,Unix 秒。普通用户的实际可查范围受实例配置限制。
结束时间,Unix 秒。
按模型名过滤,可下钻到单个模型。
按 Key 名称过滤。
按分组过滤。
按请求 ID 精确定位一次调用。
Page number, starting at 1.
Page size; values above 100 are clipped to 100.
Log type: 1 top-up, 2 consumption, 3 management, 4 system, 5 refund. Pass 2 for usage detail.
Start time in Unix seconds. The visible range for regular users is instance-configured.
End time in Unix seconds.
Filter by model, for per-model drill-down.
Filter by key name.
Filter by group.
Pin down a single call by request ID.
响应
明细列表,每条记录对应一次调用:
{
"success": true,
"message": "",
"data": [
{
"id": 90210,
"user_id": 1,
"created_at": 1763088289,
"type": 2,
"content": "model=gpt-image-2.5-flare, quota=45000",
"username": "alice",
"token_name": "prod-key",
"model_name": "gpt-image-2.5-flare",
"quota": 45000,
"prompt_tokens": 120,
"completion_tokens": 0,
"use_time": 42,
"is_stream": false,
"channel": 3,
"token_id": 12,
"group": "default",
"ip": "203.0.113.24",
"request_id": "20261114123abc"
}
]
}data[].quota(integer) — 本次调用的扣费额度。data[].model_name(string) — 实际使用的模型。data[].prompt_tokens/completion_tokens(integer) — token 用量。data[].use_time(integer) — 耗时,秒。data[].token_name(string) — 发起调用的 Key 名称。data[].created_at(integer) — 发生时间,Unix 秒。data[].request_id(string) — 请求 ID,排查时用它对齐上游日志。data[].channel(integer) — 渠道 ID。
quota 的换算比例由实例配置决定,New-API 默认 500000 额度 = 1 美元。展示时用 quota / 500000 得到美元,具体数值以你所在实例的配置为准。
A detail list where each record is one call:
{
"success": true,
"message": "",
"data": [
{
"id": 90210,
"user_id": 1,
"created_at": 1763088289,
"type": 2,
"content": "model=gpt-image-2.5-flare, quota=45000",
"username": "alice",
"token_name": "prod-key",
"model_name": "gpt-image-2.5-flare",
"quota": 45000,
"prompt_tokens": 120,
"completion_tokens": 0,
"use_time": 42,
"is_stream": false,
"channel": 3,
"token_id": 12,
"group": "default",
"ip": "203.0.113.24",
"request_id": "20261114123abc"
}
]
}data[].quota(integer) — quota charged for this call.data[].model_name(string) — the model actually used.data[].prompt_tokens/completion_tokens(integer) — token usage.data[].use_time(integer) — duration in seconds.data[].token_name(string) — the key that made the call.data[].created_at(integer) — when it happened, Unix seconds.data[].request_id(string) — request ID, useful for matching upstream logs.data[].channel(integer) — channel ID.
The quota scale is instance-configured; New API defaults to 500000 quota per US dollar, so divide by 500000 for dollars. Check your own instance's setting.
汇总统计
只想看总消耗与速率时用 GET /api/log/self/stat,参数与明细接口相同,返回一个汇总对象:
{
"success": true,
"message": "",
"data": {
"quota": 789500,
"rpm": 12,
"tpm": 8400
}
}data.quota(integer) — 时间窗口内的总扣费额度。data.rpm(integer) — 该窗口内的每分钟请求数。data.tpm(integer) — 该窗口内的每分钟 token 数。
For totals and rates only, use GET /api/log/self/stat with the same parameters; it returns one aggregate object:
{
"success": true,
"message": "",
"data": {
"quota": 789500,
"rpm": 12,
"tpm": 8400
}
}data.quota(integer) — total quota charged in the window.data.rpm(integer) — requests per minute in the window.data.tpm(integer) — tokens per minute in the window.
时间范围说明
两个时间戳都用 Unix 秒(10 位)。普通用户的查询范围上限由实例的「最长日志时间范围」配置决定,默认 365 天;超出范围的请求会被截到允许区间。
日志是逐条明细,数据看板是按时间、模型、用户或渠道聚合后的统计。两者的筛选范围与刷新时机可能不同,新请求先出现在日志里,图表要等聚合后才更新。
Both timestamps are Unix seconds (10 digits). The maximum range for regular users comes from the instance's "longest log range" setting, 365 days by default; wider requests are clipped to the allowed window.
Logs are per-call detail, while the dashboard aggregates by time, model, user, or channel. Their filters and refresh timing can differ: a new request shows up in logs first and in charts after aggregation.
错误码
| HTTP | 含义 |
|---|---|
| 200 | 请求成功。业务失败时 success 为 false |
| 401 | 令牌缺失、无效,或 New-Api-User 与令牌归属不一致 |
| 403 | 令牌无权访问该接口 |
| HTTP | Meaning |
|---|---|
| 200 | Success. Business failures return success: false |
| 401 | Token missing or invalid, or New-Api-User doesn't match the token owner |
| 403 | The token isn't allowed to call this endpoint |
For more status codes and retry guidance see Error codes and rate limits; for troubleshooting see the FAQ.
使用示例
按天取消费明细
把 start_timestamp 与 end_timestamp 设成某一天的首尾,再加 type=2,就得到当天的全部扣费记录。
按模型归因
加 model_name 过滤,可以算出单个模型的成本占比。
只取总量
换成 /api/log/self/stat 只返回一个汇总对象,适合做看板上的数字。
Daily usage detail
Set start_timestamp and end_timestamp to the start and end of a day and add type=2 to get every charge that day.
Attribute by model
Add a model_name filter to compute a single model's share of cost.
Totals only
Swap in /api/log/self/stat for one aggregate object, ideal for dashboard figures.