Skip to content

fix(tui): bill Anthropic cache-write tokens at published rates (#4318)#4348

Closed
knqiufan wants to merge 1 commit into
Hmbown:mainfrom
knqiufan:fix/4318-cache-write-pricing
Closed

fix(tui): bill Anthropic cache-write tokens at published rates (#4318)#4348
knqiufan wants to merge 1 commit into
Hmbown:mainfrom
knqiufan:fix/4318-cache-write-pricing

Conversation

@knqiufan

@knqiufan knqiufan commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Keep Anthropic cache_creation_input_tokens as Usage::prompt_cache_write_tokens instead of folding them into cache-miss.
  • Extend TUI CurrencyPricing with cache_write_per_million and publish 5-minute write rates for Anthropic/Qwen rows (e.g. claude-fable-5 at 12.50).
  • Wire token_usage_for_pricing and turn-cost math so cache-write is no longer hardcoded to 0, fixing undercounted cost estimates.

Closes #4318

Testing

  • cargo fmt --all -- --check (via cargo fmt -p codewhale-tui)
  • cargo clippy --workspace --all-targets --all-features
  • cargo test -p codewhale-tui --bin codewhale-tui --locked pricing::tests
  • Anthropic usage mapping / SSE fixture / session_usage_cache_* / turn-metadata tests
  • cargo test --workspace --all-features
  • Spot-check a Claude turn with cache creation in the TUI cost estimate

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes
  • Harvested/co-authored credit uses a GitHub numeric noreply address (N/A — original authorship)

@knqiufan knqiufan requested a review from Hmbown as a code owner July 11, 2026 12:37
@github-actions

Copy link
Copy Markdown

Thanks @knqiufan for taking the time to contribute.

This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

Keep cache-creation usage separate from cache-miss and wire
CurrencyPricing.cache_write so TUI cost estimates stop undercounting
Anthropic/Qwen write premiums (Hmbown#4318).

Signed-off-by: knqiufan <knqiufan@foxmail.com>
@knqiufan knqiufan force-pushed the fix/4318-cache-write-pricing branch from 7927645 to f0a617b Compare July 11, 2026 12:41
Hmbown added a commit that referenced this pull request Jul 12, 2026
Add canonical GitHub-noreply identities for moduvoice (PR #4347),
qinlinwang (PR #4346), and knqiufan (PR #4348) so the co-author gate can
verify machine-readable credit on the harvested commits. ci4ic4 was
already mapped.
Hmbown added a commit that referenced this pull request Jul 12, 2026
Summarize the underwater interaction system, treatment/motion
independence, compact-room fixes, footer notice ownership, ASCII tier,
and localization parity work in the 0.8.68 changelog section, and credit
the harvested community work: Korean locale (PR #4347 @moduvoice),
Anthropic schema sanitization (PR #4346 @qinlinwang), Anthropic
cache-write pricing (PR #4348 @knqiufan), NetBSD bindgen (PR #4349
@ci4ic4), and the #4208 copy-pollution report (@eugenicum).
Hmbown pushed a commit that referenced this pull request Jul 12, 2026
Keep cache-creation usage separate from cache-miss and wire
CurrencyPricing.cache_write so TUI cost estimates stop undercounting
Anthropic/Qwen write premiums (#4318).

Signed-off-by: knqiufan <knqiufan@foxmail.com>

Harvested from PR #4348 by @knqiufan
@github-actions

Copy link
Copy Markdown

Thanks @knqiufan — your contribution landed in 2215f598dab5 on main:

fix(tui): bill Anthropic cache-write tokens at published rates

Closing this PR now that the code is on main. Credit lives in the commit message and (where applicable) the CHANGELOG.md entry for the next release. Apologies for not closing this at the time of the merge — the auto-close workflow is new in v0.8.31.

If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the CONTRIBUTING.md doc has a short note on what makes a contribution mergeable as-is.

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.

Pricing: cache-write rates dropped by CurrencyPricing/TokenUsage

1 participant