Skip to content

fix(billing): price Anthropic 1-hour cache writes separately - #1203

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1788699979-anthropic-1h-cache-writes
Open

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1788699979-anthropic-1h-cache-writes

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Rewrite of #1201 by @atirna (credited as co-author) to match repo conventions; the fix itself is unchanged.

Anthropic reports a TTL breakdown under usage.cache_creation.{ephemeral_5m,ephemeral_1h}_input_tokens; the aggregate cache_creation_input_tokens was priced entirely at the 5-minute 1.25x rate, under-billing 1-hour writes (2x).

  • catalog.Pricing gains CacheWriteMultiplier1h (+ DefaultCacheWriteMultiplier1h = 2.0, EffectiveCacheWriteMultiplier1h()).
  • catalog.EffectiveInputCost(input, cacheCreation, cacheCreation1h, cacheRead, p, provider): cacheCreation1h is clamped to cacheCreation; the remainder prices at the 5-minute rate, so aggregate-only payloads (Bedrock/Vertex, cacheCreation1h == 0) are unchanged.
  • The 1h count is carried from otel.UsageExtractor (SSE message_start + non-stream JSON), translate.UsageSink.RecordCacheCreation1hTokens, handover.Usage.CacheCreation1h and streamCostWriter into billing.DebitInferenceParams.CacheCreation1h, telemetry cost columns, cost headers and policy-outcome cost.

Deltas from #1201: test comments in cost_test.go rewritten as invariant descriptions (no issue refs / pre-fix narrative, per AGENTS.md comment rule); routerCostCalculator / routerResponseCostFromPricing parameter order aligned with EffectiveInputCost (cacheCreation, cacheCreation1h, cacheRead).

Fixes #867

make precommit clean.

Link to Devin session: https://app.devin.ai/sessions/e1c3317bd01c4d7b8a4639c5ef2bae64
Open in Devin Desktop: https://app.devin.ai/desktop/session/e1c3317bd01c4d7b8a4639c5ef2bae64?variant=devin
Requested by: @steventohme

atirna and others added 2 commits September 5, 2026 19:59
Signed-off-by: Atirna <288419661+atirna@users.noreply.github.com>
Rewrite of #1201.

Co-authored-by: Atirna <288419661+atirna@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

billing: 1-hour TTL cache writes are billed at the 5-minute 1.25x rate, undercharging by 37.5%

2 participants