Introduction¶
When using models in DSH Web, calls may come from different providers, models, and sessions. It is difficult to judge monthly usage, cache hits, cost estimation, and latency changes by looking at a single answer alone. dsh-token-stats is a plugin for DeepSeek Harness / DSH Web that records the real usage of llm/stream calls into a ledger and provides global statistics on the interface. Below is an introduction to its features, installation commands, and common entry points.
What is it¶
dsh-token-stats is a global Token usage statistics plugin. The info page shows the owner as 1148281964 and the license as MIT; GitHub and community directory links are at the end. Since the repository field in package.json in the info is a placeholder, this article does not treat the owner field as a fully confirmed maintainer attribution. It is mainly used to centrally display token usage in DSH Web: recording real usage, aggregating by provider, model, session, and date dimensions, estimating costs, and providing metrics like cache hit rate, success rate, average duration, and Time to First Token (TTFT).
Core Features¶
Real usage and Ledger¶
- Collect real
usagefromllm/streamcalls: input, output, cache read, cache write, and inference tokens. - Build a persistent JSONL ledger that survives restarts; rebuilds from the ledger during startup/hot reload.
- The default ledger directory is
<profile>/data/token-stats/, which can be overridden byDSH_TOKEN_STATS_DIR. - Statistical metrics are based on real usage; Input = Uncached + Cache Read + Cache Write. This differs from the estimation metrics of DSH’s built-in token-meter.
Aggregation and Metrics¶
- Aggregate by provider, model, session, and date, supporting monthly and the last 31 days trends.
- Calculate cache hit rate, success rate, average duration, and Time to First Token (TTFT).
- Session dimension distribution is based on aggregation of the last 500 retained entries, while the total
totalsis from the full ledger.
Cost Estimation¶
- Provide cost estimation.
- Pull the latest model prices from OpenRouter and recalculate historical costs.
- The price JSON can be overridden using
DSH_TOKEN_STATS_PRICES. - Costs are estimates; actual settlement is based on the gateway/vendor bill.
Interface Display¶
- A draggable FAB (Floating Action Button) in the bottom right corner; click to expand the panel, supporting “Global | Current Session” switching.
- Click the full-screen entry in the top right corner of the panel to open a centered full-screen popup.
- The full-screen popup displays KPIs, donut charts, trends, provider/model tables, and recent call details.
- Current session tracking relies on DOM probing and title matching to select the session row and match the title; it falls back to the most recent active session if the session list is invisible or the title is ambiguous.
Model Tools and HTTP API¶
- Provide a model tool
token_statsthat supports an optionalsessionIdparameter. - Provide the following HTTP endpoints:
GET /token-stats/api/query
GET /token-stats/api/sessions
POST /token-stats/api/refresh-prices
All endpoints verify Origin (local only), and HEAD requests do not return a body.
Historical Backfill¶
- Provide the
backfill-history.mjsscript, which can be used to idempotently backfill calls made before plugin installation. - Only backfills successful calls that include usage; duration and TTFT cannot be backfilled.
- Costs are recalculated based on the current price list.
- Automatically backs up the ledger before importing.
Installation and Activation¶
The plugin targets the DSH Web profile. The CLI installation command provided in the info is:
dsh plugin --profile web add dsh-token-stats
The info shows that peerDependencies requires @deepseek-ai/cordis ^4.0.1. This package is pure JavaScript with no prepare build script; the info also states that github: installation does not require an allowedBuilds configuration. It is recommended to check the source code and MIT license before installation. The plugin runs with the permissions of the current dsh process, so only enable it in DSH instances where you trust the code.
Typical Usage¶
Browser Panel¶
- Click the FAB in the bottom right corner to expand the panel, which can be dragged to a new position.
- Switch the statistical scope to “Global | Current Session” within the panel.
- Click the full-screen entry in the top right corner of the panel to open a centered full-screen popup.
- View KPIs, donut charts, trends, provider/model tables, and recent call details in the full-screen popup.
Settings Page¶
Go to “Settings -> Token Statistics” to open the same panel and full-screen popup as the FAB.
Update Prices¶
In the full-screen popup, click the “Update Prices” entry to pull the latest model prices from OpenRouter and recalculate historical costs.
Model Tool¶
Call the model tool token_stats in a conversation to let the model directly query statistical results. Optional parameters can be passed:
{"sessionId": "..."}
HTTP API¶
The following endpoints can be called:
GET /token-stats/api/query
GET /token-stats/api/sessions
POST /token-stats/api/refresh-prices
These endpoints verify Origin (local only), and HEAD requests do not return a body.
Historical Backfill¶
Calls made before plugin installation can be backfilled using the script:
node backfill-history.mjs
node backfill-history.mjs --dry-run
node backfill-history.mjs --force
The script is for idempotent backfilling of calls before plugin installation; it automatically backs up the ledger before importing.
Use Cases and Notes¶
Suitable for the following scenarios:
- Need to view global token usage and trends in DSH Web.
- Need to compare usage by provider, model, session, and date.
- Need to estimate costs, observe cache hit rate, success rate, average duration, and TTFT.
- Need to let models query statistical results via
token_stats.
Notes:
- Costs are estimates and do not equal the final bill; refer to the gateway/vendor bill.
- Statistical metrics are based on real usage, which differs from the estimation metrics of DSH’s built-in token-meter.
- Current session tracking relies on DOM probing and title matching; it falls back to the most recent active session on failure.
- Session dimension distribution is based on aggregation of the last 500 retained entries, while the total
totalsis from the full ledger. - Historical backfill cannot recover duration and TTFT, and costs are recalculated based on the current price list.
- The DSH community directory is an independent site and has no official affiliation with DeepSeek / Quant.
References¶
- Community Directory: https://www.skillhub.cn/plugins/1148281964/dsh-token-stats
- GitHub: https://github.com/1148281964/dsh-token-stats