Introduction¶
When running agents in DeepSeek Harness (DSH), ctx.tokenMeter only reflects request pressure: the Harness does not convert tokens into monetary amounts, nor does it have a built-in price list. The three things you actually care about are often scattered across different locations—the account balance is at the official DeepSeek API, the actual daily deductions are in the local balance ledger, and the hourly tokens are in the session logs. To align “how much was spent” with “which time period the tokens were spent,” you need to piece together these three data streams. dsh-token-bill is a community plugin maintained by SanChou0627 and categorized as a web tool; it exposes two read-only tools to the model, summarizing balance, daily costs observed by the ledger, and hourly token statistics, while generating Markdown, HTML, or JSON bills.
What is this¶
The positioning of dsh-token-bill (GitHub: SanChou0627/dsh-token-bill, current package version 0.1.0, MIT License) is to use token_status to query real-time status and token_bill to generate bills with bar charts and detail tables under the DSH Web configuration. It requires no additional UI or resident daemon; the plugin does not write to the ledger, session logs, or credential files.
The design principles are clearly stated in the README: Amounts are based on observation, while tokens are based on metering. The total daily cost comes primarily from the $DSH_HOME/.dshw-usage.json balance ledger (written by dsh-whale-widget); hourly costs are calibrated using the price list for apportionment when the total ledger amount is known, ensuring sum(hourly_amounts) === daily_amount (amounts are stored as integers in units of 1e-8 yuan).
Core Features¶
Data Sources¶
| Requirement | Source | Description |
|---|---|---|
| Real-time Balance | GET https://api.deepseek.com/user/balance |
API Key authentication; falls back to the last ledger observation on failure (marked as such) |
| Actual Daily Spend | $DSH_HOME/.dshw-usage.json |
Degrades to price list estimation and explicitly marks it if the ledger is missing |
| Hourly Tokens | $DSH_HOME/sessions/**/session.v*.jsonl.zstd (and legacy uncompressed jsonl) |
Uses four mutually exclusive buckets reported by the provider: inputTokens, cacheReadTokens, cacheWriteTokens, outputTokens |
The API Key is read from the environment variable DEEPSEEK_API_KEY (or DSH_DEEPSEEK_API_KEY, DEEPSEEK_KEY) or refs.DEEPSEEK_API_KEY in $DSH_HOME/.credentials.yaml.
Two Model Tools¶
token_status: Returns the current date, balance, currency, balanceSource (api or ledger), stale status, daily cost observed by the ledger, token summaries, call counts, etc. Optional parameters include includeLedger (default true) and includePricing (default false).
token_bill: Generates a bill based on Beijing timezone dates (defaulting to the current day); supports days to summarize the last N days, costMode (ledger | token | both, default ledger), write (default true), and formats (default ["html","md"]). The output includes hourly token/cost bars, peak/valley splitting, and peak periods. Files are written to $DSH_HOME/token-bill/ as token-bill-<day>.{html,md,json} by default, which can be overridden via the environment variable DSH_TOKEN_BILL_DIR or the config option outDir.
The bill supports a peak-valley electricity pricing concept: peak periods during Beijing timezone daytime, and valley periods on weekends and statutory holidays, distinguishing between peak and valley tokens in the report.
Installation and Activation¶
Environment requirements: Node ≥ 22.12 (the plugin resolves DSH sibling dependencies via require(esm)); the DSH Web profile must have the tools service mounted.
The following introduces the installation methods from the official README. Installing from the registry (once the documentation notes that the release is available):
dsh plugin --profile web add dsh-token-bill
For local development or self-managed copies, use link pointing to an absolute path:
dsh plugin --profile web add link:/absolute/path/to/dsh-token-bill
After installation, the model will see the two tools above in new sessions. If the profile does not auto-reload, you need to restart the DSH Web service.
Typical Usage¶
Usage is completed by the agent calling tools during the conversation; no separate CLI is needed. The common flow is as follows:
- Call
token_statusfirst to quickly confirm the balance source, daily ledger-observed costs, and token bucket distribution (including cache hit rate statistics). - When archiving or sharing is needed, call
token_bill, settingday,costMode, andformatsas required; by default, it writes HTML (with inline SVG bar charts) and Markdown, but you can also request only JSON for script consumption. - If dsh-whale-widget is already running and has generated
.dshw-usage.json, keepcostModeasledgerso that the daily total aligns with account balance changes; without a ledger, accepttokenmode with an “estimated” annotation.
The text field returned by token_bill is the fully rendered, human-readable content, consistent with the content of the saved files; files lists the paths written.
Use Cases and Notes¶
This is suitable for developers and teams running Web agents in DSH long-term who need to align official balances, ledger-observed deductions, and session-level token metering. The hourly bar chart facilitates comparison of peak periods and cost allocation; the read-only design is suitable for inclusion in daily inspections without altering the Harness’s own metering semantics.
Please note before installation: The plugin runs with the permissions of the current DSH process, reads API Keys, ledgers, and session logs, and may request api.deepseek.com; you should review the GitHub repository source code and MIT License yourself before installation. The community directory SkillHub Plugin Page has no official affiliation with DeepSeek or Hithink RoyalFlush and is a third-party entry within the DSH “everything is a plugin” ecosystem.
When dsh-whale-widget is not running, the ledger does not exist, and daily costs can only rely on price list estimation; the balance can still be obtained from the live API. Recharges are recorded in the ledger’s creditUnits and will not falsely inflate “spending”; if ledger rows cannot be closed, the plugin will explain rather than silently erroring.
Conclusion¶
dsh-token-bill connects balances, ledgers, and Session logs scattered across three locations under a unified set of rules, using two agent tools to output archivable bills. Directory page: https://www.skillhub.cn/plugins/SanChou0627/dsh-token-bill; Source code and full parameter descriptions: https://github.com/SanChou0627/dsh-token-bill.