September 2026
Intermediate
206 pages
5h 13m
English
You can’t optimize what you can’t measure. That sentence has become a cliche in software engineering, but it’s especially true for LLM costs because the metrics you need don’t exist by default. Your cloud provider gives you a monthly bill. Your LLM API gives you per-request token counts buried in response headers. Nobody gives you “cost per feature” or “tokens per user” out of the box. You have to build that yourself.
This chapter builds the core of tokenwatch: a metering middleware that wraps every LLM call, extracts token usage from the API response, calculates real costs using your pricing configuration, tags the usage with metadata (feature, user, team), and stores everything ...
Read now
Unlock full access