Venice Billing
用于账户级计费与分析的只读接口。usage-analytics 在规范中标记为 Beta —— 其结构与行为可能变化。
| 接口 | 用途 |
|---|---|
| GET /billing/balance | 当前 canConsume 标志、剩余 DIEM、所得积分、捆绑积分与美元余额、纪元配额。 |
| GET /billing/usage-history | 逐笔请求台账,键集(游标)分页。支持 JSON 或 CSV。 |
| GET /billing/usage-analytics | 聚合拆分:按日期、模型、API 密钥。 |
| GET /billing/usage | 已退役。 于 2026-09-16 下线;所有请求返回 410。 |
三个仍在服务的接口都要求使用 ADMIN 密钥做 Bearer 鉴权 —— INFERENCE 密钥会得到 401("Admin API key required")。它们不接受 x402 钱包鉴权;钱包余额请使用 venice-x402。完全不带 Authorization 头的请求会收到 402 的 x402 发现响应体而不是 401 —— 忽略其中的支付选项,改用 ADMIN Bearer 密钥重发;密钥错误会得到 401。
GET /billing/usage已下线。 自 2026-09-16 起,无论是否鉴权,所有请求都返回410 Gone,不返回任何用量数据。响应体的error字符串会指明替代接口与参数改名,响应头携带Deprecation: @1783555200、Sunset: Wed, 16 Sep 2026 00:00:00 GMT,以及Link: </api/v1/billing/usage-history>; rel="successor-version", <https://docs.venice.ai/api-reference/endpoint/billing/usage-history>; rel="deprecation"; type="text/html"。 该路由按 IP 限速 60 次/分钟(超出后返回429,其消息会重复迁移指引)。请迁移到GET /billing/usage-history:page+limit→pageSize+nextCursor,startDate/endDate→startTimestamp/endTimestamp。
货币与扣费优先级
每笔请求只记入一种货币,按以下顺序选取:
DIEM—— 来自质押的 DIEM;配额每个纪元(UTC 日)重置。EARNED_CREDITS—— 以美元计价的所得积分。BUNDLED_CREDITS—— 付费 Venice 订阅计划附带的美元计价积分。USD—— 预充值的法币余额。
预扣(报价)类费用(如排队任务和图像)使用第一种能覆盖全部成本的货币。按 token 计价的请求在执行后计费,记入第一种仍有正余额的货币,因此可能使其略微转负。
旧称 VCU(DIEM 的旧名)已不再是可消耗货币;/billing/usage-history 的 currency 过滤器会拒绝它。
按键计算的美元消耗限额会同时覆盖 USD、BUNDLED_CREDITS 和 EARNED_CREDITS;DIEM 限额覆盖 DIEM(参见 venice-api-keys)。
GET /billing/balance
curl https://api.venice.ai/api/v1/billing/balance \
-H "Authorization: Bearer $VENICE_ADMIN_KEY"
{
"canConsume": true,
"consumptionCurrency": "DIEM",
"balances": { "diem": 90.5, "usd": 25, "bundledCredits": 10, "earnedCredits": null },
"diemEpochAllocation": 100
}
- 当账户可花的 DIEM、所得积分、捆绑积分与美元合计不低于 $0.10 时,
canConsume为true。它不考虑按键限额或账户的 API 等级 —— 真正的准入检查在每个推理请求上执行。需要包含这些因素的检查,请用GET /api_keys/rate_limits→accessPermitted。 consumptionCurrency是按DIEM、EARNED_CREDITS、BUNDLED_CREDITS、USD顺序第一种有正余额的货币,否则为null。规范枚举还列出VCU,但永远不会返回它。- 账户未质押 DIEM 时
balances.diem为null;否则为本纪元剩余 DIEM。 - 不为正时,
balances.usd、balances.bundledCredits和balances.earnedCredits为null。 diemEpochAllocation是当前纪元的 DIEM 总额 ——balances.diem / diemEpochAllocation= 剩余比例。
GET /billing/usage-history
逐笔请求台账,键集(游标)分页,时间戳升序。
curl "https://api.venice.ai/api/v1/billing/usage-history?startTimestamp=2026-06-01T00:00:00Z&endTimestamp=2026-07-01T00:00:00Z&pageSize=1000¤cy=USD" \
-H "Authorization: Bearer $VENICE_ADMIN_KEY" \
-H "Accept: application/json"
查询参数
一次请求要么是带过滤条件的第一页,要么是裸的续页请求。把 cursor 与任何过滤参数一起发送会得到 400,任何未知参数同样如此 —— 校验器很严格。
| 参数 | 说明 |
|---|---|
| startTimestamp | 可选。包含下界,ISO 8601 UTC、带 Z 后缀(最长 40 字符)。仅第一页使用。 |
| endTimestamp | 可选。排除上界,格式相同。必须晚于 startTimestamp。共享边界值的连续窗口可以无缝、无重叠地遍历历史。 |
| currency | 可选。USD / DIEM / BUNDLED_CREDITS / EARNED_CREDITS。 |
| pageSize | 整数 10–1000。默认 1000。 |
| cursor | 来自上一次 nextCursor 的不透明续页令牌([A-Za-z0-9_-],≤ 512 字符)。它携带所续遍历的过滤条件与页大小,因此必须单独发送。 |
已过期、被篡改或发给其他用户的 cursor 返回 400("Invalid or expired cursor; restart from the first page")。在记录新用量时,已有页内容保持稳定;不返回结果总数。
响应(JSON)
{
"data": [
{
"timestamp": "2026-06-15T19:05:10.504Z",
"sku": "zai-org-glm-5-1-llm-output-mtoken",
"units": 0.000227,
"pricePerUnitUsd": 2.8,
"amount": -0.06356,
"currency": "DIEM",
"notes": "API Inference",
"inferenceDetails": {
"requestId": "chatcmpl-4007fd29f42b7d3c4107f4345e8d174a",
"promptTokens": 339,
"completionTokens": 227,
"inferenceExecutionTime": 2964
}
}
],
"nextCursor": "AZq3fK9tXhIVDm2j4vN8cQwYt1sB6uEoLxRgPzKaJdHfM5nC7yW0K3w"
}
最后一页的 nextCursor 为 null。
字段
sku—— 计费行项(模型 + 单位类型 + 格式)。units—— 对 LLM 而言是百万 token 数(如0.000227= 227 个 token)。pricePerUnitUsd—— 每单位的美元单价。amount—— 扣款为负数。currency——USD、DIEM、BUNDLED_CREDITS或EARNED_CREDITS。inferenceDetails—— 非推理条目为null。存在时,requestId是原始响应返回的id;promptTokens、completionTokens和inferenceExecutionTime(毫秒)在未记录时各自可为null(非 LLM 用量的 token 数为null)。
CSV
发送 Accept: text/csv。列包括:timestamp, sku, pricePerUnitUsd, units, amount, currency, notes, inferenceDetails.requestId, inferenceDetails.inferenceExecutionTime, inferenceDetails.promptTokens, inferenceDetails.completionTokens。
Content-Disposition 为 attachment; filename=billing-usage-history-<UTC export stamp>.csv,因此遍历的每一页都以唯一且按时间排序的文件名下载。由于 CSV 没有信封结构,续页令牌移到 x-next-cursor 响应头中,最后一页不含该头。
遍历完整历史
let url = `${base}/billing/usage-history?startTimestamp=${start}&endTimestamp=${end}`
for (;;) {
const page = await fetch(url, { headers }).then(r => r.json())
handle(page.data)
if (page.nextCursor === null) break
url = `${base}/billing/usage-history?cursor=${encodeURIComponent(page.nextCursor)}`
}
GET /billing/usage-analytics
面向仪表盘的聚合摘要。按用户 + 时间段缓存 10 分钟。
curl "https://api.venice.ai/api/v1/billing/usage-analytics?lookback=7d" \
-H "Authorization: Bearer $VENICE_ADMIN_KEY"
查询参数(两种方式二选一)
lookback=Nd—— 必须匹配^[1-9]\d*d$。默认7d。超过90d的值会被收敛到 90 天(响应中的lookback显示为"90d")。- 或者
startDate=YYYY-MM-DD与endDate=YYYY-MM-DD(含端点,UTC 日)。范围最长 90 天,且endDate不得早于startDate。两者都要传:只传一个会被忽略并应用lookback。
响应(部分键)
{
"lookback": "7d",
"byDate": [{ "date": "2026-04-20", "USD": 0.5, "DIEM": 10.25 }],
"byModel": [
{
"modelName": "GLM 5.1",
"unitType": "tokens",
"modelType": "LLM",
"totalUsd": 0.4,
"totalDiem": 12.5,
"totalUnits": 50000,
"breakdown": [
{ "type": "Output", "usd": 0.3, "diem": 10, "units": 35000 },
{ "type": "Input", "usd": 0.1, "diem": 2.5, "units": 15000 }
]
}
],
"byModelDaily": [{ "date": 1705276800000, "GLM 5.1": 5.5, "Kimi K2.6": 3.2 }],
"byModelDailyUsd": [{ "date": 1705276800000, "GLM 5.1": 0.4, "Kimi K2.6": 0 }],
"topModels": ["GLM 5.1", "Kimi K2.6"],
"byKey": [
{ "apiKeyId": "key_abc123", "description": "Production Key",
"totalUsd": 0.8, "totalDiem": 15, "totalUnits": 75000 },
{ "apiKeyId": null, "description": "Web App",
"totalUsd": 0, "totalDiem": 4, "totalUnits": 25000 }
],
"byKeyDaily": [{ "date": 1705276800000, "Production Key": 8.5, "Web App": 2 }],
"byKeyDailyUsd": [{ "date": 1705276800000, "Production Key": 0.8, "Web App": 0 }],
"topKeyNames": ["Production Key", "Web App"]
}
byDate窗口内每天一条(升序,零填充)。USD合计包含BUNDLED_CREDITS但不含EARNED_CREDITS:从所得积分支付的开销不会出现在任何分析合计中。byModel/byKey列出每一个模型和密钥,按总开销(USD + DIEM)排序。仅当模型拥有多种 token 类型时才有breakdown(Input / Output / Cache Read / Cache Write …)。byModelDaily/byKeyDaily是图表行:date(Unix 毫秒)加每个序列一个字段(USD + DIEM 合并)。byModelDailyUsd/byKeyDailyUsd是相同的行但只含美元部分(含捆绑积分)。这两个*Usd数组会返回但尚未写入公开 schema。topModels/topKeyNames是图表序列:按开销取前 50 名,外加把 50 名之后全部求和的尾部"Other"序列(仅在超过 50 时出现)。规范文本仍写 "top 8";实际接口返回 50。apiKeyId: null/description: "Web App"是来自 Venice 网页应用的用量。没有描述的密钥显示为Key ...<id 末 6 位>;重复的描述会加(...<id 末 6 位>)后缀以避免序列名冲突。- 积分充值被排除;只聚合扣款。
实用配方
调用推理前先确认账户非空
/billing/balance 的 canConsume 不考虑按键限额与账户 API 等级,因此改用 GET /api_keys/rate_limits 的 accessPermitted 做闸门(可配合即将使用的密钥,包括 INFERENCE 密钥):
const { data } = await fetch(`${base}/api_keys/rate_limits`, { headers }).then(r => r.json())
if (!data.accessPermitted) throw new Error('Venice balance exhausted — top up before continuing')
每月 CSV 导出
curl -D headers.txt "https://api.venice.ai/api/v1/billing/usage-history?startTimestamp=2026-04-01T00:00:00Z&endTimestamp=2026-05-01T00:00:00Z&pageSize=1000" \
-H "Authorization: Bearer $VENICE_ADMIN_KEY" \
-H "Accept: text/csv" \
-o billing-april-001.csv
从 headers.txt 读取 x-next-cursor,用 ?cursor=<token>(不带其他参数)重复请求,直到该头消失。
头部模型图表
const a = await fetch(`${base}/billing/usage-analytics?lookback=30d`, { headers }).then(r => r.json())
// chart(a.byModelDaily, { series: a.topModels, xField: 'date' })
错误
| 代码 | 含义 |
|---|---|
| 400 | /billing/usage-history:cursor 与任何过滤参数同发、未知参数、时间戳格式错误、pageSize 超出 10–1000、endTimestamp 不晚于 startTimestamp,或 cursor 无效/过期。/billing/usage-analytics:lookback / 日期格式错误、endDate 早于 startDate,或日历范围超过 90 天(lookback 超过 90d 会被收敛而非拒绝)。 |
| 401 | 密钥无效,或在任何计费接口使用了非 ADMIN 密钥。 |
| 402 | 完全没有 Authorization 头 —— x402 鉴权挑战。 |
| 410 | /billing/usage —— 永远如此。2026-09-16 下线。 |
| 429 | /billing/usage 超过每 IP 60 次/分钟;或通用 API 错误预算。 |
| 500 | 内部错误。 |
| 504 | /billing/usage-analytics 查询超时 —— 缩短 lookback 或日期范围。 |
注意事项
- 每个计费接口都需要 ADMIN 密钥,
usage-analytics也不例外(旧文档说任意密钥可用 —— 该说法已于 2026-07-21 失效)。 - 完全不要调用
/billing/usage。它不返回任何数据;把它返回的任何410视为"立即迁移"。 /billing/usage-history接收startTimestamp/endTimestamp(带Z的完整 ISO 日期时间)和pageSize;/billing/usage-analytics接收lookback或纯YYYY-MM-DD格式的startDate/endDate。不要混用两种格式。/billing/usage-history的currency过滤器不接受VCU;请使用DIEM。- 非推理条目(如订阅扣费)的
inferenceDetails为null。 - 一个推理请求可能拆成多行台账(例如输入与输出 token 各一个 SKU),它们重复相同的
inferenceDetails。对amount跨行求和,但汇总 token 数之前先按requestId去重。 - 分析接口缓存 10 分钟 —— 突发用量高峰会延迟这么久才反映到仪表盘。
byModelDaily.date是 Unix 毫秒整数;byDate.date是YYYY-MM-DD字符串。- 来自 Venice 网页应用的用量
apiKeyId为null—— 对账时不要丢弃它。 - x402(钱包)余额不要用这些接口 —— 请用
GET /x402/balance/{walletAddress}。

Scan to join WeChat group