Stats
Query project-wide analytics and usage data.
Auth: Platform key (sk_pj_*) required.
Get Overview
GET /v1/platform/analytics/overview
Returns aggregated statistics for a date range.
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
from | string | Yes | Start date (ISO 8601) |
to | string | Yes | End date (ISO 8601) |
const overview = await billing.analytics.getOverview({
from: '2025-01-01',
to: '2025-01-31',
})Response
{
"total_requests": 125000,
"total_cost": "892.340000",
"total_input_tokens": 30000000,
"total_output_tokens": 15000000,
"avg_latency": 1250,
"error_count": 1500,
"cache_hits": 42500
}| Field | Type | Required | Description |
|---|---|---|---|
total_requests | number | Always | Total request count |
total_cost | string | Always | Total cost in USD |
total_input_tokens | number | Always | Sum of input tokens |
total_output_tokens | number | Always | Sum of output tokens |
avg_latency | number? | Always | Average latency in milliseconds, or null |
error_count | number | Always | Total error count |
cache_hits | number | Always | Number of cache hits |
Get Timeseries
GET /v1/platform/analytics/timeseries
Returns daily breakdown of usage metrics.
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
from | string | Yes | Start date (ISO 8601) |
to | string | Yes | End date (ISO 8601) |
const timeseries = await billing.analytics.getTimeseries({
from: '2025-01-01',
to: '2025-01-07',
})Response
{
"data": [
{
"date": "2025-01-01",
"requests": 18000,
"tokens": 6500000,
"cost_usd": "128.500000",
"avg_latency_ms": 1180,
"errors": 215
}
]
}| Field | Type | Required | Description |
|---|---|---|---|
date | string | Always | Day bucket (ISO 8601 date) |
requests | number | Always | Request count for that day |
tokens | number | Always | Total tokens for that day |
cost_usd | string | Always | Cost for that day |
avg_latency_ms | number | Always | Average latency in milliseconds |
errors | number | Always | Error count for that day |
Get Cache Stats
GET /v1/platform/cache/stats
Returns cache hit/miss metrics for a date range.
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
from | string | Yes | Start date (ISO 8601) |
to | string | Yes | End date (ISO 8601) |
const cache = await billing.cache.getStats({
from: '2025-01-01',
to: '2025-01-31',
})Response
{
"total_requests": 125000,
"cache_hits": 42500,
"cache_misses": 82500,
"hit_rate": 0.34
}| Field | Type | Required | Description |
|---|---|---|---|
total_requests | number | Always | Total requests in range |
cache_hits | number | Always | Number of cache hits |
cache_misses | number | Always | Number of cache misses |
hit_rate | number | Always | Hit rate (0-1) |