beijingwahw/dsh-usage-ledger

dsh-usage-ledger(Token 费用统计)— 自动记下每笔对话花了多少 Token、多少钱(按对话、按天、累计都能查),价格自动跟着官方最新价走、支持多家国产厂商,低谷时段自动按便宜价算,预算超了自动提醒还能拦下调用,带可视化仪表盘。

Project Overview项目介绍

dsh-usage-ledger is a token usage and cost ledger plugin for DeepSeek Harness. It aggregates input, output, and cache read/write tokens from assistant/message events per session, per Beijing-time day, and per lifetime, pricing them in CNY via dynamic scraped official rates (DeepSeek peak/off-peak included). It adds daily/total/per-session budget warnings and optional call blocking, multi-vendor catalog auto-update, customPrices overrides, a web dashboard at /usage-ledger, and a usage_report tool. Use it to visualize usage and cap LLM spend. Caveat: with enforceBudget on, over-budget calls are blocked, and initial startup needs network access to fetch pricing.

dsh-usage-ledger 是 DeepSeek Harness 的 Token 用量与费用记账插件。它按会话、北京日、生命周期聚合 assistant/message 的 input/output/缓存读写 Token,按官方定价(支持峰谷分时)折算 CNY,并提供日/总/会话三级预算告警与拦截、动态抓取多家国产模型定价、customPrices 用户覆盖、Web 仪表盘 /usage-ledger 路由及 usage_report 工具。适合需要可视化用量、控制 LLM 成本的 Harness 部署。需注意:启用 enforceBudget 后超限会直接拦截模型调用,首次启动需网络以抓取定价页。

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 add beijingwahw/dsh-usage-ledger --profile web

把 beijingwahw/dsh-usage-ledger 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-usage-ledger ( Token费用统计 )

dsh-plugin license

中文 | English

DeepSeek Harness 的 Token / 用量统计与成本控制插件:按对话聚合消耗、动态跟随官方定价、支持预算拦截,并内置 Web 仪表盘。

功能特性

  • 按会话统计:监听 session/event,把每次 assistant/message 的 usage(输入 / 输出 / 缓存读写 Token)折算为费用,按会话、按北京日、按生命周期三个维度聚合,并持久化到账本文件。
  • 动态官方定价:定期抓取官方定价页,自动解析并热更新价格,官方调价 / 上新模型时无需改代码即可生效。
  • DeepSeek 峰谷分时:识别官方「高峰 / 空闲」时段表与生效日期,按调用发生的北京时间实时取价。
  • 多厂商价格目录:覆盖 DeepSeek、智谱 GLM、月之暗面 Kimi、阿里通义、字节豆包、MiniMax、百度文心等主流国产模型,新模型上线官方定价页后自动导入。
  • 预算控制:支持日 / 总 / 单会话三级预算,达到阈值进入告警,超限可通过 llm/stream 钩子直接拦截模型调用。
  • Web 仪表盘:通过 dsh-host-webserver 注册 /usage-ledger 路由,提供用量可视化与 JSON API。
  • 用户覆盖价:customPrices 设置可为任意模型(含自定义模型)覆盖或补充价格,优先级最高。

安装

一键安装

dsh plugin add beijingwahw/dsh-usage-ledger --profile web

常用进阶命令:升级 dsh plugin upgrade dsh-usage-ledger --profile web;卸载 dsh plugin remove dsh-usage-ledger --profile web;本地路径安装 dsh plugin add ./dsh-usage-ledger --profile web。

Harness 通过 dsh.plugin.json 与 cordis.patch.yml 自动加载插件,lib/ 随仓库分发,无需本地构建。

配置

在 Harness 的 cordis.yml 中挂载并配置:

- name: dsh-usage-ledger
  config:
    ledgerPath: ''            # 留空则使用 $DSH_HOME/usage-ledger.json
    saveIntervalMs: 5000      # 账本落盘防抖
    pricingTimeoutMs: 10000   # 单次定价抓取超时

usage-ledger 命名空间的用户设置(可在运行时热更新):

设置 默认 说明
dailyBudget 0 日预算(元),0 关闭
totalBudget 0 总预算(元),0 关闭
sessionBudget 0 单会话预算(元),0 关闭
warnRatio 0.8 进入告警的预算占比
enforceBudget true 超预算时拦截模型调用
pricingUrl DeepSeek 官方页 定价刷新来源
refreshIntervalMin 60 定价刷新间隔(分钟)
customPrices {} 按模型 id 覆盖价格(最长前缀匹配)

customPrices 示例:

{
  "glm-4.6": { "inputCacheHit": 1, "inputMiss": 5, "output": 5 }
}

价格单位为 元 / 百万 tokens。

价格解析优先级

用户覆盖 > DeepSeek 实时表 > 各厂商实时抓取表 > 内置目录精确匹配 > 最长前缀匹配

各厂商抓取方式(fetchKind):

厂商 通道
DeepSeek 官方定价页 HTML(含峰谷表)
智谱 GLM SPA app.*.js 内嵌价格 + 公开运营位接口
Kimi Next.js RSC flight payload 子页
通义千问 官方定价页表格
豆包 火山文档中心服务端 Markdown
MiniMax 官方定价页表格
文心 百度 CDN Gatsby page-data

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-lint-loop 下一个 Next dsh-study-buddy →