Foreword¶
In DSH, usage at this level is usually just a token count: you can read how many tokens were used this round, but it is hard to directly answer “how much money this message cost”. Prices vary by model and time slot—DeepSeek offers discounts on reasoning prices during certain hours, and the unit price for usage generated during rush hour and late night in the same conversation is not the same, while cache hits and misses represent two different pricing structures. To calculate this per round, one must read the official usage projection themselves, determine time slots, convert amounts, and also maintain the “cumulative for all sessions” layer.
Below is an introduction to dsh-plugin-usage-budget. It converts token usage into RMB amounts based on configurable pricing, providing session cost readings, per-round prices, account balance, and daily/weekly/monthly budget guards. It does not participate in inference itself, only manages cost calculation.
What is this¶
One-sentence positioning: DSH’s usage cost and budget plugin, responsible for the “token → amount → budget reminder” chain.
- Repository: dddfuxi/dsh-plugin-usage-budget
- Maintainer: ddfuxi (GitHub); package
authorfield isfuxi - Category: Model Inference (Usage billing side, not the inference core)
- License: MIT
- Version:
0.1.0(package.json) - Requirements: Node
>=20, for@deepseek-ai/cordis~4.0.5
The plugin is a merge of two early self-use small plugins: dsh-plugin-usage-cost (cost reading) and dsh-plugin-account-balance (account balance), plus new budget guards and per-round prices.
Operation Mechanism¶
The Host side registers two session projections in lib/index.js:
usageCost: For every settledassistant/messageusage event, uses the event’s own time to determine peak/valley hours, calculates and accumulates based ontokens / 1e6 × unit price × time slot discount, accumulates by round, and keeps the last 120 rounds.usageBudget: Converts every usage event into an amount and writes it to a ledger aggregated by local natural day, outputting today / this week / this month, budget levels, and a table of unit prices required for the next estimate.
Two files handle core logic:
lib/pricing.js: Core pricing, no dependencies, usesIntlforAsia/Shanghaiand DST time slot determination.lib/budget.js: Core ledger, pure functions, 48 unit tests, runs in both browsers and Node.
The ledger falls at $DSH_HOME/usage-budget/ledger.json. On first run (or ledger version change), a global backfill happens: reads all session logs stored on disk, rebuilds the ledger based on each usage event’s own time and pricing, and then only does incremental updates; forks of sessions with inherited prefixes (before session/end-seed) are skipped to avoid double billing.
Interface & Features¶
The plugin does not modify the official DOM but uses extension points:
| Interface | Position | Data Source |
|---|---|---|
| Current Session Usage Cost | Input box status bar (Usage Icon) | Host usageCost projection, priced by actual round time |
| Budget / Remaining / Next Estimate | Input box status bar (Shield Icon) | Host usageBudget projection + Global Ledger |
| Account Balance | Session top preset bar + Budget Popup | remote.account.getBalance (same source as “Settings -> Account & Balance”) |
| Per-round Price / Cache Savings | “Current Round Usage” popup for each message | Matches tokens of that round’s token bucket with usageCost.turns |
| Every Message Usage Row | Bottom of every assistant message | Tokens + Amount for that round in usageCost.turns |
Input box controls are registered via the conversation.composer.dock slot, with the same ID as built-in usage controls but lower priority, thus replacing in place; the usage row at the bottom of messages uses the official extension point conversation.chat.turnTail. Budget popup and per-round price popup cover cumulative and unit price breakdowns for “Today / Rolling 7 Days / Natural Month” respectively.
Peak/Valley Pricing¶
Built-in default pricing is RMB Yuan / 1 Million tokens (taken from DeepSeek official pricing page in Nov 2026):
| Model | Cache Hit | Cache Miss | Output |
|---|---|---|---|
deepseek-flash |
0.04 | 2 | 8 |
deepseek-v4-pro |
0.30 | 9 | 27 |
Peak hours are Beijing Time Mon-Fri 09:00–12:00, 14:00–18:00; off-peak (including weekends) is 50% off; DeepSeek does not list a separate cache write price, so cacheWrite: 0. The pricing config item can cover the whole table:
pricing:
currency: CNY
timezone: Asia/Shanghai
models:
deepseek-flash: { cacheRead: 0.04, cacheWrite: 0, input: 2, output: 8 }
deepseek-v4-pro: { cacheRead: 0.30, cacheWrite: 0, input: 9, output: 27 }
fallback: { cacheRead: 0.04, cacheWrite: 0, input: 2, output: 8 }
windows:
- { id: offpeak, label: { zh: 优惠时段, en: Off-peak }, start: "00:00", end: "09:00", days: [1,2,3,4,5], factor: 0.5 }
- { id: offpeak, label: { zh: 优惠时段, en: Off-peak }, start: "12:00", end: "14:00", days: [1,2,3,4,5], factor: 0.5 }
- { id: offpeak, label: { zh: 优惠时段, en: Off-peak }, start: "18:00", end: "24:00", days: [1,2,3,4,5], factor: 0.5 }
- { id: offpeak, label: { zh: 优惠时段, en: Off-peak }, start: "00:00", end: "24:00", days: [6,7], factor: 0.5 }
The amount is an estimate, not a bill: converted based on configurable pricing; peak/valley determined at the moment of event settlement; Chinese statutory holidays are not modeled (windows only support days of week); for exact amounts, refer to the actual bill.
Installation & Enablement¶
Method 1 is the Plugin Manager page (recommended in README):
git clone https://github.com/dddfuxi/dsh-plugin-usage-budget.git
Then open Plugins -> Add Plugin -> Install Third-party Plugin in the DSH sidebar, paste the repository address above into “Package Name/Git Address”, or fill in the absolute path of the cloned directory in “Local Directory”. After installation, enable it; a card named Usage Cost (with icon and Chinese description) will appear in the “Plugins” sidebar.
Method 2 is manual bundle installation:
1. Copy this directory to %USERPROFILE%\.dsh\profiles\<profile>\node_modules\dsh-plugin-usage-budget
2. profile's package.json:
- dependencies add "dsh-plugin-usage-budget": "link:<absolute path to this directory>"
- dsh.profile.bundles append "dsh-plugin-usage-budget"
3. HMR will automatically reassemble; refresh the page if it hasn't updated; profiles without HMR need a restart.
Note: README does not provide one-line commands like dsh plugin add ...; the installation entry points are the Plugin Manager page or manual bundle; do not concatenate names yourself.
Configuration¶
Budget numbers are written in the profile’s cordis.patch.yml, only containing overrides (i.e., budget values), do not manually write insert lines:
- id: usage-budget
name: dsh-plugin-usage-budget
config:
dailyBudget: 30
weeklyBudget: 100
monthlyBudget: 200
warnAt: 0.75
Full config items:
| Key | Default | Description |
|---|---|---|
dailyBudget |
20 | Day budget (Yuan); 0 disables |
weeklyBudget |
0 | Rolling last 7 days budget (Yuan); 0 disables |
monthlyBudget |
0 | Natural month budget (Yuan); 0 disables |
warnAt |
0.8 | Enter warning color when spending/budget >= this ratio (0-1) |
assumedOutputTokens |
600 | Estimated output token count to be used before sending |
assumedCacheReadRatio |
null | null = use session actual cache hit rate; 0..1 can force |
pricing |
— | Optional: override pricing (structure see previous section); omitted uses built-in default pricing |
timezone |
Asia/Shanghai |
Timezone used for ledger and time slot determination |
Budget numbers can also be changed directly in Settings -> General Settings -> Usage Budget, saving and taking effect immediately upon pressing Enter or blurring.
Measurement Scope & Testing¶
The plugin only counts settled assistant/message usage; stream requests that were interrupted or retried without being persisted may be undercounted; the cumulative scope is shared by all sessions; the blocked budget is only a “guard + reminder”, not blocking sending.
Test:
npm test
# Equivalent to node --test test/budget.test.mjs test/pricing.test.mjs
Covers time boundaries, crossing midnight, timezones and DST, per-bucket amounts, cache savings, unknown model fallbacks, ledger rolling, and dirty data tolerance.
Known Limitations:
- Only counts settled
assistant/message; stream requests interrupted/retried without persistence may be undercounted. - Global backfill happens only once, covering about the last 130 days; importing earlier session logs later requires deleting the ledger to trigger a re-backfill.
- Budget is only a guard and reminder, not blocking sending (DSH’s sending path has no external blocking slots).
- Pre-send estimate is heuristic: input tokens take context pressure projection, output length takes configured assumed value.
Applicable Scenarios & Notes¶
Suitable for those already using DSH who want to view costs in terms of money rather than token count: for long session cost review, cross-session budget control, confirming actual savings from cache hits, or providing a unified cost metric for a team.
Two reminders: First, the plugin runs with the permissions of the current dsh process; check the source code and license before installing. Second, the community directory of the DSH ecosystem is an independent site with no official affiliation with DeepSeek / Huanfang, and this plugin is not an entry in the official app store. For verification, compare with the repository README and the directory page skillhub.cn/plugins/dddfuxi/dsh-plugin-usage-budget.
Summary¶
Its value lies in turning scattered token numbers into readable amounts and executable budget thresholds: costs are priced based on the time slot of the event, budgets are accumulated across sessions and persisted to a local ledger, and per-round prices and message usage rows ensure every change can be matched to an account. Budgets are implemented as “reminders” rather than “interceptions”, and exact amounts still refer to the account bill. The license is MIT, enabling self-audit before enabling.