Skip to content

feat(usage): input_cache_write_1h dimension + per-TTL cache parser#68

Merged
Menci merged 2 commits into
mainfrom
precursor-input-cache-write-1h
Jun 20, 2026
Merged

feat(usage): input_cache_write_1h dimension + per-TTL cache parser#68
Menci merged 2 commits into
mainfrom
precursor-input-cache-write-1h

Conversation

@Menci

@Menci Menci commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • input_cache_write_1h BillingDimension — Anthropic's extended-cache-ttl-2025-04-11 beta surfaces 1-hour cache writes under usage.cache_creation.ephemeral_1h_input_tokens. Previously these folded into the same input_cache_write bucket, under-billing 1h writes (priced at input × 2 vs input × 1.25 for 5m).
  • Per-TTL cache parser — Messages parser reads 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 (preserves old upstream-shape compatibility).
  • Migration 0035_usage_input_cache_write_1h.sql — SQLite recreate pattern (CHECK changes need rebuild). Widens dimension CHECK list with input_cache_write_1h. Existing rows backfill cleanly.

Test plan

  • typecheck + test + lint clean

Menci added 2 commits June 20, 2026 03:58
…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.
@Menci Menci force-pushed the precursor-input-cache-write-1h branch from 1990ca3 to 92685bd Compare June 20, 2026 03:41
@Menci Menci changed the title feat(protocols,gateway): input_cache_write_1h dimension + migration adding tier column feat(protocols,gateway): input_cache_write_1h dimension + per-TTL cache parser Jun 20, 2026
@Menci Menci changed the title feat(protocols,gateway): input_cache_write_1h dimension + per-TTL cache parser feat(usage): input_cache_write_1h dimension + per-TTL cache parser Jun 20, 2026
@Menci Menci merged commit 7d7f243 into main Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant