2006spy/dsh-token-billing 预览 preview

2006spy/dsh-token-billing

Plugin插件 Native原生 ⭐ 3 MIT Usage & Cost用量与计费

DSH实时token计费插件:官网人民币价直接计费、高峰/错峰自动切换、价格实时跟随官网、可视化自定义模型价格。Real-time token billing plugin for DeepSeek Harness (dsh web)。

Project Overview项目介绍

This is a native plugin built exclusively for DeepSeek Harness (DSH) that provides real-time token billing and cost tracking. It calculates session cost based on actual token usage including input, output, cache read and cache write, multiplied by the corresponding model unit price, and displays the result above the input box in real time. It supports per-provider and per-model routing pricing, automatically switches between peak and off-peak pricing following DeepSeek's official pricing policy, and includes a visual statistics dashboard with trend charts and budget alerts. It also normalizes model aliases to ensure accurate pricing after DeepSeek model updates.

This plugin is designed for DSH users who want to keep close track of their API token spending and avoid unexpected overage charges. During each conversation session, it first estimates the cost while the response is streaming, then automatically corrects the cost once it receives the exact token usage data from the model. Aborted or interrupted requests will not be counted toward your total bill. Users can view historical daily and monthly spending trends, check cost breakdowns by model and provider, set budget alerts and export their billing data for further analysis if needed.

This plugin is released under the open source MIT license, and has zero build dependencies, as it uses a handwritten ESM host and client bundle. It comes with a full test suite that covers over 300 test cases for pricing calculation, model normalization, routing pricing and other core features. By default, it automatically fetches the latest official DeepSeek pricing every hour, and users can customize their own configuration if needed. Note that the debug scripts in the tests folder are temporary diagnostic tools, not part of the official test suite, so you should run tests one by one as listed.

这是专为 DeepSeek Harness 开发的原生实时 Token 计费插件,基于每次会话实际产生的输入、输出、缓存读写四类 Token 用量,结合对应模型单价计算本次会话费用,在输入框上方实时展示。它支持按服务商与模型路由计价,可自动切换北京时区的高峰/错峰价格,价格实时跟随 DeepSeek 官网调整,支持自定义模型价格,自带可视化统计仪表盘,包含费用趋势图表和预算预警功能。

面向需要追踪 API Token 消费成本的 DeepSeek Harness 用户,日常使用中,用户每发起一次对话,插件就会在流式生成时先估算费用,收到模型返回的精确用量后自动修正费用,中断未完成的请求不会计费。用户还可以在统计仪表盘查看今日、昨日、本月的费用趋势,按模型和服务商查看费用占比,导出账单数据做进一步分析管理。

本插件采用 MIT 许可证开源,零构建依赖,采用手写 ESM 宿主和客户端 bundle,自带完整的测试用例覆盖计价、归一化、路由定价等多个场景。安装后即可自动运行,默认每小时自动抓取一次官方最新价格,用户可根据需要自定义配置。需要注意的是,仓库中的 debug 脚本为临时诊断工具,不属于测试套件,运行测试时请按清单逐个执行。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 warning1 项注意
  • Only 3 stars - very few users, little community feedback星标只有 3,几乎没人在用,遇到问题缺少社区反馈
DSH walks through these 9 checksDSH 会逐条核对这 9 项

Compatibility兼容性

  • DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
  • External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
  • Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册

Security安全性

  • Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
  • Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
  • curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
  • Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
  • Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
  • Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式

Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。

Or use CLI install (for developers)或使用命令行安装(适合开发者)

CLI Install命令行安装

dsh plugin --profile web add github:2006spy/dsh-token-billing

把 2006spy/dsh-token-billing 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

💸 dsh-token-billing

DeepSeek Harness (dsh) 实时 token 计费插件 · Real-time token billing for DSH

官网人民币价直接计费 · 按 (provider + 模型) 路由计价 · 高峰/错峰自动切换 · 价格实时跟随官网 · 可视化自定义模型价格 · 订阅/免费/本地收费形式分类 · 统计仪表盘(趋势折线图 + 占比环形图 + 预算预警)

License: MIT DSH Plugin Version


✨ 这是什么

为 DeepSeek Harness(dsh)Web 提供实时费用统计:按本次会话实际的 token 用量(输入 / 输出 / 缓存读 / 缓存写四个桶)乘以模型单价,换算成费用,在输入框上方实时显示。

  • 估算 → 精确自动修正:流式生成期间用字符/4 启发式估算(标注「估」),收到模型的精确 usage 后自动修正;被中断(abort)的估算步骤不会落地计费。
  • 零构建依赖:手写 ESM 宿主 + __ModuleLoader__ 客户端 bundle,与 modlens 同款立场。

输入框上方一行实时显示(与 TPS 同款样式):

💸 ¥0.0302 · 12.3k in / 1.2k out · 本轮(估) ¥0.0011 · deepseek-v4-flash ¥4/M · 空闲

📸 界面一览

统计页仪表盘(v0.7 · 纯手写 SVG 图表 · 模拟数据渲染):

统计页仪表盘

图中可见:KPI 概览卡(今日 / 昨日环比 / 本月·预算环 / 累计 / 调用次数)· 费用趋势折线图 · 按模型费用占比环形图 · Token 用量趋势折线图 · 按 Provider 实际花费占比环形图 · 月度预算进度条 · 账户余额 · 按模型 / 按天明细。

截图由 scripts/render-preview.mjs 用模拟账本数据生成;真实界面随实际账本数据展示。


🛠 更新日志

v0.8.1(2026-09-12)

修复:费用行「当前单价」段在走全局价目表时会显示官方档位名,容易被误读为「插件认错了模型」。

  • 该段此前渲染命中那条价目行的名字。走全局表(官方定价页)时那个名字是官方档位名 (如 deepseek-flash),于是中转路由下的 deepseek-v4.1-flash 会被显示成 deepseek-flash。
  • 现改为优先显示你实际选中的模型名,仅当它与计价档位名不同时附注: deepseek-v4.1-flash ¥4/M(按 deepseek-flash 计价)。
  • 价格本身一直是正确的 —— 档位归一化只影响「匹配哪条价目」,不影响金额。实测:重启后 27 条 deepseek-v4.1-flash @mxy 记录与官方空闲价重算逐位吻合(1.0000×)。本版仅修显示。
  • 决策逻辑抽为具名函数 priceLineParts,由 tests/client-alias-parity.mjs 从源码提取后断言 (5 条行为 + 2 条接线/回归),该测试 10 → 17 通过。

v0.8.0(2026-09-11)

三件事:计价正确性修复(官方页脚注污染 / 模型改名档位 / 2026-08-17 峰谷起点与 2026-09-10 12:00 flash 调价)、让「按路由计价」真正生效、补齐兼容声明与自包含测试。

一 · 计价正确性修复

  • 官方页脚注污染(价格 key 失配) —— 官网定价页模型表头带脚注标记,旧解析器产出脏 key deepseek-flash(1) / deepseek-v4-pro(2),与真实模型名永不相等:官方抓到的价等于没用,一直回落到内置旧价(缓存读约 25 倍多算、输入约 2 倍多算)。新增 stripFootnoteMarks / canonicalModelId / modelTier(lib/prices.js,解析层与写入层共用的单一归一化函数),parseDeepSeekPricingHtml 的模型键、fetchedToFlat、flattenPiAiCost、fetchJsonPrices 与 applyFetchedPrices(全局表与 provider 桶)全部在写入前归一化,脏 key 不再落进价格缓存。实测现页(2026-09-11 抓取)解析结果为 deepseek-flash / deepseek-v4-pro,无任何括号脚注。
  • 模型改名与档位归一化 —— 官方现名为 deepseek-flash;旧名 deepseek-v4-flash / deepseek-v4.1-flash / deepseek-v4-flash-0731 / deepseek-v4-flash-ga-260731 / deepseek-v4-flash-vision-exp / DeepSeek-V4-Flash-0731 / deepseek/deepseek-v4-flash-0731 等仍可调用并按 Flash 价计费,故统一归入档位。大小写、分隔符与 vendor 前缀不敏感,10 个真实模型名全部命中正确档位;非 DeepSeek 键形不变(mimo-v2.5 / deepseek-chat)。
  • 官方现价 + 价格政策时间线 —— 内置表更新为官方现值:flash 空闲 1/4/0.02/1、高峰 2/8/0.04/2;pro 空闲 4.5/13.5/0.15/4.5、高峰 9/27/0.3/9。新增 PRICE_POLICY_TIMELINE(lib/projection.js)三段:平价段、2026-08-17 00:00(北京)峰谷起点(flash 高峰 3/9/0.1/3)、2026-09-10 12:00(北京)flash 新价。取价按消息发生时刻选段:非最新段一律用内置历史价(历史回看不被新规追溯改写),最新段在已有人民币抓取价时让位抓取表(从而可跟随官网未来调价)。
  • 周末空闲规则曾被「默认值不等价」挡在门外 —— 官方 2026-08-23 起高峰仅周一至周五(周末全天空闲价);但 windowsAreDefault 原本只认「内置北京时间带 days」一种写法,用户端 Config 里那份旧版 UTC 默认窗口([["01:00","04:00"],["06:00","10:00"]])被误判为「用户自定义」,于是官网抓到的窗口(含工作日)进不来、周末规则失效。本版改为语义等价即视为默认(同时认「旧 Config 默认 UTC 无 days」「北京时段但漏写 days」「内置北京带 days」三种写法),并同步 tzIsDefault(Asia/Shanghai / UTC / 空值都算默认);真正自定义的窗口(如 22:00-23:00)不被覆盖。
  • DEFAULT_FALLBACK(仅在配置缺省时兜底;正常安装下 Config 默认 2/8/0.5/2 先行生效)同步更新为官方 Flash 空闲价 1/4/0.02/1。

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev dsh-loader 下一个 Next dsh-sparrow →