Assistant Billing

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

NameTypeRequiredDescription
fromstringYesStart date (ISO 8601)
tostringYesEnd 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
}
FieldTypeRequiredDescription
total_requestsnumberAlwaysTotal request count
total_coststringAlwaysTotal cost in USD
total_input_tokensnumberAlwaysSum of input tokens
total_output_tokensnumberAlwaysSum of output tokens
avg_latencynumber?AlwaysAverage latency in milliseconds, or null
error_countnumberAlwaysTotal error count
cache_hitsnumberAlwaysNumber of cache hits

Get Timeseries

GET /v1/platform/analytics/timeseries

Returns daily breakdown of usage metrics.

Query Parameters

NameTypeRequiredDescription
fromstringYesStart date (ISO 8601)
tostringYesEnd 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
    }
  ]
}
FieldTypeRequiredDescription
datestringAlwaysDay bucket (ISO 8601 date)
requestsnumberAlwaysRequest count for that day
tokensnumberAlwaysTotal tokens for that day
cost_usdstringAlwaysCost for that day
avg_latency_msnumberAlwaysAverage latency in milliseconds
errorsnumberAlwaysError count for that day

Get Cache Stats

GET /v1/platform/cache/stats

Returns cache hit/miss metrics for a date range.

Query Parameters

NameTypeRequiredDescription
fromstringYesStart date (ISO 8601)
tostringYesEnd 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
}
FieldTypeRequiredDescription
total_requestsnumberAlwaysTotal requests in range
cache_hitsnumberAlwaysNumber of cache hits
cache_missesnumberAlwaysNumber of cache misses
hit_ratenumberAlwaysHit rate (0-1)