CYBERAUTOMATIONSStart a project
AI infrastructure and operationsIn daily use

One page for AI spend across four sources

One page that shows AI usage and spend across Ollama Cloud, a hosted model router, a LiteLLM gateway and Claude Code. A collector refreshes it every 30 minutes and never stores prompt text or key values.

usage sources merged
4
full refresh
30 min
Claude usage refresh
5 min

The problem

Once a team uses more than one model provider, spend is scattered. A hosted Ollama plan, a model router, a self-run LiteLLM gateway with dozens of virtual keys and Claude Code sessions each report usage in a different place, and some report nothing useful at all.

Nobody can answer simple questions quickly: which key is close to its limit, which program is making the calls, and which requests are failing.

The approach

  1. A Python collector reads every source read-only: gateway health, the map from model names to backends, virtual key names and the daily activity rollup (requests, tokens, spend and failures by model group, deployment and key).
  2. The gateway's own spend log adds error codes, retries and a caller table, so a failing integration can be traced to the program that made the call.
  3. Claude Code session logs are parsed locally and de-duplicated by message id and request id. Parsed files are cached by size and modified time, so each run only reads files that changed.
  4. Counts only. The collector never writes prompt or response text and never writes a key value. Keys are shown by their alias and at most their last four characters, and the output is checked for key values before it is saved.
  5. A scheduled task runs the full collection every 30 minutes. A lighter run refreshes only the Claude section every 5 minutes so the rolling 5-hour usage window stays current.
  6. The dashboard is one static HTML page that reads the JSON snapshot. There is no build step and no framework, so it can be dropped into any internal portal.

How it flows

SchedulerCollectorAI gatewaySession logsDashboardRun every 30 minutesRead usage and errorsCounts by model and keyParse only files that changedCheck for key valuesWrite one JSON snapshotPage reads the snapshot
  1. Scheduler to Collector: Run every 30 minutes
  2. Collector to AI gateway: Read usage and errors
  3. AI gateway to Collector: Counts by model and key
  4. Collector to Session logs: Parse only files that changed
  5. Collector: Check for key values
  6. Collector to Dashboard: Write one JSON snapshot
  7. Dashboard: Page reads the snapshot
One collection run. Counts only: no prompt text and no key values are written. Solid arrows are requests, dashed arrows are replies.
Show this diagram as Mermaid text
sequenceDiagram
    participant P0 as Scheduler
    participant P1 as Collector
    participant P2 as AI gateway
    participant P3 as Session logs
    participant P4 as Dashboard
    P0->>P1: Run every 30 minutes
    P1->>P2: Read usage and errors
    P2-->>P1: Counts by model and key
    P1->>P3: Parse only files that changed
    P1->>P1: Check for key values
    P1->>P4: Write one JSON snapshot
    P4->>P4: Page reads the snapshot

Tech stack

Collector
Python 3.12, standard library HTTP and JSON
Gateway data
LiteLLM admin endpoints and its Postgres spend log
Local data
Claude Code session logs (JSONL)
Front end
Static HTML with Chart.js 4
Scheduling
Operating system task scheduler, two jobs

Results

  • Four separate usage pages became one, and it stays current without anyone running a script.
  • Failures are now triaged from the dashboard: it lists error codes, retries and response latency next to the key and program that made the call.
  • Usage from a second machine is folded in, with a cached fallback when that machine's logs cannot be read.
  • We have not published a savings figure, because the dashboard measures spend rather than cutting it. What it gives is the picture you need to decide where to cut.

Every figure on this page comes from the project's own code, tests or notes. Where there is no measured number, we describe the outcome in words.

Demo

Collector usage
python collect_llm_stats.py                (full snapshot, then exit)
python collect_llm_stats.py --claude-only  (refresh the Claude section only)

# Scheduled: full snapshot every 30 min, Claude-only every 5 min.
# Output: one JSON snapshot. Counts only: no prompt or response text,
# no key values. Keys are named by alias plus the last 4 characters at most.
The collector's two run modes, from its own usage notes.

A dashboard screenshot and a sample cost breakdown are being prepared with private figures removed.

Source code

The source is being prepared for public release. Until then, contact us for a walkthrough of AI Usage Dashboard.

Service

Private AI infrastructure

LLM gateways, model routing and cost control, run on infrastructure you own.

See all custom build services

More builds

Last updated 2026-11-10

Want something like this on your data?

Tell us what you want automated. If it fits, we will tell you exactly what it looks like and what it costs.