Commit c2e522f
feat: cc.billing — per-call cache-tier attribution, exact to API usage
Lays each LLM call's request out as ordered pieces (static config prefix,
then the conversation in transcript order) and cuts by position against the
call's usage: [0,R) cache_read, [R,R+W) cache_creation, tail fresh — prompt
caching is prefix-based, so position determines the billing tier. Output is
booked from per-block attributed tokens.
Exactness contract, validated per call and therefore per trace (trace usage
is the sum of its spans): by_lane columns — including an explicit
`unattributed` row that absorbs unparsed content (system reminders, request
envelope) and estimation drift — sum exactly to input_tokens, cache_read,
cache_creation and output_tokens. Usage-derived pieces are never rescaled;
estimates shrink proportionally only on overshoot.
Tier tokens are per-call billing events: additive across calls, traces and
periods, so plain SUM aggregation reproduces the API bill exactly — no
cumulative weighting needed for the billed view.
Verified against two real sessions (5 calls each): totals and lane sums
match measured usage to the token on all four columns.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent d4f08d1 commit c2e522f
3 files changed
Lines changed: 639 additions & 0 deletions
0 commit comments