Preface¶
When running the main session, sub-agents, or workflows in DeepSeek Harness (DSH), model calls happen continuously. If you only look at each provider’s backend or scattered logs, it’s hard to answer: how many tokens did I burn today, which model did most of the spending go to, did caching help, how much balance is left on the relay station? The community plugin dsh-token-metrics (maintainer hugoyee75-cmyk) brings statistics, cost estimation, and balance queries into the DSH sidebar. The data comes from DSH’s own session logs; no additional requests are made and no content is uploaded. Below we introduce what it does, how to install it, and how to use it.
What Is This¶
dsh-token-metrics is a DSH plugin (category: model inference). It records every model call that passes through Harness and shows Token usage, estimated cost by model (including DeepSeek peak/off-peak pricing), provider balance and quota, and breaks them down by model, provider, project, source, account, date, etc. The current repository version is 0.3.0, license MIT, Node requirement ^22.19 || >=24 (see package.json).
Core Features¶
Usage Statistics¶
- Today, last 7 days, and all-time token totals with trend up/down.
- Usage rankings by model and provider; cache hit rate (whether repeated input is burning money).
- Token consumption by project and sub-agent.
- Total dimensions include: input / output / cacheRead / cacheWrite / reasoning / total, call count, cache hit rate.
- Discriminated by source: main session, sub-agent, workflow; grouped by project using the session working directory.
The statistics are based on DSH session logs: completed calls append assistant/message in the log, carrying fields like data.message.source.{provider, model} and data.usage; scenarios including main session, sub-agent, workflow, compression, and session title generation are counted. Intermediate failed-retry states assistant/attempt are not counted by default (to avoid duplication); counting failed requests can be enabled optionally.
Cost Estimation¶
- Prices are taken from the public LiteLLM price list (about 2800 models).
- Peak/off-peak pricing: DeepSeek off-peak prices are half of peak prices, differentiated by the call time.
- Switch between USD / CNY, with real-time exchange rate fetched.
- Models that cannot be matched to a price are marked as “unpriced” and provide an entry to supplement prices; they will not be silently computed as 0.
Model Access and Balance¶
- 32 service presets (prioritized for domestic providers); select one to fill in the address and protocol.
- Provider balance and quota: covering Sub2API / new-api / one-api gateways and 8 official platforms.
- Identify context, output limit, thinking tier, and attachment capabilities from the pi-ai model directory (1241 models).
- Write provider and model into DSH model configuration with one click.
For subscription-based platforms (e.g., some Coding Plans) without the concept of “balance”, the UI shows the remaining ratio for each time window and a reset countdown.
Alerts and UI¶
Seven types of alerts can be pushed to the bottom-right corner: low balance, quota nearly exhausted, quota about to reset, query failure, plugin update, etc. Alerts have three-layer deduplication: server-side cooldown, state persisted to disk, and client-side memory.
The statistics page supports time range and multi-select model filters; the trend chart and donut chart are linked. The detail table can switch by model / source / project / provider / account / date. The donut chart and trend are merged by model name (cross-provider), while the detail table is still split by provider; the two sets of totals are consistent. The UI follows DSH language settings (中文 / English) and switching at runtime takes effect immediately.
HTTP Interface and Self-Update¶
The plugin provides an API inside the host process; the port follows DSH. The statistics page has an entry, and you can also call it directly. For example, an aggregated snapshot:
| Method | Path | Purpose |
|---|---|---|
GET |
/api/dsh-token-metrics/summary |
Aggregated snapshot |
GET |
/api/dsh-token-metrics/flush |
Flush to disk immediately and return the latest snapshot |
POST |
/api/dsh-token-metrics/rebuild |
Recompute all statistics from session logs |
Manual recomputation example (the port depends on your local DSH):
curl -X POST http://127.0.0.1:53414/api/dsh-token-metrics/rebuild
The version number in the upper-right corner is clickable to check for updates; self-update, installation, and hot reload are supported, with rollback on failure. The plugin has zero runtime dependencies; no npm install build is required.
Installation and Activation¶
Run in DSH (replace the path with your local plugin directory):
plugin_manager install_bundle /path/to/dsh-token-metrics
Or manually write into the profile’s package.json:
{
"dsh": { "profile": { "bundles": ["dsh-token-metrics"] } },
"dependencies": { "dsh-token-metrics": "link:/path/to/dsh-token-metrics" }
}
After restarting DSH, a “Token Usage Statistics” icon will appear in the sidebar. The first time you open the page, it automatically back-scans historical session logs to recompute usage; it may take a few to a dozen seconds depending on the number of sessions.
Typical Usage¶
- After installation and restart, open “Token Usage Statistics” from the sidebar and wait for the first back-scan to complete.
- Switch among “Today / Last 7 days / All” at the top; use the model dropdown multi-select to narrow the range; check whether the metric cards, trend chart, and detail table are linked.
- Switch to the “Model Access” tab, configure the relay station or official platform, and view balance, quota, and reset countdown; adjust alert thresholds and other settings in
cordis.patch.ymlif needed. - If it does not match the official bill, take the official bill as the standard; local statistics are for trends and attribution. After switching accounts, historical usage cannot be traced back to the account from the logs and will be attributed as “Unknown”.
Common configuration override example (note: an override with the same id entirely replaces config; to change a few items, write all of them or only the items you want to change):
- id: token-metrics
config:
showSessions: true
snapshotCacheMs: 5000
For more items, see the repository README configuration table (e.g., retentionDays, trackAccount, alertThresholds.*, etc.).
Use Cases and Notes¶
Who it is for: developers who long-term mix multiple models and multiple providers in DSH, need local aggregation of tokens, rough cost estimation, and monitoring of balance and quota, and want the data to remain within the local machine’s session log chain.
Permissions and security: the plugin runs with the permissions of the current DSH process. It reads session logs and (enabled by default) read-only information of the currently logged-in account. Before installing, review the GitHub source and the MIT license to confirm compliance.
Platform: does not call shell; paths are joined with node:path; the documentation states it is available on macOS, Windows, Linux, and Web DSH.
Ecosystem note: DSH adopts an “everything is a plugin” extension approach; the SkillHub catalog page is a community collection and has no official affiliation with DeepSeek / Huan.
Conclusion¶
dsh-token-metrics centralizes tokens, cost estimation, and provider status for every model call on the Harness side into a single panel, supporting multi-dimensional breakdowns and local log back-scans. To install or view full configuration and FAQ, see the catalog page skillhub.cn/plugins/hugoyee75-cmyk/dsh-token-metrics and the repository github.com/hugoyee75-cmyk/dsh-token-metrics.