Introduction¶
Running agent conversations in DSH consumes tokens for both context and tool calls. While the host can usually display token usage, it is difficult to correlate “how much this session cost,” “the cumulative total across all sessions,” and “whether to intercept before sending the request in this turn” on a single screen. Recording data in Excel manually or reconciling statements after the fact creates a disconnect from the pace of the conversation.
The yoka-dsh-billing introduced below (repository niliemi/dsh-billing, maintained by niliemi, categorized under SkillHub admin-security) is a DSH billing plugin. It prices four types of tokens using official price lists, displays session and global costs persistently below the chat input box and to the left of the token ring, and shows the DeepSeek account balance in the sidebar. When your set limits are reached, the host blocks LLM requests before the turn begins.
What is this¶
In one sentence: It bills based on tokens within DSH Desktop, features dual-track limits (global + single session), allows blocking when limits are exceeded, and supports resetting the “current” billing starting point without losing historical token records.
- npm package name:
yoka-dsh-billing, current version 0.2.8 (subject topackage.json) - Runtime environment: Node
>=20, DSH>=0.2.0-rc.1; README documents long-term compatibility tests with DSH Desktop 0.2.0-rc.2 - Browser profile half:
web; ledger and pricing occur in the host half, while the browser fetches state via same-origin/plugin-billing/...
What you will see on the interface¶
Two badges are persistently displayed below the chat input box (illustration):
● ¥0.0834 / ¥50.00 ↺ ● ¥12.3600 / ¥1000.00 ↺
Current Session Billing / Limit Global Current Billing / Your Set Global Limit
- Bottom of the left sidebar (next to settings button):
Balance ¥...(Recharge + Credit, for reference only, refreshes approximately every 60 seconds, panel can be manually refreshed) - Click a badge to open the panel; the ↺ on the right side of each cost item resets the billing start point for that metric
- Dot color: Green <60%, Orange 60–90%, Red ≥90%; if no global limit is set, the dot is gray (no blocking)
After clicking a badge or the sidebar balance to enter the panel, you can configure the global billing limit, exchange rate, over-limit blocking switch, per-session limits for each individual session, and override unit prices by model or restore official prices.
Core Functions¶
Billing Metrics¶
| Item | Description |
|---|---|
| Granularity | Global (accumulated across all sessions) + Single Session (aggregated by session for the same set of tokens) |
| Token Source | Folding logic identical to the official tokenUsage projection |
| Four Token Types | Uncached Input / Output / Cache Read / Cache Write, priced separately |
| Unit Price | Built-in @earendil-works/pi-ai official price list (USD / million tokens); repository locks 32 providers and 605 models, panel supports per-model overrides |
| Exchange Rate | Default 1 USD = 7.2 CNY, changeable in the panel |
| Unknown Models | Estimated price [Input 1, Output 4, Cache Read 0.1, Cache Write 0] USD / million tokens |
Amounts are always calculated on the fly: The ledger only stores tokens and model keys; changing the exchange rate or unit price immediately recalculates all historical usage.
Limits, Balance, and Blocking¶
- Global Limit: Entered in the panel “Global Billing Limit”; blank or 0 = no limit, no blocking. The limit is self-set and does not automatically equal the balance.
- Balance: Comes from the host’s
deepseekAccount.getBalance(recharge + credit). If your set global limit exceeds the balance, it will be clamped to the balance (the original value remains in the ledger); if the balance cannot be retrieved or is 0, no clamping occurs, and your self-set limit remains effective. - Single Session Limit: Located in the independent “Single Session Limit” section of the panel. Each session has its own setting, independent of others; blank / 0 = no limit for that session; not subject to balance clamping.
- Crossing the Line: If the limit is crossed and the guard is enabled, the host returns
{kind:"reject"}atagent/pre-step, and the LLM request is not sent for that turn. After blocking, you can choose to allow once, allow for this session, go to recharge, raise the limit, or not allow temporarily (allowing for “this session” does not bypass the global limit).
Current, Cumulative, and the two ↺¶
- Current: Calculated from the last reset, used for comparison with limits; Cumulative represents all history, is for reference only, and never resets to zero.
- Global ↺ only resets the global current counter; Session ↺ only resets that specific session’s current counter; they do not affect each other. “Clear History” at the bottom of the panel is a hard reset (deletes all token records, irrecoverable).
Data and HTTP¶
- Default Ledger:
~/.dsh/billing/ledger.json(can be overridden via plugin configstoreFile) - Host Route Prefix:
/plugin-billing(e.g.,GET /state,POST /config,POST /reset, etc.); the guard only accepts same-origin /dsh-auth-cookie / loopback address requests.
Installation and Activation¶
The installation goal is to allow the desktop profile to resolve this package and register it in dsh.profile.bundles. The equivalent commands executed in the README are as follows (replace the local directory with your path):
# Use the plugin_manager tool within a DSH session, equivalent to:
dsh plugin --profile desktop add link:<dir>
# Example target: link:C:\Users\walex lin\Desktop\dsh workflow\plugins\dsh-billing
Upon success, "yoka-dsh-billing": "link:..." is written to the dependencies in ~/.dsh/profiles/desktop/package.json, and the package name is appended to dsh.profile.bundles, followed by a hot application.
The plugin’s built-in Cordis patch inserts the service with default configuration:
- insert:
- id: yoka-dsh-billing
name: 'yoka-dsh-billing'
config: { rate: 7.2, limit: 0, guard: true }
This means the default exchange rate is 7.2, global limit is 0 (no limit), and the over-limit guard is enabled. The browser half is injected via dsh-client-modules using a combo URL (of the form /plugins/??yoka-dsh-billing/client.js&rev=<rev>), requiring no separate build.
Typical Usage¶
- After installation and hot application, verify the appearance of the dual badges and sidebar balance below the input box. If they do not appear, use
node tests/probe-hmr.mjsfrom the README to check if the running host has loaded the localclient.js(for development/self-testing scenarios). - Click the badge to open the panel: Enter the budget for this round (CNY) in “Global Billing Limit”; modify the exchange rate if needed, and ensure “Over-limit Blocking” is enabled.
- In the “Single Session Limit” section, fill in the limit for each row corresponding to current or historical sessions; the current session row will be marked “Current”.
- Observe the badge color and “Current / Limit” during the conversation; blocking will occur when approaching or exceeding the limit. Follow the prompts to allow or click the corresponding ↺ to reset the billing start point.
- If you need to change configuration via HTTP, you can write to the same-origin
POST /plugin-billing/configwith{limit},{sessionId, sessionLimitFor}, exchange rate, and unit price overrides, etc. (see README interface table for details).
Use Cases and Notes¶
Who it is for: Developers who run agents across multiple sessions in DSH Desktop for extended periods, wish to use official price lists for equivalent cost reference, and rely on self-set limits to hard-stop losses before sending requests.
Must Know:
- The plugin runs with the current DSH process permissions: The host half reads/writes only this plugin’s ledger (default
~/.dsh/billing/ledger.json), and the browser half only sends requests to same-origin/plugin-billing. Please review the source code and MIT license before installation. - Subscription-based accounts do not charge by token unit price; the amount displayed is an equivalent value reference, not a DeepSeek invoice.
- SkillHub Directory Page: niliemi/dsh-billing is a community plugin index and has no official affiliation with DeepSeek / High-Flyer; the DSH ecosystem philosophy is “everything is a plugin,” decoupling the store from the host.
Conclusion¶
yoka-dsh-billing integrates token usage, official price lists, dual-track limits, and blocking guards into the DSH interface: view session and global costs next to the input box, view balance in the sidebar, and set global and per-session limits in the panel to reset the “current” start point. For details, screenshots, and self-testing commands, please refer to the GitHub README.
- Directory Page: https://www.skillhub.cn/plugins/niliemi/dsh-billing
- Repository: https://github.com/niliemi/dsh-billing