Commit 0aa0f8e
JSONbored
fix(observability): count the prompt-cache tiers as input tokens for the CLI providers
Every claude-code call recorded exactly ~2 input tokens. Measured on edge-nl-01 over
48h: 2048 input tokens across 1000 calls -- an average of 2.0 -- against 1051 output
tokens per call and $225.06 of real spend. An average of 2.0 over a thousand calls is
not a measurement, it is a constant.
Anthropic, and therefore Claude Code, splits one prompt across three counters:
input_tokens carries only the portion neither read from nor written to the prompt
cache, with the rest in cache_read_input_tokens and cache_creation_input_tokens.
INPUT_TOKEN_KEYS read only the first, so with caching active -- which it is on every
review the CLI runs -- the figure degenerated to the handful of genuinely-new tokens.
These are real input tokens: the model processed them and they are billed, cache reads
at a reduced rate. Each tier gets its OWN alias group because the three are additive
components of one prompt, not names for one value; folding them into INPUT_TOKEN_KEYS
would take the maximum of the three and silently under-report again, just less
severely. Absence is still absence -- an envelope reporting no input counter at all
yields undefined rather than a fabricated 0 (#10207), and a tier present but zero
contributes a real zero.
Providers that emit no cache keys -- codex and the OpenAI-compatible bindings -- are
byte-identical to before, which is what makes this safe at the shared extraction
point. loopover_ai_input_tokens_total is corrected by the same change, since it reads
the same usage.inputTokens.
coerceByokUsage (src/services/ai-review.ts) is deliberately NOT changed. It already
documented these two keys and declined them, because callAiProvider never sends
cache_control so the provider never populates them there, and it feeds
BYOK_MODEL_PRICING_USD_PER_MTOK where a cache read bills at a different rate than
fresh input. Its comment now records that the divergence from the CLI path is
intentional rather than an oversight.
Closes #102351 parent ee1b86e commit 0aa0f8e
3 files changed
Lines changed: 76 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
796 | 796 | | |
797 | 797 | | |
798 | 798 | | |
| 799 | + | |
| 800 | + | |
799 | 801 | | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
800 | 822 | | |
801 | 823 | | |
802 | 824 | | |
| |||
819 | 841 | | |
820 | 842 | | |
821 | 843 | | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
822 | 862 | | |
823 | 863 | | |
824 | 864 | | |
| |||
829 | 869 | | |
830 | 870 | | |
831 | 871 | | |
832 | | - | |
| 872 | + | |
833 | 873 | | |
834 | 874 | | |
835 | 875 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2009 | 2009 | | |
2010 | 2010 | | |
2011 | 2011 | | |
2012 | | - | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
2013 | 2017 | | |
2014 | 2018 | | |
2015 | 2019 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1618 | 1618 | | |
1619 | 1619 | | |
1620 | 1620 | | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
1621 | 1651 | | |
1622 | 1652 | | |
1623 | 1653 | | |
| |||
0 commit comments