Privacy

Accept optional first-party analytics or decline. Functional journey and sound preferences stay on this device.

Read the privacy notice
ProjectJuly 13, 2026

LLM Cost & Behavior Tracing

Every LLM call across the platform is traced — model, tokens, prompt, answer and USD cost — and surfaced in an admin dashboard, so AI spend and behavior are never a black box.

Category
AI & RAG
Tech stack
  • FastAPI
  • Python
  • Claude API
  • OpenAI API
Metrics
  • 100% of LLM calls traced
  • Per-call USD cost attribution
Role
Design + build
Alex CMS analytics dashboard showing LLM cost tracing: $1.24 total, 407 calls, cost broken down by model

A tracing layer wraps every model call in Alex OS (Claude and OpenAI) and writes a structured record per call: model, token counts, prompt, response and computed USD cost. Traces are rendered in a dedicated LLM tab on the admin analytics page, making it possible to audit any AI feature end-to-end and spot cost regressions immediately.

AI features quietly accumulate API costs and it is hard to answer "what did that answer cost, and what prompt produced it?" after the fact.

Traces are written to an append-only JSONL file rather than a database table: no migration to run, no write load on the CMS database, and the whole history stays greppable. The wrapping happens at the client layer instead of inside each feature, so every new AI feature is traced from its first call whether or not its author thought about observability. USD cost is computed per call and stored in the trace itself, so spend reports read straight from the record instead of being recomputed later.

Traces store prompts and answers verbatim — that is exactly what makes them useful for auditing behavior, and it also means the trace log is itself sensitive and stays behind the admin.

Complete per-call audit trail of AI usage and spend across the whole platform.

Built with AI assistance (Claude Code). The architecture, the decisions and the trade-offs are mine; a lot of the implementation was written in pair with the model. I work this way deliberately — it's why one person can run a system this size — and the reasoning behind every call here is documented above.


aiobservabilitycostsystem