DeepSeek 余额与逐次调用成本追踪:基于真实 usage 的持久化成本账本,支持官方高峰/低谷定价(北京时间 ×2),60 秒余额轮询,侧栏底部显示余额与今日消耗。
安装
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:storyOuO/dsh-plugin-ds-balance
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。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
该插件的 README 只有英文版本。
A dsh plugin that tracks your DeepSeek API balance and per-call cost live in the sidebar.
It is a dual-face ("双面") dsh plugin built on the standard Cordis extension mechanism — no private dsh APIs:
- Host half (
lib/index.js, Node) wraps thellm/streamwaterfall, prices every successful DeepSeek call from the provider-reportedusagechunk into a durable per-call ledger, polls the official balance endpoint, and exposes a JSON snapshot route/api/ds-balance. - Client half (
lib/client.js, browser) injects an action into thesidebar.footer.actionslot showing balance + today's spend (30 s polling).
Content is DeepSeek-specific: only the
deepseek-officialprovider is priced, and the balance endpoint / response shape (balance_infos,total_balance) are DeepSeek's. The mechanism is generic and works in any dsh profile (dsh web, headless, or this desktop shell).
Features
- Per-call cost ledger from real
usagechunks (durable, JSON under the dsh home). - Daily rollover at the host machine's local midnight, with archived per-day history.
- DeepSeek official balance polling (every 60 s) with
.bakrecovery so a torn write can never wipe the ledger. - Peak pricing: off-peak buckets billed ×2 during Beijing peak windows (Mon–Fri 09:00–12:00 and 14:00–18:00, UTC+8, no DST).
- Per-model pricing overrides via the loader entry
config.
Install
The package declares dsh.bundle, so it installs through the official plugin
path (recommended):
npm install ds-balance
dsh plugin --profile web add ds-balance
It can also be wired by name in the profile's cordis.patch.yml (see
cordis.patch.yml.example) — the bundle install
and the patch wiring are equivalent, and both keep the package resolvable by
the bare name ds-balance:
- insert:
- id: ds-balance
name: 'ds-balance'
config:
pricing:
deepseek-v4-pro:
input: 2.0
cacheRead: 0.5
cacheWrite: 2.0
output: 8.0
config.pricing.<model> overrides the default off-peak CNY-per-1M-token
buckets. cacheWrite defaults to input when omitted.
Data & troubleshooting
The durable ledger lives at $DSH_HOME/storages/ds-balance.json (default
~/.dsh/storages/ds-balance.json). Each successful DeepSeek call appends one
ledger entry; the whole file is replaced atomically and the previous good
snapshot is rotated to ds-balance.json.bak, so a torn write can never wipe
the history — the plugin falls back to the backup automatically.
| Symptom | Cause / fix |
|---|---|
Sidebar shows -- for balance |
No DEEPSEEK_API_KEY in the environment or in $DSH_HOME/.credentials.yaml (refs.DEEPSEEK_API_KEY); the host records balanceError: "no DEEPSEEK_API_KEY". |
| Balance never refreshes | The balance poll hits api.deepseek.com directly; check your network / proxy. balanceError carries the last failure and the snapshot is marked stale. |
| Today's spend looks wrong | Peak windows bill ×2 (Mon–Fri 09:00–12:00 / 14:00–18:00 Beijing time); check the call time and your per-model config.pricing overrides. |
| Want a fresh start | Stop dsh, delete ds-balance.json (and its .bak), restart. History since the last midnight is lost; today's counters reset. |
Test
The verification script exercises the host half (pricing, ledger, credentials
key resolution, daily history, .bak recovery) with a mocked cordis ctx —
no network, no absolute paths:
npm test
License
MIT
链接
同类插件
bowenliang123/dsh-context★ 1969
DSH 上下文洞察面板:Context 仪表盘 + /context命令 + Context 浏览器,查看 Context的分类组成、内容详情、演进趋势、压缩/注入事件、统计等一站式 Context 全生命周期管理。
Han-1413141/dsh-cost-meter★ 388
会话与当日 API 费用统计、预算图框(已用%)、官方余额、历史看板,支持峰谷计价与官方价格一键同步。
wssfk12138/dsh-damage-pulse★ 257
在 DSH Web 界面追踪 DeepSeek Token 用量、单次与会话费用及账户余额,并显示缓存感知的扣费动画。
zh667/TokenLedger★ 202
侧边栏用量面板:把 Token 归属到实际服务该请求的中转站,站点从已有的 provider 配置中读出,无需额外配置;含今日/本月/累计三窗口、按站点与模型下钻、一年活跃度热力图,以及 New API / Sub2API / DeepSeek 余额。
Ychris12138/dsh-usage-stats★ 171
多供应商用量看板:按供应商/模型统计 Token 与日期下钻,统一展示账户余额,并追踪 OpenCode Go / Z.ai 订阅额度。
PolinniZhong/dsh-personal-center★ 118
DeepSeek Harness 个人中心:跨会话用量统计、按模型成本估算、全局自定义指令、外观全局字号、数据驱动的桌面宠物(位图/矢量皮肤)与会话状态概览,纯本地离线运行。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。