远程 claude-code 会话 cache 读取 token 计费虚高约 100 倍(按错误单价计费)
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 395
- Avg merge
- 21h 48m
- Merged PRs (30d)
- 776
Description
**提交人**: 匿名
**客户端版本**: 0.1.49
---
## 现象
远程 claude-code 会话(运行在远程主机,经 SDK 网关)的费用统计里,**cache 读取 token 被按远高于定价表的价格计费**,导致单会话费用虚高约两个数量级。示例会话总费用被统计为 **196.55 元**,按本地定价表重算应约 **1.77 元**。
## 影响范围
仅出现在**远程会话**(路由到远程 cc-mgr daemon 的 claude-code 会话)。本地会话费用正常。
## 复现步骤
- 在远程主机上运行一个 claude-code 会话,选 deepseek/deepseek-v4-flash(1M 上下文)。
- 会话中多次往返、产生大量 cache 读取 tokens。
- 查看该会话的费用统计 → cache 读取部分按错误单价计费。
## 期望行为
cache 读取 token 按定价表 `model-pricing.json` 中配置的 `cacheReadPerMtok` 计费:
- deepseek/deepseek-v4-flash:`cacheReadPerMtok = 0.02`(元/百万)
- deepseek/deepseek-v4-pro:`cacheReadPerMtok = 0.025`(元/百万)
## 实际行为
远程会话上报的 `turnCost` 隐含的 cache 单价约为 **3.8 ~ 17.3 元/百万 token**(约是正确值的 190~860 倍)。`turnCost` 标记为 `actual-cost`(非估算)。
## 复现频率
远程会话必现(6/6 已计费轮次全部受影响);本地会话未复现。
## 证据(已脱敏)
**会话费用明细**(一个远程会话,6 个已计费轮次):
| 轮次(UTC) | 模型 | 输入 | 输出 | cache读取 | 上报费用(CNY) | 正确费用(CNY) | 隐含cache单价(元/百万) |
|---|---|---|---|---|---|---|---|
| 07:10 | v4-pro+v4-flash | 211,558 | 69,198 | 7,761,408 | 44.679 | 0.505 | 5.71 |
| 07:46 | v4-flash | 114,804 | 1,220 | 281,600 | 4.994 | 0.123 | 17.32 |
| 08:10 | v4-flash | 9,536 | 6,554 | 1,271,424 | 5.677 | 0.048 | 4.45 |
| 08:12 | v4-flash | 22,722 | 2,075 | 1,192,704 | 5.104 | 0.051 | 4.26 |
| 08:38 | v4-flash | 76,219 | 72,130 | 33,272,704 | 126.099 | 0.886 | 3.78 |
| 08:42 | v4-flash | 114,291 | 6,225 | 1,529,472 | 9.995 | 0.157 | 6.45 |
| 合计 | | | | | **196.547** | **1.770** | |
其中 08:38 轮次 **99.77% 的费用来自 cache 读取**(33,272,704 tokens),按正确单价 0.02 元/百万仅值 0.67 元,却计了 126.10 元。
**计价表引用**(本地 `Cache/model-pricing.json`,与上报单价对比):
| 模型 | cacheReadPerMtok(定价表) | 上报隐含单价 |
|---|---|---|
| deepseek/deepseek-v4-flash | 0.02 元/百万 | ~4.3~17.3 元/百万 |
| deepseek/deepseek-v4-pro | 0.025 元/百万 | ~5.7+ 元/百万 |
疑似 root cause:远程侧(远程 cc-mgr / SDK / 网关)在计算 `turnCost` 时把 cache 读取按了错误档位(接近或高于输入价),而不是按 `cacheReadPerMtok`。`daily_spend` 等聚合也随之虚高(本日合计 198.99 元中 196.55 元来自这一个会话)。
## 已尝试
- 核对本地 `Cache/model-pricing.json` 定价(cache 单价正确)。
- 用正确定价对 6 个轮次逐笔重算,确认上报金额与 token 数无法对应。
---
**版本区域**: CN
**OS**: win32 x64 (10.0.22621)
**界面语言**: zh-CN
Contributor guide
Research direction
Start with Cache/model-pricing.json, then trace how the remote cc-mgr daemon, SDK gateway, and remote session path calculate and report turnCost. Compare that path with local session billing, focusing on cacheReadPerMtok and the daily_spend aggregation. Done means remote cache-read charges match the pricing table and related totals no longer overstate the session cost.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100