Introduction

In the DSH plugin ecosystem, plugins like router / mode-boost typically handle routing or modes, while persona handles personality and expression. If you only call the DeepSeek API without self-hosting, another common problem is cost: how much a session costs, how the cache hit rate is, how peak and off-peak coordination works, and whether billing stops after the budget is exhausted.

sixtysevenlf/dsh-cost-guard is a cost plugin designed for this scenario. It is mounted on top of router / mode-boost, does not touch persona, and only handles things related to “money”.

What is it

dsh-cost-guard is a DSH cost plugin, repository name is sixtysevenlf/dsh-cost-guard, license is MIT.

It targets the “API-only, self-deployment-free” scenario, calculating session costs for DeepSeek V4-Flash-0731 based on DeepSeek’s official 2026-08-17 peak/off-peak tiers (¥/million tokens), and provides budget guard, session-level convergence toggle, automatic cost routing, peak/off-peak awareness, off-peak queue, client dashboard, and dsh-optab sub-package.

Core Features

Cost Calculation & Cache Statistics

The plugin calculates session costs and tracks cache hit rate, full hit savings, and spent amount (¥).

cost_status can be used to view the current status.

Budget Guard

cost_budget {budget} is used to set a budget. The budget is a hard limit: after spending up to the budget, llm/stream is short-circuited and intercepted, and no new billing is generated.

There is a clear boundary: the request currently in flight will complete; subsequent new requests will be short-circuited and will not incur new fees.

The budget hard limit only takes effect when the project cost guard is enabled. When the guard is disabled, the budget is only recorded and not intercepted. Off-peak daemon and one-off calls without sessionId are not affected by the budget gate.

Session-level Convergence Toggle

The input box button can serve as a session-level convergence toggle: click once to inject a convergence guide, click again to retract the unconsumed guide and exit convergence mode.

cost_guide {target} can also be used to inject a convergence guide.

Here is a principle: do not inject dynamic content into system; dynamic signals should go to the end of the message to avoid breaking the prefix cache.

Automatic Cost Routing

Complex tasks can automatically choose depth, convergence, or off-peak based on complexity, peak/off-peak, and remaining budget.

Peak/Off-peak Awareness & Off-peak Queue

cost_peak is used to view the current peak/off-peak status and off-peak suggestions.

cost_defer {task, maxTokens?} is used to register tasks into the off-peak queue, to be executed automatically during idle periods by the daemon.

cost_deferred is used to view the queue status.

Client Dashboard

The client dashboard provides monitoring cards, budget three-level scopes, off-peak queue, deferred results, project-level enable toggles, and project grouping.

dsh-optab Sub-package

The dsh-optab sub-package provides prefix trimming, tool output compression, automatic reasoning tier selection, and supports peak-time caps and overspending tightening.

Installation and Usage

First, install the plugin package:

dsh plugin --profile web add <tgz>

If there is an existing local directory, the installation methods provided in the documentation include:

dsh plugin --profile web add <this directory>

In hot-injection scenarios, you can use:

dev_inject_plugin D:\DSH\测试\优化\dsh-cost-guard

You can also execute:

dev_install_package

The plugin depends on cordis:

cordis >=4.0.0-rc <5

Dashboard registration depends on a restart: client-modules is cached by package name and never expires; changes to the plugin set require a restart of the web process to take effect. In hot-injection scenarios, if the dashboard or the “convergence” button does not appear, restart the web process once.

If building dsh-optab from source:

cd optab && bash scripts/build.sh

This build requires DSH_CHECKOUT; lib/ is the build artifact and is not included in the repository.

Typical Usage

Below are examples of tools and interfaces provided in the documentation.

View status and set budget:

cost_status
cost_budget {budget}

View peak/off-peak and register off-peak tasks:

cost_peak
cost_defer {task, maxTokens?}
cost_deferred

Inject convergence guide, or switch project-level toggle:

cost_guide {target}
cost_enable {mode: on|off|auto}

The dashboard can call the following interfaces:

GET /cost-guard/api/state
POST /cost-guard/api/enable
POST /cost-guard/api/optab {enabled}

Applicable Scenarios & Notes

This plugin is suitable for those who only use the API and wish to view costs, cache hits, budgets, and off-peak tasks in a unified way.

Its division of labor with router / mode-boost is: they handle routing and modes, while dsh-cost-guard handles costs.

Usage notes:

  • The plugin runs with the current DSH process permissions; before installing, check the source code and the MIT license.
  • The budget hard limit only takes effect when the project cost guard is enabled; when the guard is disabled, the budget is only recorded and not intercepted.
  • The request currently in flight will complete; only subsequent new requests will be short-circuited.
  • Off-peak daemon and one-off calls without sessionId are not affected by the budget gate.
  • Do not inject dynamic content into system; dynamic signals should go to the end of the message to avoid breaking the prefix cache.
  • The dashboard uses a two-step confirmation for deleting projects or sessions, as window.confirm is silently intercepted in sandboxed iframes.
  • v0.1.17 removed the “boot self-healing” feature based on unauthorized access to the dsh-client-modules private API.
  • The plugin has zero dependencies, is neutral regarding prefix caching, is mounted on the host plane, and does not touch the internal state of dsh-client-modules.

Conclusion

The value of dsh-cost-guard lies in putting cost calculation, budget hard limits, convergence guidance, automatic cost routing, and off-peak execution in the same DSH plugin suite.

GitHub repository address:

https://github.com/sixtysevenlf/dsh-cost-guard