Facturación
Analíticas de uso de facturación (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>"
}Este es un endpoint en beta y puede ser inestable o cambiar sin previo aviso.
Parámetros de consulta
Puedes especificar el periodo de tiempo para las analíticas mediante:- lookback: un periodo relativo como “7d” (7 días), “30d” (30 días), hasta “90d” (90 días)
- startDate y endDate: un rango de fechas personalizado en formato
YYYY-MM-DD. Envía ambos para usar un rango personalizado.
Si envías solo uno de
startDate o endDate, la solicitud no falla: devuelve 200 usando el lookback predeterminado de 7 días e ignora la fecha, sin ninguna advertencia. Envía siempre ambos juntos.Un lookback superior a 90 días se limita a 90d. Un rango startDate/endDate superior a 90 días devuelve 400.Campos de respuesta
lookback
El periodo de lookback utilizado para la consulta. Puede estar en formato “Nd” (p. ej., “7d”) o “startDate:endDate”.byDate
Totales de uso diarios para el periodo solicitado.- date: la fecha en formato
YYYY-MM-DD - USD: uso total en USD para ese día
- DIEM: uso total en DIEM para ese día
byModel
Desglose de uso por modelo, ordenado por gasto total (mayor primero).- modelName: nombre del modelo para mostrar (p. ej., “GLM 5”)
- unitType: tipo de unidades consumidas (tokens, images, chars, minutes, seconds)
- modelType: tipo de modelo (LLM, IMAGE, TTS, ASR, VIDEO), o null
- totalUsd: total en USD gastado en este modelo
- totalDiem: total en DIEM gastado en este modelo
- totalUnits: total de unidades consumidas para este modelo
- breakdown: array de desgloses de uso por tipo (solo presente si hay múltiples tipos). Cada entrada contiene:
- type: tipo de token (p. ej., “Input”, “Output”, “Cache Read”, “Cache Write”)
- usd: importe en USD para este desglose
- diem: importe en DIEM para este desglose
- units: número de unidades para este desglose
byModelDaily
Datos de gráfico diarios para los 8 modelos principales. Cada entrada contiene una “date” (timestamp) más los nombres de modelo como claves con valores de uso en DIEM.topModels
Array de los 8 nombres de modelos principales por uso, para leyendas de gráficos.byKey
Desglose de uso por API key, ordenado por gasto total (mayor primero).- apiKeyId: el ID de la API key, o null si el uso provino de la aplicación web
- description: descripción de la API key o “Web App”
- totalUsd: total en USD gastado mediante esta clave
- totalDiem: total en DIEM gastado mediante esta clave
- totalUnits: total de unidades consumidas mediante esta clave
byKeyDaily
Datos de gráfico diarios para las 8 API keys principales. Cada entrada contiene una “date” (timestamp) más las descripciones de las claves como claves con valores de uso en DIEM.topKeyNames
Array de las 8 descripciones de API key principales por uso, para leyendas de gráficos.Ejemplo de uso
# Obtener analíticas de uso de los últimos 7 días (predeterminado)
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics" \
-H "Authorization: Bearer YOUR_API_KEY"
# Obtener analíticas de uso de los últimos 30 días
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics?lookback=30d" \
-H "Authorization: Bearer YOUR_API_KEY"
# Obtener analíticas de uso para un rango de fechas específico
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"
Autorizaciones
Parámetros de consulta
Respuesta
Successful response with aggregated usage analytics
Aggregated usage analytics response with breakdowns by date, model, and API key
¿Esta página le ayudó?
⌘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>"
}