Skip to content

[Bug]: Usage prices Claude 1-hour cache writes at the 5-minute rate #21010

Closed

Description

@iamshadmantaqi

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Summary

Usage prices every Claude cache write at cache_creation_input_token_cost (the 5-minute rate). Claude Code also writes 1-hour cache entries, which bill at a higher rate, so Claude cost is understated.

Steps to reproduce

  1. Use Claude Code long enough to produce transcript records whose message.usage.cache_creation.ephemeral_1h_input_tokens is greater than 0.
  2. Compare the cost Usage shows with tokens x rate: the 1-hour tokens are charged at the 5-minute rate.

Expected behavior

Tokens in usage.cache_creation.ephemeral_1h_input_tokens are priced with cache_creation_input_token_cost_above_1hr from the pricing data; the rest of cache_creation_input_tokens stays at cache_creation_input_token_cost. For example the LiteLLM entry anthropic.claude-opus-4-5-20251101-v1:0 has 6.25e-06 for the 5-minute write and 1e-05 for the 1-hour write (1.6x).

Actual behavior

  • parseClaudeRecord in apps/server/src/provider/Drivers/claudeUsage.ts reads only cache_creation_input_tokens, so the 5-minute and 1-hour split is dropped.
  • readTokenRates in apps/server/src/usage/usagePricing.ts (the cacheRate("cache_creation_input_token_cost", ...) call, near line 76) reads one write rate and never cache_creation_input_token_cost_above_1hr.

Measured over 30 days on one machine (Claude Code transcripts): 290M tokens were 1-hour writes, which is about $870 of cost not counted. Together with the output-token undercount in #20246, Claude cost shows about 13% low here. Total tokens are not affected.

Suggested fix

Carry the 1-hour write count through UsageRecord totals next to cacheCreationTokens, and in the cost step price it at cache_creation_input_token_cost_above_1hr when the entry has it (fall back to the 5-minute rate when it does not, as cacheRate already does for missing fields). Records with no cache_creation breakdown keep today's behaviour.

Impact

Minor bug or occasional failure

Version or commit

Desktop app 0.1.0 (Beta build), checked against main @ 13aa882

Environment

macOS, Claude Code transcripts from the 2.1.x series

Activity

  1. juliusmarminge commented on Oct 17, 2026

    @juliusmarminge
    Member

    Note

    Grok responding on behalf of Julius.

    Thanks for the detailed report. Open PR #16922 already prices the ephemeral_1h_input_tokens part of Claude cache writes at cache_creation_input_token_cost_above_1hr (falling back to the 5-minute rate when a model has no 1-hour rate), so I've linked it to close this issue when it lands. The output-token undercount you mentioned is tracked separately in #20246 / #20276.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions