<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged token-tracking</title>
<link>https://coderlegion.com/tag/token-tracking</link>
<description>Powered by Question2Answer</description>
<item>
<title>The Price of Everything ... checked by `jq empty`</title>
<link>https://coderlegion.com/22200/the-price-of-everything-checked-by-jq-empty</link>
<description>&lt;p&gt;Every &lt;strong&gt;AI usage cost&lt;/strong&gt; monitoring tool runs the same multiplication: tokens from a log file times a &lt;strong&gt;price&lt;/strong&gt; from a table. &lt;/p&gt;
&lt;p&gt;The tokens are easy. Claude Code and its cousins write them to disk with model names attached. &lt;br&gt;
The &lt;strong&gt;price&lt;/strong&gt; is the interesting part, because almost the whole ecosystem gets it from one place: &lt;strong&gt;LiteLLM's&lt;/strong&gt; community price map, about 2,783 models in a single JSON file, in a repo with roughly 51k stars. &lt;strong&gt;ccusage&lt;/strong&gt;, at 16.4k stars itself, re-pins it hourly. &lt;strong&gt;tokencost&lt;/strong&gt; vendors a copy. &lt;strong&gt;ccost&lt;/strong&gt; embeds it. When that file is wrong, everyone is wrong together, in the same direction, with the same confidence.&lt;/p&gt;
&lt;h4 id=&quot;the-only-automated-quality-check-on-that-file-is-jq-empty-&quot;&gt;The only automated quality check on that file is &lt;code&gt;jq empty&lt;/code&gt;.&lt;/h4&gt;
&lt;p&gt;Your linter has stronger opinions about import order than the ecosystem has about whether a million Grok tokens cost 💲2.00  or  💲1.25.  Money-adjacent data, maintained with less rigor than a lint rule. I don't know about you, but it bothers me.&lt;/p&gt;
&lt;p&gt;That is not a simplification. &lt;code&gt;jq empty&lt;/code&gt; confirms the JSON parses. No value validation, no cross-check against the provider's published page, no guard against swapping input and output prices. Nothing dates a record or says who verified it. The number your cost dashboard multiplies by a month of token counts clears CI the moment it is syntactically valid. &lt;/p&gt;
&lt;h3 id=&quot;the-543-branch&quot;&gt;The 💲543 branch&lt;/h3&gt;
&lt;p&gt;One Saturday morning I grouped a month of my spend by project and branch, mostly out of curiosity. The month came to about 💲2,770. One feature branch, a big Rails plus SvelteKit UI refactor, had eaten 💲543 on its own, more than everything else on that client combined. The tiny PR branch next to it: 💲32.&lt;/p&gt;
&lt;p&gt;The mechanism was the retry loop. A complex multi-file refactor fails halfway, and the retry re-sends the entire &lt;strong&gt;80K-plus&lt;/strong&gt; token context. You revert, you try again, same cost, nothing shipped. You never feel it per message. You feel it at month end, as a lump.&lt;/p&gt;
&lt;p&gt;Tools existed to show me this after the fact. &lt;strong&gt;ccusage&lt;/strong&gt; and its relatives parse the same logs and render perfectly good totals. What I wanted did not exist: something that enforces a limit instead of a dashboard you check once the damage is done. &lt;/p&gt;
&lt;p&gt;So I built the open-source &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/RoninForge/budgetclaw&quot;&gt;BudgetClaw&lt;/a&gt;, a single static Go binary that tails the session logs with &lt;code&gt;fsnotify&lt;/code&gt;, computes cost in real time, and on a breach sends &lt;code&gt;SIGTERM&lt;/code&gt; to the Claude process and mobile notifications via &lt;a rel=&quot;nofollow&quot; href=&quot;https://ntfy.sh/&quot;&gt;ntfy&lt;/a&gt;. &lt;strong&gt;ccusage&lt;/strong&gt; tells you what you spent; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/RoninForge/budgetclaw&quot;&gt;BudgetClaw&lt;/a&gt; stops you from spending it.&lt;/p&gt;
&lt;p&gt;Which is exactly where I hit the wall.&lt;/p&gt;
&lt;h3 id=&quot;enforcement-is-only-as-good-as-the-multiplication&quot;&gt;Enforcement is only as good as the multiplication&lt;/h3&gt;
&lt;p&gt;Cache pricing is what makes this unforgiving: a cache read bills at 0.1x the base input rate, a 5-minute cache write at &lt;em&gt;1.25x&lt;/em&gt;, a 1-hour cache write at &lt;em&gt;2x&lt;/em&gt;. Get one multiplier or one base rate slightly wrong and every per-branch figure is quietly off. For a tool whose entire value is &quot;&lt;em&gt;trust this number&lt;/em&gt;&quot;, quietly off is not acceptable in my book. So before shipping, I read how the price table everyone depends on is actually maintained.&lt;/p&gt;
&lt;h3 id=&quot;the-litellm-autopsy&quot;&gt;The LiteLLM autopsy&lt;/h3&gt;
&lt;p&gt;Start with a concrete case. Four &lt;code&gt;xai/grok-4.20-*&lt;/code&gt; rows in LiteLLM's map, each citing its source:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;in the map:        $2.00 / $6.00 per 1M tokens (input / output)
cited docs.x.ai:   $1.25 / $2.50
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The entry contradicts its own citation, and nothing in the pipeline can notice, because the pipeline checks that the file parses and stops there. It gets worse the deeper you read. Input and output prices have been transposed in the past with no guard to catch it. A &lt;code&gt;source&lt;/code&gt; field is present on only about 31 percent of records. There are no &lt;code&gt;last_validated&lt;/code&gt;, &lt;code&gt;confidence&lt;/code&gt;, or date fields at all, and no history: when a price changes the old value is overwritten and gone, so nobody can answer what a model cost in March. Governance compounds it. &lt;/p&gt;
&lt;p&gt;The default branch is &lt;code&gt;litellm_internal_staging&lt;/code&gt;, the public &lt;code&gt;main&lt;/code&gt; can run about nine days stale and serve a bug already fixed on staging, and a bulk staging sync can overwrite a community fix after it merges. A correction can land, merge, and silently regress.&lt;/p&gt;
&lt;p&gt;The &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/ccusage/ccusage/issues/764&quot;&gt;ccusage community already knows&lt;/a&gt; , the request is closed unresolved, and &lt;strong&gt;ccusage&lt;/strong&gt; keeps applying today's prices to all historical data, so costs do not reflect what was actually charged at the time. The upstream data model cannot express it, because the upstream data model deletes the past.&lt;/p&gt;
&lt;h3 id=&quot;a-28-line-control-experiment&quot;&gt;A 28-line control experiment&lt;/h3&gt;
&lt;p&gt;I did not want to write about a bug I had not tried to fix, so I filed the fix. &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/BerriAI/litellm/pull/30849&quot;&gt;BerriAI/litellm#30849&lt;/a&gt;, Twenty-eight lines, touching both the root map and the bundled backup so they could not drift on this model, plus the cost-calculator test that did not exist, so the corrected number could not silently regress.&lt;/p&gt;
&lt;p&gt;Weeks later it sits open and unmerged, reviewed by exactly three entities: a CLA signature bot, greptile, and codecov. No human has looked at it. The lazy reading is &quot;maintainers bad&quot;, and the lazy reading is wrong. The repo fields roughly 1,158 pricing PRs. No volunteer team hand-verifies that volume against provider pages, which is precisely why the only gate is &lt;code&gt;jq empty&lt;/code&gt;: it is the one check that scales without humans. The failure is structural. Money-adjacent data needs the rigor of money, and a JSON parse check is not that, however good the people running it are.&lt;/p&gt;
&lt;h3 id=&quot;correctness-is-a-provenance-problem&quot;&gt;Correctness is a provenance problem&lt;/h3&gt;
&lt;p&gt;My first instinct was the obvious wrong one: fork it, cover more models, do it better. Then I realised: nobody's cost tool broke because model 2,784 was missing; mine would have broken because one number among the 94 I use was wrong, uncited, and undated. One bad price kills a cost tool; 2,700 correct ones do not save it.&lt;/p&gt;
&lt;p&gt;So the thing I built is not a bigger table. It is an automated price sentinel, published as &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/RoninForge/ai-price-index&quot;&gt;ai-price-index&lt;/a&gt;. A bot diffs each provider's own official pricing page; a human - mostly me,  verifies every change before it lands. Every record carries a first-party source URL, an effective date, a &lt;code&gt;last_validated&lt;/code&gt; date, and a confidence label. The dataset is bitemporal: a correction supersedes the old row, it never deletes it, so the audit trail survives its own fixes. Point-in-time lookup is a first-class operation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;priceOn(&quot;gpt-4&quot;, &quot;2023-06-01&quot;) // the rate in effect that day, not today's
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As of this writing the index holds 94 models across 11 providers, 202 current price rows, and history back to GPT-4's launch in March 2023. It ships as an open dataset (CC-BY-4.0 data, MIT tooling) with raw JSON, an npm library, and a zero-key MCP server, on the theory that a reference table is only useful if it is easier to reuse than to re-scrape. Found a wrong price? Send a PR with the source.&lt;/p&gt;
&lt;h3 id=&quot;one-table-under-everything&quot;&gt;One table under everything&lt;/h3&gt;
&lt;p&gt;The payoff is boring, which is how I know it is real. That single audited table is now the shared backbone for &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/RoninForge/budgetclaw&quot;&gt;BudgetClaw&lt;/a&gt; and a handful of small, free, fully client-side cost tools on &lt;a rel=&quot;nofollow&quot; href=&quot;https://roninforge.org&quot;&gt;roninforge.org&lt;/a&gt;: &lt;a rel=&quot;nofollow&quot; href=&quot;https://roninforge.org/claude-code-spend-analyzer/&quot;&gt;a Claude Code spend analyzer&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://roninforge.org/anthropic-cost-analyzer/&quot;&gt;an Anthropic cost analyzer&lt;/a&gt; with per-API-key attribution, &lt;a rel=&quot;nofollow&quot; href=&quot;https://roninforge.org/ai-price-index/&quot;&gt;the price explorer itself&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://roninforge.org/copilot-bill-migrator/&quot;&gt;a couple of Copilot bill calculators&lt;/a&gt;. They parse your local exports in the browser and upload nothing, and because every one reads the same sourced, dated rows, their numbers cannot drift apart. None of them has an interesting UI. What they have is a price table with receipts.&lt;/p&gt;
&lt;p&gt;Parsing the logs is the easy 90 percent; the tokens sit on your own disk with model names attached. The dollar at the bottom of the report is a different kind of claim. It is only worth trusting if someone kept the receipt for the price, and today, for most of the AI cost stack, that receipt is a JSON file whose sole certification is that it parses. &lt;code&gt;jq empty&lt;/code&gt; can tell you a price table is valid. It cannot tell you it is true.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/22200/the-price-of-everything-checked-by-jq-empty</guid>
<pubDate>Fri, 10 Jul 2026 09:50:57 +0000</pubDate>
</item>
</channel>
</rss>