
zh667/TokenLedger
dsh-tokenledger
Relay-site attributed token usage for DeepSeek Harness — zero config, no credentials
Install
npx @deepseek-ai/dsh plugin --profile web add "github:zh667/TokenLedger"Restart `dsh web` after install. Bundle APIs can change during the developer preview.
README badge
[](https://dshhub.dev/plugins/tokenledger)Paste this into your README. The star count updates with every catalog sync.
From the README
Excerpt from zh667/TokenLedger, cleaned of badges and images.
TokenLedger
把 DeepSeek Harness 的 Token 用量算清楚,并归属到实际服务这次请求的中转站——不用配置,不用凭据。
Token-usage accounting for DeepSeek Harness, attributed to the relay site that
served each request. The existing Web GUI (dsh web) and renderer-neutral
consumers share the same host-owned aggregation. Zero configuration.
展示图使用演示数据与本机模拟中转站;面板上的每个数字都由真实代码路径算出,只是数据是造的。插件不会把 API Key 或上游原始响应发送到浏览器。
一眼看懂 / At a glance
| 能力 | 说明 | |
|---|---|---|
| 🎯 | 中转站归属 | 按 provider 的 baseURL 归一化 origin 分组——同一站的多把 key 合成一行,站名就是域名,不是你自己起的路由别名 |
| 📁 | 按项目归属 | 用量按会话启动时所在的目录分组——工作区注册过的用它的标题,没注册过的用目录名,子目录里起的会话照样算进去 |
| 🔍 | 零配置发现 | 从宿主的 provider 配置里读出中转站,不用你再填一遍。只读 baseURL,绝不碰旁边的凭据 |
| 💳 | 余额 | DeepSeek 官方、New API、Sub2API,每个账户一把普通 key 即可;不限额度的 key 报"已用"而不是假余额 |
| ⏳ | 订阅配额 | 卖套餐不卖余额的家数越来越多——5 小时 / 每周 / 每月各自滚动、各自重置,每个窗口一条进度条和一个重置时刻 |
| 📊 | 用量分析 | 今日/本月/累计三窗口、按站点/模型下钻、缓存命中率、一年活跃度热力图(悬停看当天模型构成) |
| 🧮 | 费用估算 | 生效日期分段的费率表、分桶计价、峰谷时段;未定价的模型显示破折号而不是 0 |
| 🗂 | 导出与诊断 | CSV / JSON 导出,索引健康度,归因不上的行数单独列出 |
| 🔒 | 只读回环 | 两个端点仅接受回环 GET,且在 peer socket 地址上设防;从不读取提示词、工具参数或响应内容 |
快速安装 / Quick start
需要 DeepSeek Harness web profile(@deepseek-ai/dsh >= 0.1.0-rc.6)。
dsh plugin --profile web add "github:zh667/TokenLedger"
重启已经在跑的 dsh web,浏览器硬刷新。侧边栏底部会出现「用量账本」入口。
升级或卸载:
dsh plugin --profile web update dsh-tokenledger
dsh plugin --profile web remove dsh-tokenledger
重装同一个 spec 会重新解析,所以 add 一遍就能拿到最新的 main(实测过,不是推测)。
要钉某个版本,必须用完整的 40 位 commit SHA。 包管理器把 ref 拿去和 git ls-remote 广播的引用列表比对,而那份列表里只有完整 SHA 和分支/标签名——短 SHA 匹配不到任何东西,会直接报 Could not resolve:
| spec | |
|---|---|
github:zh667/TokenLedger | ✅ |
github:zh667/TokenLedger#main | ✅ |
github:zh667/TokenLedger#947247a | ❌ 短 SHA 解析不了 |
github:zh667/TokenLedger#947247a86f0835f0e746695538569b1a76356dd1 | ✅ |
如果 package.json 里已经被写进了一个解析不了的 spec,add 也会失败——它会先解析整份清单。改掉那一行再 install 即可。
装完之后 /tokenledger diagnostics 会打印当前的路由归属和索引里的路由——排查「我的中转站为什么不显示」看这里,不用猜。
装完即可用:没有要填的配置,也不需要任何凭据就能看到全部用量与中转站分布。余额是唯一用到 key 的地方,而那把 key 宿主已经替你存着了。
命令 / Commands
面板能回答的问题,命令行都能回答——两边读的是同一批查询,不存在第二套聚合。
/tokenledger # 全部时间
/tokenledger 7 # 最近 7 天
/tokenledger 30 api.example.com # 某个中转站,最近 30 天
/tokenledger site # 列出发现到的中转站
/tokenledger site add <路由名> <地址>
/tokenledger site rm <路由名>
/tokenledger export csv 30 # 导出
/tokenledger diagnostics # 索引健康度
/tokenledger reindex # 丢弃索引,从头重建
支持的账户类型 / Providers
| Provider | 模式 | 凭据 | 上游接口 |
|---|---|---|---|
| DeepSeek 官方 | 余额 | provider 的 apiKeyEnv | /user/balance |
| New API 系(含 One API、VoAPI 等分支) | 余额/额度 | provider 的 apiKeyEnv | /api/usage/token/ + /api/status |
| Sub2API | 余额 / 额度 / 订阅 | provider 的 apiKeyEnv | /v1/usage |
| Moonshot / Kimi | 余额 | provider 的 apiKeyEnv | /v1/users/me/balance |
| 智谱 GLM / Z.ai | 余额 | provider 的 apiKeyEnv | /api/biz/account/query-customer-account-report,读不到时回退 /api/paas/v4/balance |
| OpenRouter | 余额 | Management Key | /api/v1/credits |
| OpenCode Go | 订阅 | provider 的 apiKeyEnv,或本机 auth.json | /zen/go/v1/usage |
| Kimi For Coding | 订阅 | provider 的 apiKeyEnv | /coding/v1/usages |
| MiniMax Coding Plan | 订阅 | provider 的 apiKeyEnv | /v1/token_plan/remains |
| 智谱 GLM / Z.ai Coding Plan | 订阅 + 余额 | provider 的 apiKeyEnv | /api/monitor/usage/quota/limit |
…

