pricing: Claude's 1-hour cache writes are priced at 1.25x, but billed at 2x

未关闭
#191 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@anascherif 已经在做这个了。

开始于 2026年11月9日。

  • #192 来自 @anascherif —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
data

调研方向

Read pricing.py and the Claude session reader that extracts usage.cache_creation; the issue names both as the change points. Check how effective_tokens applies weight tables and inspect the existing tests for session parsing and pricing. Done when 1-hour cache-write tokens are capped by cache_creation_input_tokens, priced at 2x when the weight is available, and existing rows and weight tables retain current behavior.

由索引模型根据 Issue 内容生成。

描述

pricing.py prices every Claude cache-write token at 1.25x input (cache_write=1.25). Anthropic bills a cache write by its lifetime: 1.25x for the 5-minute cache and 2x for the 1-hour cache (prompt caching pricing).

Claude Code records the split per message in usage.cache_creation (ephemeral_5m_input_tokens, ephemeral_1h_input_tokens), but claude_session_usage only reads the total cache_creation_input_tokens, so the 1-hour share is lost before pricing.

Effect. On my machine (Claude Code on a subscription), across my 35 most recent session transcripts (4,841 assistant messages), essentially all cache-write tokens are in ephemeral_1h_input_tokens. Pricing them at 2x instead of 1.25x raises those sessions' effective tokens by about 8%, so te status and the session ledger understate them by that much.

Proposed fix. Have the Claude session reader sum the 1-hour share as cache_creation_1h_input_tokens, and have effective_tokens price that share at a cache_write_1h weight (2.0 on the Claude curve). Rows without the field and weight tables without the entry stay priced exactly as today. I have this implemented with tests and will open a PR.

One detail from real transcripts: some messages carry a non-zero ephemeral_1h_input_tokens while every top-level count is 0, so the 1-hour share should be capped at the message's cache_creation_input_tokens.

主要语言
Python
星标
5.6k
派生
344
平均合并
14 小时 41 分钟
30 天内合并 PR
54

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TokenEconomizer 的其他 Issue

查看 microsoft/TokenEconomizer 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。