[OPIK-7392] [BE] fix: split cipx cache-creation tokens by TTL (5m vs 1h) - #7565
Conversation
Cache writes are billed by TTL (5-minute = 1.25x input, 1-hour = 2x input) and Claude Code writes its cache with a 1-hour TTL, but cipx_spends collapsed the split into a single u_cache_creation lump, so AI-spend priced everything at the 5m rate (~18% cost understatement). - migration 000109: add u_cache_creation_5m / u_cache_creation_1h to cipx_spends - CipxSpendDAO: parse and persist the split from usage.cache_creation - CipxSpendBlockDAO: a span is a single LLM call with one TTL, so each write block inherits the span's TTL into its tier (cache_creation_5m / _1h) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
⏱️ pre-commit per-hook timing
⏭️ 40 skipped (no matching files changed)
|
|
|
||
| -- Anthropic bills cache writes by TTL: 5-minute at 1.25x input, 1-hour at 2x input. Claude Code | ||
| -- writes its stable prefix with a 1-hour TTL, so pricing every cache-creation token at the 5m rate | ||
| -- understates cost (~18% in practice). The proxy already emits the split on |
There was a problem hiding this comment.
Doubt that these kind of comments are valid for a DAO object in Opik repo :)
"understates cost (~18% in practice)"
Moreover IMO in OSS repo we should try to be as mean with cost explaining comments as possible
There was a problem hiding this comment.
Fixed in a44dc78 — trimmed the migration comment to the technical schema change (what the split columns are and that the proxy emits them), dropping the pricing/cost rationale. That business context lives in the cost-api repo where the pricing actually happens. Good call keeping the OSS side lean.
🤖 Reply posted via /address-github-pr-comments
There was a problem hiding this comment.
Commit a44dc78 addressed this comment by removing the detailed cost/pricing explanation from the DAO migration comment while retaining only the relevant technical context.
Address PR #7565 review: keep the OSS migration comment to the technical schema change (what the columns are and their source), dropping the pricing/cost explanation, which lives in the cost-api repo. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Details
Persists the 5-minute vs 1-hour cache-creation split so AI-spend can price 1h cache writes at 2× input. Previously
cipx_spendscollapsed the split into a singleu_cache_creationlump, so cost was computed at the 5m rate (1.25× input) for all cache-creation tokens — a ~18% understatement, since Claude Code writes its cache with a 1-hour TTL (2× input).000109: addu_cache_creation_5m/u_cache_creation_1htocipx_spendsCipxSpendDAO: parse and persist the split fromusage.cache_creationCipxSpendBlockDAO: a cipx span is a single LLM call with one cache TTL, so each write block inherits the span's TTL into itstier(cache_creation_5m/cache_creation_1h); legacy rows keepcache_creationand are read as 1h downstreamChange checklist
Issues
AI-WATERMARK
AI-WATERMARK: yes
/usageTesting
CostIntelligenceIngestionTestextended with 5m/1h split assertions and a parameterized write-block TTL-inheritance test.cipx_spends.u_cache_creation_1handcipx_spend_blocks.tier='cache_creation_1h'populate correctly, and the AI-spend UI total matches/usageto the cent.Paired cost-api change that applies the pricing: comet-ml/ai-cost-backend#36
Important
Deploy order: this migration (000109) must be deployed before the cost-api change, which reads the new columns.
Documentation
N/A