在输入框旁实时显示当前会话的 token 花费:用服务端上报的四个 token 分桶乘以本 profile 的价格表,并同时列出高峰与空闲价格。
安装
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:jessicacui99/dsh-plugin-token-cost
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
English | 中文
Live token spend for the current DSH session, shown beside the composer.
- Token counts are exact — the four buckets the server reports (
tokenUsage: cache-hit input, cache-miss input, cache write, output), not a local character estimate. - Money is computed — buckets × your profile's price table. Click the pill to expand: per-bucket tokens, unit price, charge, and both the peak and off-peak rate (the one in force is marked), so you can check it against a bill.
- Sits next to the built-in
38.4M tok · 缓存命中 99.6%stats line, same size and height.
- Peak/off-peak can be pinned; by default it follows UTC time (Mon–Fri 01:00–04:00 and 06:00–10:00 are peak).
Install
# from GitHub
dsh plugin --profile web add github:jessicacui99/dsh-plugin-token-cost
# or from a checkout you already have
dsh plugin --profile web add /absolute/path/to/dsh-plugin-token-cost
The host half mounts under patchReload: live; the browser half needs one page refresh.
There is no build step — lib/client.js is a hand-written bundle depending only on React and
react/jsx-runtime, and the host half imports nothing.
Prices
The bundled table is in yuan per 1,000,000 tokens, at the provider's peak rate.
Defaults: deepseek-flash ¥0.04 hit / ¥2 miss / ¥8 output; deepseek-v4-pro ¥0.30 / ¥9 / ¥27.
Off-peak is half of peak on every row. Models with no price show a hint instead of an amount —
never a silent ¥0.
Check the numbers against your own bill and, if they differ, override the row in your profile's
cordis.patch.yml. A patch replaces the whole config, so restate every field you keep:
- id: token-cost
config:
currency: CNY # display symbol only (¥ / $ / €)
period: auto # peak | off-peak | auto
models:
- model: deepseek-flash
provider: deepseek-official
inputCacheHit: 0.04 # yuan / 1M tokens, PEAK rate
inputCacheMiss: 2
output: 8
- model: deepseek-v4-pro
provider: deepseek-official
inputCacheHit: 0.3
inputCacheMiss: 9
output: 27
Bad config (negative numbers, a missing model, a misspelled period) fails at load rather than
running with wrong prices.
Limits
- The amount is a reference, not a bill: cache writes are charged at the miss rate, peak/off-peak follows the UTC rule, and an official price change or rule change means updating the table.
- Every request resends the whole context, so prompt tokens grow with turn count on a long session (cache hits are the bulk of it). That is the billing model, not double counting — duplicate records for the same turn/step are replaced, not added.
- Subagent spend is not in the parent's number; each is its own session.
- After switching models mid-session, the accumulated tokens are all priced at
modelSelection.lastUsed—tokenUsageis a whole-log total and does not split by model. - Current session only: switching sessions resets the number.
License
MIT
中文
在 DSH Web 界面的输入框旁边实时显示当前会话已经花了多少钱(默认人民币)。
- token 数是精确的:来自服务端上报的
tokenUsage投影(未命中缓存的输入 / 命中缓存的输入 / 缓存写入 / 输出四个分桶),不是本地按字符估算。 - 金额是算出来的:分桶 token 数 × 本 profile 的价格表。点一下价格胶囊展开明细:每一档的 token 数、单价与金额,并同时列出高峰与空闲两个价格(当前按哪个计价会标出来),方便和账单核对。
- 位置就在内置的
38.4M tok · 缓存命中 99.6%统计条旁边,同字号同高。
安装
dsh plugin --profile web add github:jessicacui99/dsh-plugin-token-cost
profile 开启 patchReload: live 时宿主半边会自动挂载;浏览器半边需要刷新一次页面。
没有构建步骤:lib/client.js 是手写 bundle,只依赖 React 与 react/jsx-runtime;宿主半边不 import 任何第三方包。
价格
内置表单位为元 / 百万 token,写的是高峰价,空闲价按官方规则(空闲 = 高峰的一半)在显示时折算。
默认值:deepseek-flash ¥0.04 / ¥2 / ¥8,deepseek-v4-pro ¥0.30 / ¥9 / ¥27(命中 / 未命中 / 输出)。
未配置价格的模型会显示提示而不是金额,不会静默算成 0。
和账单对不上时,在 ~/.dsh/profiles/<profile>/cordis.patch.yml 里覆盖 token-cost 这一行。
一个 patch 会替换整行的 config,所以要把想保留的字段全部写出来——完整示例见上方英文小节。
已知边界
- 金额是参考值,不是账单:缓存写入按「未命中」价计,高峰/空闲按 UTC 规则判断,官方调价或改规则时需要更新价格表。
- 每个请求都会把整段上下文重新发一遍,所以长会话的 prompt token 会随轮次快速膨胀(缓存命中占绝大多数);这是计费口径,不是插件重复计数——同 turn/step 的重复记录会被替换而不是累加。
- 子会话(subagent)的花费不在父会话的数字里,它属于各自独立的会话。
- 中途换过模型时,累计 token 会整体按
modelSelection.lastUsed(当前模型)计价。 - 只显示当前会话:换会话后数字归零重算。
链接
同类插件
bowenliang123/dsh-context★ 5628
DSH 上下文洞察面板:Context 仪表盘 + /context命令 + Context 浏览器,查看 Context的分类组成、内容详情、演进趋势、压缩/注入事件、统计等一站式 Context 全生命周期管理。
Han-1413141/dsh-cost-meter★ 774
会话与当日 API 费用统计、预算图框(已用%)、官方余额、历史看板,支持峰谷计价与官方价格一键同步。
wssfk12138/dsh-damage-pulse★ 291
在 DSH Web 界面追踪 DeepSeek Token 用量、单次与会话费用及账户余额,并显示缓存感知的扣费动画。
zh667/TokenLedger★ 207
侧边栏用量面板:把 Token 归属到实际服务该请求的中转站,站点从已有的 provider 配置中读出,无需额外配置;含今日/本月/累计三窗口、按站点与模型下钻、一年活跃度热力图,以及 New API / Sub2API / DeepSeek 余额。
Ychris12138/dsh-usage-stats★ 193
多供应商用量看板:按供应商/模型统计 Token 与日期下钻,统一展示账户余额,并追踪 OpenCode Go / Z.ai 订阅额度。
PolinniZhong/dsh-personal-center★ 114
DeepSeek Harness 个人中心:跨会话用量统计(按供应商/模型分别统计,自动读取已配置模型)、按模型成本估算、全局自定义指令、数据驱动的桌面宠物(位图/矢量皮肤)与会话状态概览,纯本地离线运行。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。