ds-balance
已验证ds-balance · v0.2.4 · MIT · Web 界面
DeepSeek API balance + per-call cost tracker — a dsh plugin (cordis host half + sidebar client half)
安装
dsh plugin add ds-balance 用 dsh --profile default --dump-config 确认 layer 已生效 —— 参见安装指南。
源码
发布到 npm 但没有公开仓库。安装前请检查包内容。
标签
作者
说明文档
ds-balance
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.
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