前言¶
在用 DeepSeek Harness 跑多轮会话时,经常需要知道单条回复的消耗、累计花费和账户余额。尤其是按分时段计费(峰时/非峰时)的场景,如果不手动计算,很难掌握真实成本。下面介绍 dsh-burn,一个为 DeepSeek Harness Web UI 提供会话级 token 消耗、峰时/非峰时定价和余额查询的插件。
插件定位¶
- 插件名:dsh-burn
- 维护者:yishan
- 类型:客户端
- GitHub:https://github.com/yishan/dsh-burn
- 目录页:https://www.skillhub.cn/plugins/yishan/dsh-burn
插件通过 host 服务折叠会话日志,按模型和计费时段对 token 进行桶统计,并通过 Web 客户端在对话头部与每条回复的操作栏中展示实时费用与余额,无需手动计算。
核心功能¶
- 单条回复实时费用
每条已落地的助手消息在操作栏(复制/点赞/分享)右侧显示 ↑in · ↓out ¥cost。费用根据该回复生成时间对应的计费档位与实时价格表计算。
- 会话头部累计花费与余额
在 Standard 模式下,对话头部右侧会显示 累计 ¥xx · 余额 ¥xx。累计金额从会话快照实时折叠(每次回复 settle 时更新);余额通过调用 DeepSeek /user/balance 接口获取(默认 60 秒缓存,同一时间戳去重)。
- 设置面板(费用 / Cost)
- 修改各模型价格(默认内置官方价格表)
- 选择显示档位:
auto/peak/offPeak/average - 加载官方价格表或自定义峰时/非峰时时段
- 档位切换后,整段历史会话按新档位重新计价
计费规则遵循 DeepSeek 按回复生成时间计费:工作日 09:00–12:00 和 14:00–18:00 为峰时,其余为非峰时(半价);周末全天非峰时(2026-08-23 规则)。auto 和 average 按“实际分时段”的时间加权计算,peak / offPeak 固定锁定档位供人工核查。
安装与启用¶
插件为 bundle:dsh plugin add 会自动挂载,无需手动 patch。
从 GitHub 安装:
dsh plugin --profile web add github:yishan/dsh-burn
dsh web # 重启 Web 服务以使配置生效
从 npm 安装(发布后可用):
dsh plugin --profile web add dsh-burn
dsh web
从本地目录安装:
dsh plugin --profile web add /path/to/dsh-burn
dsh web
配置说明¶
默认零配置:启动时自动从内置官方价格表填充(deepseek-v4-flash / deepseek-v4-pro),所有设置可在 设置 → 费用 中实时编辑,并持久化到各 profile 的配置文件(<profileDir>/plugins/dsh-burn/settings.json)。余额读数需要从 DEEPSEEK_API_KEY 解析的凭证调用 DeepSeek 接口。
高级:通过 profile patch 覆盖:
# $DSH_HOME/profiles/web/cordis.patch.yml
- id: dsh-burn
config:
displayMode: auto # auto | peak | offPeak | average
tierSchedule: default # default | custom
customWindows: [] # [{ start: 540, end: 720, tier: 'peak' }, ...]
defaultTier: offPeak # 未覆盖时段的默认档位
prices:
deepseek-v4-flash:
peak: { input: 3.0, cacheRead: 0.1, cacheWrite: 3.0, output: 9.0 }
offPeak: { input: 1.5, cacheRead: 0.05, cacheWrite: 1.5, output: 4.5 }
deepseek-v4-pro:
peak: { input: 9.0, cacheRead: 0.3, cacheWrite: 9.0, output: 27.0 }
offPeak: { input: 4.5, cacheRead: 0.15, cacheWrite: 4.5, output: 13.5 }
defaultPrice:
peak: { input: 3.0, cacheRead: 0.1, cacheWrite: 3.0, output: 9.0 }
offPeak: { input: 1.5, cacheRead: 0.05, cacheWrite: 1.5, output: 4.5 }
apiKeyEnv: DEEPSEEK_API_KEY
balanceRefreshMs: 60000
balanceBaseURL: 'https://api.deepseek.com'
价格单位为 CNY/百万 token。cacheWrite 用于镜像未单独计费缓存写入的提供商。
工作原理¶
- Host(
src/index.ts、src/projection.ts):CostMeter服务折叠会话日志,按模型与计费时段将 token 分桶,提供GET/POST /api/cost/settings接口,并代理GET /api/cost/balance(凭证 seam、401/502/60s 缓存)。投影的totalCost根据当前价格表与显示档位实时计算,档位切换后整段历史重新计价。 - Client(
src/client/):在三个 slot 注入显示——对话头部累计花费与余额、每条回复的操作栏费用、设置页。价格与档位在渲染时按当前价格表计算,无需重启。会话折叠为增量追加(O(Δ)),每次消息通过索引 O(1) 查询。 - 配置持久化到各 profile 的设置文件,启动时覆盖 profile 配置;未在价格表中的模型自动回填官方价格表。
开发与兼容性¶
开发环境:
pnpm install
pnpm run typecheck # tsc --noEmit
pnpm run test # vitest
pnpm run build # esbuild: lib/index.js + lib/client.js
客户端为 classic-script,通过 window.__ModuleLoader__ 注册,仅导入平台模块表。
兼容性声明(package.json):
| 目标 | 声明范围 | 验证方式 |
|---|---|---|
| Node.js | ^22.19.0 || >=24.0.0 |
在 Node 22.22.2 (macOS arm64) 上验证 |
| DSH 版本 | 0.1.1-rc.2: compatible |
disposable-profile 安装/卸载 + live web-profile 启动 + HTTP 200 |
对 DSH 0.1.0-rc.7 及以上版本兼容,其他 DSH 版本需逐版验证。
适用场景与注意¶
适合需要精细化成本控制与余额监控的 DSH Web UI 使用者,尤其是按分时段计费的场景。插件运行在 DSH 进程内,host 读写自身配置文件,client 无浏览器存储,网络仅调用余额接口。安装前建议检查源码与许可证。
结尾¶
dsh-burn 通过会话级 token 投影与实时价格表,将 DeepSeek Harness 的费用与余额信息直接呈现在 Web UI 中,便于按档位与时段核查成本。目录页:https://www.skillhub.cn/plugins/yishan/dsh-burn;GitHub:https://github.com/yishan/dsh-burn。