le-soleil-se-couche/dsh-token-cost
DeepSeek Harness(DSH)Web GUI 的 Token 用量 / 缓存命中 / 费用统计插件:单对话与整体汇总,内置 DeepSeek 双计价方案(东八区峰谷),也可为自己调用的其他模型填写单价。
catalog 简介 / catalog descriptioncatalog description:在对话页面直接查看消耗费用(嵌入官方底部状态条,点击看明细);设置中汇总用量与费用,并可自定义其他模型单价
项目介绍Project Overview
DSH 插件,用于统计 DeepSeek Web GUI 的 token 用量、缓存命中与费用。单对话视图在底部状态行直接展示本会话费用,可点开查看按请求的明细(时间、模型、缓存命中/未命中、输出、费用);设置页提供整体汇总,支持今天/昨天/近 7/30 天/本月/上月/自定义时间筛选,按模型、会话、日期分组。内置东八区峰谷双计价方案,第三方模型走自定义单价,添加后历史费用即时按新单价重算。需注意:币种仅支持 cny/usd,自定义价格按每百万 tokens 填写。
DSH plugin that tracks token usage, cache hits, and cost for the DeepSeek Web GUI. The per-conversation view embeds the session cost directly in the bottom status bar, with a clickable popup showing per-request detail (time, model, cache miss/read, output, cost). The settings page adds an aggregate dashboard with today/yesterday/last 7/last 30 days/this month/last month/custom filters, grouped by model, conversation, or date. Two built-in peak/valley pricing schemes run on UTC+8; third-party models use custom per-million-token prices written to local storage, and historical costs are recomputed immediately after changes. Note: currency supports only CNY/USD, and cache-read price can be left empty (treated as 0).
请帮我了解并安装插件:【dsh-token-cost】【https://github.com/le-soleil-se-couche/dsh-token-cost】
把上面这条消息直接发给当前会话里的 DSH,让它帮你了解并安装。安装命令不一定准确,发给 DSH 更稳。Send this message to DSH in your current session. CLI install commands may not be accurate across systems — DSH will figure it out for you.
或使用命令行安装(适合开发者)Or use CLI install (for developers)
命令行安装CLI Install
dsh plugin --profile web add github:le-soleil-se-couche/dsh-token-cost
把 le-soleil-se-couche/dsh-token-cost 加入你的 DSH 配置(web profile)即可启用。
READMEREADME
dsh-token-cost
English · 中文
DeepSeek Harness(DSH)Web GUI 的 Token 用量 / 缓存命中 / 费用统计插件:单对话与整体汇总,内置 DeepSeek 双计价方案(东八区峰谷),也可为自己调用的其他模型填写单价。
2026-08-17更新:支持为自己调用的其他模型填写单价;点「添加模型」即写入本地价格文件,刷新后仍在,历史费用立刻按新单价重算。
2026-08-25 更新:计量内核升级为 attempt-aware fold,补齐失败调用后 retry、compaction/summary.usage 与 fork seedLength 边界;账本 schema 升至 v2,旧缓存会从权威 session logs 自动重折叠。
功能
- 单对话视图:对话页面底部官方状态行(「首 token 平均 … · … tok/s」之后)直接嵌入本会话消耗费用,点击即可打开按请求的明细弹窗(时间 / 模型 / 缓存未命中 / 缓存命中 / 输出 / 费用,最新在上)。
- 整体汇总(设置 > 插件配置 > Web UI 插件 > Token 费用统计):时间筛选(今天 / 昨天 / 最近 7 天 / 最近 30 天 / 本月 / 上月 / 自定义,最多 30 天)+ 费用 / 输入 / 输出 / 缓存命中率统计卡,按模型、会话、日期分组。
- 计价状态:高峰时段按东八区显示(09:00–12:00、14:00–18:00),判定也按东八区时钟。
- 自定义模型价格:配置页可从账本发现未定价模型,或手动添加尚未调用的模型;按每百万 tokens 填写缓存未命中 / 缓存命中 / 输出。点「添加模型」即写入本地价格文件,刷新后仍在,历史记录立刻按新单价重算。缓存命中可不填(按 0 计)。第三方模型按平价,不受 DeepSeek 峰谷影响。
数据来源
插件读取 DSH 的持久会话日志($DSH_HOME/sessions/<cwd>/<session-id>/session.jsonl.zstd),把 provider 上报的 usage 事件折叠为按调用尝试的计费记录:同一次 attempt 内最终 message 替换 chunk 样本;失败 finish 会结算当前 attempt,让同一 turn/step 的 retry 另行累加;compaction/summary.usage 作为独立调用计入;聚合 fork 子会话时跳过 seq < seedLength 的继承前缀。紧凑账本($DSH_HOME/storages/dsh-token-cost/ledger.json)缓存解析结果,只重解析变化的日志;计量语义升级会自动使旧账本失效并从 session logs 重折叠。自定义单价存在同目录的 custom-prices.json。zstd 解压使用 fzstd(纯 JS 零依赖)。
Token 字段遵循 Harness 约定:inputTokens = 缓存未命中部分,cacheReadTokens = 缓存命中部分(两者不相交,相加即计费输入)。
统计边界仍由上游日志决定:标题生成、Web Search、被中断调用或其他客户端若没有写出 usage,插件不会虚构 token 或费用。可公开复核的 synthetic fixture 与手算结果位于 tests/fixtures/usage-accounting/。
计量优化与官方差异
截至 2026-08-25,DSH 官方 master b150a551b8 的 tokenUsage projection 仍为 stateVersion: 1:它能去重同一次 attempt 的 chunk/message 样本,但尚未折叠 compaction/summary.usage,失败 attempt 后同一 (turn, step) 的 retry 仍会覆盖前一次 usage;跨 session 汇总也需要消费方自行排除 seq < seedLength 的继承前缀。
本插件已经覆盖这些边界,并用 ledger v2 自动使旧口径缓存失效。在“已写入 DSH session logs 的 usage 如何结算”这一明确范围内,本插件当前领先于官方 master;这不代表插件能替代官方账单,也不扩大上游没有记录 usage 的遥测边界。独立 synthetic conformance checker 的四个 bucket 已逐项通过,记录见 deepseek-harness Discussion #1886。
安装
dsh plugin --profile web add github:le-soleil-se-couche/dsh-token-cost
重启 dsh web 后,在设置页展开「Web UI 插件」即可看到。历史会话日志在首次查询时自动回填。
配置项
| 键 | 类型 | 默认 | 说明 |
|---|---|---|---|
enabled |
boolean | true |
总开关(状态行费用显示 + 汇总卡片) |
currency |
'cny' | 'usd' | 'cny' |
priceMode |
'auto' | 'scheme-a' | 'scheme-b' |
customPrices |
string (JSON) | '' |
兼容旧设置项;现用配置页表单,落盘到 storages/dsh-token-cost/custom-prices.json |
以上均可在卡片的「配置」页编辑;「重新扫描会话日志」按钮强制全量重解析。
开发
pnpm install && pnpm -r build
pnpm --filter @deepseek-ai/dsh-token-cost test
pnpm --filter @deepseek-ai/dsh-token-cost typecheck
架构说明见 DESIGN.md。
ruvnet/ruflo
amruthpillai/reactive-resume
volcengine/OpenViking
Molunerfinn/PicGo
titanwings/colleague-skill
nocobase/nocobase
Tencent/WeKnora