Preface¶
The plugin architecture of DSH allows extending capabilities around sessions, tool calls, and context management. When performing token cost accounting, a common issue is mixing information from different sources into a single total: some calls lack persisted usage data, some routes are not covered by the price book, and current context pressure is not the same as cumulative spend.
dsh-cost addresses these problems. It calculates costs based on durable assistant/message.usage events, presenting route breakdowns, evidence completeness, optional budget status, and the current ctx.tokenMeter pressure snapshot separately, while providing explicit fail-open/fail-closed budget checks.
What This Is¶
dongsheng123132/dsh-cost is a plugin for DeepSeek Harness (DSH), positioned as:
Evidence-first token cost ledger and budget checks for DeepSeek Harness
It is maintained by dongsheng123132, licensed under MIT, requires Node.js >=22, and has @deepseek-ai/dsh-tools as an optional peer dependency.
Core Features¶
Session Cost Reports¶
dsh-cost provides durable session cost reports, including:
- Cost calculation based on durable
assistant/message.usageevents - Route breakdown
- Evidence completeness
- Optional budget status
- Current
ctx.tokenMeterpressure snapshot
Cost here is not aggregated out of thin air but derived from existing persisted usage events. Calls with missing usage or not covered by the price book remain in an explicit state rather than being merged into a seemingly complete total.
Budget Checks¶
The plugin provides explicit fail-open/fail-closed budget checks.
Note: It does not claim to automatically intercept future calls. Budget checks are decision outputs, not an automatic interception mechanism for subsequent requests.
MCP Server¶
The plugin includes a stdio MCP server exposing:
cost_reportcost_check
MCP accepts only bounded, sanitized usage rows and rejects prompts, message bodies, credentials, and any other additional fields.
Price Book¶
Cost calculation uses a user-owned price book. Prices are calculated per million tokens, with token buckets divided into:
- Input
- Output
- Cache-read
- Cache-write
These buckets are disjoint. The price book does not include vendor prices; prices should be maintained by the user based on current vendor contracts and kept up to date.
Offline CLI Ledger¶
dsh-cost provides an offline CLI ledger for calculating costs from durable assistant/message.usage events.
Installation and Enablement¶
Install the plugin under the target profile:
dsh plugin --profile <name> add github:dongsheng123132/dsh-cost
After installation, the price book path and default budget need to be configured. Verified configuration items include:
priceBookFile
defaultBudget
An example configuration is as follows:
- id: dsh-cost
name: dsh-cost
config:
priceBookFile: C:/absolute/path/prices.json
defaultBudget: 5
priceBookFile points to a price file maintained by the user, and defaultBudget sets the default budget value. Prices in the price file should be entered per million tokens and must distinguish between the four buckets: input, output, cache-read, and cache-write.
Typical Usage¶
Offline Session Cost Calculation¶
When session events and a price book are already available, the offline CLI can be used directly:
dsh-cost --events session-events.json --prices prices.json --budget 5 --fail-closed
This command calculates costs from an existing events file and performs a fail-closed check with the budget parameter.
If missing usage or unpriced calls exist, results under the budget should be interpreted as unknown, not within. In other words, when evidence is incomplete, the plugin will not give a seemingly reliable “within budget” conclusion.
Using via MCP¶
The same evidence-based cost accounting capability is also available through the bundled stdio MCP server, with the interface names:
cost_report
cost_check
On the MCP side, only bounded, sanitized usage rows are accepted, and prompts, message bodies, credentials, and other additional fields are rejected.
Applicable Scenarios and Considerations¶
Suitable for use in the following scenarios:
- Need ledger-style recording of token costs in DSH sessions
- Need to distinguish between route breakdowns, evidence completeness, and budget status
- Need explicit budget checks rather than just a single aggregated number
- Need to preserve missing usage and unpriced calls as independent states
- Need to expose cost reports and budget checks to external tools via MCP
Points to note before use:
- The plugin runs with the current dsh process permissions; source code and the MIT license should be reviewed before installation
dsh-costdoes not automatically intercept future calls; budget checks are explicit decisions, not a request gateway- The price book is maintained by the user and does not include vendor prices
- If usage is missing or calls are unpriced, results under the budget are unknown, not within
- MCP only accepts bounded, sanitized usage rows and rejects additional fields
- The DSH community directory is an independent site with no official affiliation with DeepSeek / High-Flyer; it should not be treated as an official app store
Conclusion¶
The value of dsh-cost lies in transforming token costs from ambiguous totals into an auditable evidence chain: costs derive from durable usage events, routes and evidence status are presented separately, budget checks explicitly distinguish fail-open from fail-closed, and missing information is not packaged as “within budget.”
Related links:
- Community directory: view the entry by
dsh-cost - GitHub: https://github.com/dongsheng123132/dsh-cost