账单
账单用量分析(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.
GET
/
billing
/
usage-analytics
/api/v1/billing/usage-analytics
curl --request GET \
--url https://api.venice.ai/api/v1/billing/usage-analytics \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.venice.ai/api/v1/billing/usage-analytics"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.venice.ai/api/v1/billing/usage-analytics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.venice.ai/api/v1/billing/usage-analytics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.venice.ai/api/v1/billing/usage-analytics"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.venice.ai/api/v1/billing/usage-analytics")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.venice.ai/api/v1/billing/usage-analytics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"lookback": "7d",
"byDate": [
{
"date": "2024-01-15T00:00:00.000Z",
"USD": 0.5,
"DIEM": 10.25
},
{
"date": "2024-01-14T00:00:00.000Z",
"USD": 0.3,
"DIEM": 8.75
}
],
"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
}
],
"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
}
],
"topKeyNames": [
"Production Key",
"Web App"
]
}{
"error": "<string>",
"details": {
"_errors": [],
"field": {
"_errors": [
"Field is required"
]
}
}
}{
"error": "<string>"
}{
"error": "This API key is restricted to configured IP addresses, and this request's source IP is not allowed"
}{
"error": "<string>"
}{
"error": "<string>"
}这是一个 beta 端点,可能不稳定或在无通知的情况下变更。
查询参数
您可以使用以下任一方式指定分析的时间段:- lookback:相对时间段,例如 “7d”(7 天)、“30d”(30 天),最长 “90d”(90 天)
- startDate 和 endDate:以
YYYY-MM-DD格式自定义日期范围。若要使用自定义范围,请同时发送两者。
如果只发送
startDate 或 endDate 其中之一,请求不会失败:它会返回 200,使用默认的 7 天 lookback 并忽略该日期,且不会给出任何警告。请务必同时发送两者。超过 90 天的 lookback 会被限制为 90d。超过 90 天的 startDate/endDate 范围会返回 400。响应字段
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 密钥描述数组,用于图表图例。使用示例
# 获取过去 7 天的用量分析(默认)
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics" \
-H "Authorization: Bearer YOUR_API_KEY"
# 获取过去 30 天的用量分析
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics?lookback=30d" \
-H "Authorization: Bearer YOUR_API_KEY"
# 获取特定日期范围的用量分析
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics?startDate=2024-01-01&endDate=2024-01-31" \
-H "Authorization: Bearer YOUR_API_KEY"
授权
查询参数
响应
Successful response with aggregated usage analytics
Aggregated usage analytics response with breakdowns by date, model, and API key
⌘I
/api/v1/billing/usage-analytics
curl --request GET \
--url https://api.venice.ai/api/v1/billing/usage-analytics \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.venice.ai/api/v1/billing/usage-analytics"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.venice.ai/api/v1/billing/usage-analytics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.venice.ai/api/v1/billing/usage-analytics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.venice.ai/api/v1/billing/usage-analytics"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.venice.ai/api/v1/billing/usage-analytics")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.venice.ai/api/v1/billing/usage-analytics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"lookback": "7d",
"byDate": [
{
"date": "2024-01-15T00:00:00.000Z",
"USD": 0.5,
"DIEM": 10.25
},
{
"date": "2024-01-14T00:00:00.000Z",
"USD": 0.3,
"DIEM": 8.75
}
],
"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
}
],
"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
}
],
"topKeyNames": [
"Production Key",
"Web App"
]
}{
"error": "<string>",
"details": {
"_errors": [],
"field": {
"_errors": [
"Field is required"
]
}
}
}{
"error": "<string>"
}{
"error": "This API key is restricted to configured IP addresses, and this request's source IP is not allowed"
}{
"error": "<string>"
}{
"error": "<string>"
}