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
- 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).
- 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.
- 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.
- 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.
- 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.
- 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
- Scheduler to Collector: Run every 30 minutes
- Collector to AI gateway: Read usage and errors
- AI gateway to Collector: Counts by model and key
- Collector to Session logs: Parse only files that changed
- Collector: Check for key values
- Collector to Dashboard: Write one JSON snapshot
- Dashboard: Page reads the snapshot
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 snapshotTech 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
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.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.
Related
Service
Private AI infrastructure
LLM gateways, model routing and cost control, run on infrastructure you own.
See all custom build servicesFree tools built the same way
More builds
- AI Stack CVE Labs: Security research
- Agentic Agency: Agent framework
- Geo-Intel: Data pipeline
- Security Knowledge Base: Knowledge base
- RapidAPI MCP: API integration
- Claude Budget: AI spend control
- Flightdeck: Agent operations
- Niagara BQL and NEQL Reference: OT reference
- IG Sanitize: Privacy tool
- WinHostPEAS: Security tooling
Last updated 2026-11-10