The DeepSeek Harness (DSH) ecosystem already has dsh-token-meter for counting token usage, but it is only a counter. When a project moves into production, developers need to control budgets, set thresholds, and take action when spending exceeds limits (such as sending notifications or blocking requests). dsh-cost-governor is designed to solve this problem. It acts as a higher-level budget guardian, uses the official DSH sessionProjections interface to convert discrete token buckets into monetary amounts, and enforces budget policies.
Core Features¶
Model-Based Cost Accounting¶
The plugin implements cost accounting based on the official sessionProjections interface. This ensures that data remains accurate during log compaction and cold reads, and that historical records are automatically repriced when you modify the price list. It supports statistics by model dimension and breaks token buckets down into input, output, cache read/write, reasoning, and other components.
Multi-Provider Price Catalog¶
Built-in price catalogs are included for providers such as DeepSeek, OpenAI, Anthropic, Google, xAI, Qwen, GLM, and Moonshot. Independent cache read/write and reasoning rates can be configured for different providers, and all prices can be manually overridden.
Budget Governance Policies¶
Budgets can be set for daily, weekly, monthly, or unlimited periods.
* Soft threshold: warnRatio. A warning is triggered when spending reaches the configured ratio (default: 0.8).
* Hard threshold: hardRatio. A hard limit action is triggered when spending reaches the configured ratio (default: 1.0).
* Enforcement action: hardAction supports three modes: notify only (notify-only), block new requests (block-new-requests), or steer to a cheaper model (steer-to-cheaper-model).
Notifications and Dashboard¶
- Webhook notifications: Notifications can be sent when thresholds are triggered. Slack-style, Feishu, and DingTalk formats are supported.
- Visual dashboard: Available at
Settings → Usage & Cost. It provides KPI cards, an animated budget bar, a spend table grouped by model, a daily spend chart, and CSV export. - Sidebar HUD: A compact circular budget indicator is shown in the sidebar.
Installation and Enablement¶
- Install the plugin:
npm i -g dsh-cost-governor
- Add the plugin node to DSH’s
cordis.ymlconfiguration file. The configuration includes currency, budget period, amount, threshold ratios, and action.
- name: dsh-cost-governor
config:
currency: USD
budget:
period: monthly # daily | weekly | monthly | unlimited
budgetUsd: 20 # Budget cap for the period
warnRatio: 0.8 # Soft threshold: warn at 80%
hardRatio: 1.0 # Hard threshold: enforce action at 100%
hardAction: notify-only # notify-only | block-new-requests | steer-to-cheaper-model
notifyWebhook: "" # Optional webhook URL
- Restart the DSH service. The dashboard will appear under the
Usage & Costmenu on the Settings page.
Notes¶
- Billing scope: The plugin only calculates usage for final
assistant/messageresponses. If a request fails before message assembly, its input consumption is not included in the statistics (even though the provider may typically charge for it). - Price accuracy: Prices in the built-in catalog are community placeholders. Verify the official pricing from each provider before use.
- Integration verification:
block-new-requestsandsteer-to-cheaper-modelrequire integration verification against the official DSH plugin documentation to ensure correct integration with the LLM request flow.
Overview¶
- Project name: yushuosun/dsh-cost-governor
- Maintainer: yushuosun
- License: MIT
- GitHub: https://github.com/yushuosun/dsh-cost-governor