Introduction¶
DeepSeek Harness (DSH) adopts a plugin-based architecture, modularizing functionality to adapt to different use cases. When deploying locally or interacting through DSH, tracking token consumption, estimating costs, and managing balances across multiple platforms are basic and frequent requirements. Existing approaches are often fragmented across different channels and lack a unified view. This plugin aims to aggregate this data and provide a visualized dashboard with real-time readouts.
Plugin Overview¶
nigel211/dsh-token-usage is a token usage and cost accounting plugin for DSH. It does not rely on third-party services; all data is derived entirely from DSH’s persisted session logs. After installation and restarting the service, the plugin automatically backfills historical data, supports aggregation by model, session, and time range, and provides cost estimation and multi-platform balance lookup capabilities.
Core Features¶
Usage Statistics¶
The plugin extracts data from DSH logs and supports statistics for input tokens, output tokens, and cached-hit tokens. Users can view aggregated results by model, by session, or by time range (today, last 7 days, last 14 days, last 30 days).
Cost Estimation¶
It includes the official DeepSeek CNY price list. The pricing logic is segmented by effective date:
- Old price before 8-17: uniformly estimated using the old price.
- Peak/off-peak pricing starting from 8-17: billed by time segment based on Beijing time. 9:00–12:00 and 14:00–18:00 are peak hours, while all other hours are off-peak (half price).
The price list supports adding, deleting, and modifying entries, with persistence. For unknown models, users can manually add prices, and the system will calculate costs immediately based on them.
Account Balances¶
It supports automatic enumeration of configured model routes (such as DeepSeek official, pi-ai, etc.). Template-based queries support platforms such as DeepSeek, OpenRouter, SiliconFlow, and New-API. Balance lookups include a 60-second cache, support a keep-last-good strategy, and classify transient/deterministic errors. The DeepSeek official row in the interface includes a “Recharge” button that can directly redirect to the open platform.
Charts and Interface¶
- Charts: Includes trend charts (a single chart with four curves + dual-axis cost), a current-month calendar activity heatmap (blue intensity represents token volume), and a model proportion donut chart (with hover interaction support).
- Dashboard: Located in the “Token Usage” section on the settings page, it displays cost hero metrics, account balance cards, usage trends, activity heatmap, and more.
- Persistent readout: Below the conversational input box, it persistently displays current-session tokens/cost and today’s cost.
Installation and Activation¶
This plugin is only published on GitHub. There is a conflicting package with the same name in the npm registry. Do not install it using the bare package name.
Install using the GitHub syntax:
dsh plugin --profile web add github:Nigel211/dsh-token-usage
(If a specific version is required, you can append #v0.1.15.)
After installation, you must restart the dsh web service for the plugin features to take effect.
Typical Usage¶
- View usage: After restarting the service, go to Settings → Token Usage. The dashboard will automatically load data for the current range.
- Adjust prices: If you are using non-official models, you can manually add prices in the Price List section of the dashboard. Cost calculations will update immediately.
- Query balances: When the settings page is opened, the plugin automatically queries balances for each route. You can click the recharge button on the DeepSeek official row.
- View trends: In the Usage Trends chart, switch the time range (for example, last 7 days) and observe the change curves for input/output/cached-hit tokens and costs.
Notes¶
- Historical data backfill: Historical backfill only counts
assistant/messageentries that include theusagefield. Entries where usage was not reported are not counted. - API key security: During balance lookups, API keys are resolved through the DSH credential service, sent only to the corresponding platform APIs, and never written to logs.
- Price limitations: Historical price adjustments before 8-17 are not segmented and are uniformly estimated using the old price.
- Permission requirements: Balance lookups depend on
curl(built into Windows 10+) or PowerShell. Ensure network reachability to the corresponding platform APIs.
Conclusion¶
By reusing DSH log data, this plugin creates a closed loop from usage statistics to cost estimation and then to balance management. For users who need to control costs precisely or manage API keys across multiple platforms, it provides a concise, modern centralized view. The related code and project structure can be viewed in the GitHub repository.