feat(usage): input_cache_write_1h dimension + per-TTL cache parser#68
Merged
Conversation
…ache parser Anthropic's `extended-cache-ttl-2025-04-11` beta surfaces 1-hour cache writes under `usage.cache_creation.ephemeral_1h_input_tokens`. Until now we folded both 5m and 1h writes into the same `input_cache_write` bucket, under-billing 1h writes (priced at input × 2 vs. input × 1.25 for 5m). Adds `input_cache_write_1h` as a disjoint billing dimension with the fallback chain 1h -> 5m -> input, and teaches the Messages parser to read `cache_creation.ephemeral_5m_input_tokens` / `ephemeral_1h_input_tokens` separately when the sub-object is present; falls back to the flat `cache_creation_input_tokens` when not. Threads the new dimension through the surfaces that hardcode the billing dimension list — the upstream-model zod schema, the `pricingField` / custom `/v1/models` cost parsers (now driven off `BILLING_DIMENSIONS` to follow any future additions), the dashboard usage page (Cache Write column folds both TTLs), and the model editor (separate 5m and 1h input fields so operators on custom upstreams can price each).
…write_1h SQLite cannot alter a CHECK constraint in place, so widening the `usage.dimension` list to admit `input_cache_write_1h` requires recreating the table. `usage_requests` is untouched: it has no dimension column. Existing rows backfill cleanly into the recreated table; aggregation treats them identically to before.
3 tasks
1990ca3 to
92685bd
Compare
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
input_cache_write_1hBillingDimension — Anthropic'sextended-cache-ttl-2025-04-11beta surfaces 1-hour cache writes underusage.cache_creation.ephemeral_1h_input_tokens. Previously these folded into the sameinput_cache_writebucket, under-billing 1h writes (priced at input × 2 vs input × 1.25 for 5m).cache_creation.ephemeral_5m_input_tokens/ephemeral_1h_input_tokensseparately when the sub-object is present; falls back to the flatcache_creation_input_tokenswhen not (preserves old upstream-shape compatibility).0035_usage_input_cache_write_1h.sql— SQLite recreate pattern (CHECK changes need rebuild). Widens dimension CHECK list withinput_cache_write_1h. Existing rows backfill cleanly.Test plan