DeepSeek API balance + per-call cost tracker: durable per-call cost ledger from real usage chunks with official Beijing peak/off-peak (x2) pricing, 60 s balance polling, and a sidebar footer action showing balance and today's spend.
Install
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:storyOuO/dsh-plugin-ds-balance
Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).
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
Links
More in this category
bowenliang123/dsh-context★ 1192
DSH context insight panel: Context dashboard + /context command + Context browser — one-stop context lifecycle management with categorized composition, content details, evolution trends, compaction/injection events, and stats.
Han-1413141/dsh-cost-meter★ 232
Per-session and daily API cost, budget with usage %, official balance, history dashboard, and one-click official price sync with peak/off-peak pricing.
zh667/TokenLedger★ 190
Sidebar usage panel that attributes tokens to the relay site that served each request, read from your existing provider config: today/month/all-time totals, per-site and per-model breakdowns, a year activity heatmap, and New API / Sub2API / DeepSeek balances.
wssfk12138/dsh-damage-pulse★ 145
Tracks DeepSeek token usage, per-call and session costs, and account balance with cache-aware charge animations in the DSH Web UI.
Ychris12138/dsh-usage-stats★ 132
Multi-provider usage dashboard with provider/model token breakdowns, calendar drill-downs, account balances, and OpenCode Go / Z.ai subscription quota tracking.
feibi-mochi/deepseek-harness-control-center★ 66
DeepSeek Harness control center for official balance monitoring, per-session costs and tokens, third-party token totals, completion alerts, official recharge, flexible layouts, and agent-assisted session controls.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.