Report model token counts in status --json
What
With the real-model proxy running, status --json --usage reads the proxy's request, input-token and output-token totals, in all and per model, into state as model_usage, stamped with read_at. status --json surfaces it under schema_version 3. It reads null while no proxy runs (the mock model and the direct arms record nothing), and real-model off clears it.
How
- Endpoint: LiteLLM's own Prometheus
/metricson the loopback listener, pinned image v1.100.0. The proxy runs with no database, so its spend endpoints (/spend/logs,/global/spend/*) have nothing behind them; the config gains theprometheuscallback, and/metricsasks for no key. - Series read:
litellm_requests_metric_total,litellm_input_tokens_metric_total,litellm_output_tokens_metric_total, summed by themodellabel. - Pulled on demand by
status --usage; no daemon. - The proxy answers
/metricswith 401 unlessrequire_auth_for_metrics_endpoint: false, sogce/litellm/config.yamlsets it. The listener binds 127.0.0.1; the alternative is handing the reader the master key./metricsthen redirects (307) to/metrics/, whichusage.shfollows, and it exits non-zero on a body with nolitellm_series so a bad answer never reads as zero. - Redaction: those series carry key hashes and aliases, so
gce/litellm/usage.shruns on the VM and keeps three counts per model. Only model names and numbers cross ssh. No master key or virtual key is read, and none reaches state or output.status --jsoncutsmodel_usageto a fixed key list. - Word budget stays at its ceiling: the paragraph added to
gce/operations.mdis paid for by trims in the same file.
Test
The engine self-test feeds a stub /metrics body carrying a planted key hash, alias and prompt-like label, and asserts the totals land in state, the planted values appear nowhere in output or state, the mock model (no proxy) records none, and a failed read keeps the last reading.
Live run
One GCE VM, real-model proxy on Vertex (gemini-2.5-flash), model calls through the lab. status --json --usage | jq '.model_usage' returned {"read_at":"2026-11-17T06:35:20Z","source":"litellm /metrics","requests":12,"input_tokens":96,"output_tokens":147,"models":{"gemini-2.5-flash":{...}}}. The state file held no key or hash. The VM is deleted.
Closes #24 (closed)