Introduction¶
DeepSeek Harness (DSH) adopts an “everything is a plugin” architecture. For developers using the DeepSeek API, it is necessary to keep real-time track of API call costs and account balance. The moyunlee/deepseek-ai-dsh-api-cost plugin is mounted on the DeepSeek Harness Web profile and provides real-time cost monitoring.
The plugin connects directly to the official balance API and does not rely on third-party services. It provides not only balance display, but also consumption statistics, trend analysis, and reconciliation features. After installation, developers can intuitively see the cost and Token consumption generated by each conversation in the Web interface.
Features¶
The plugin includes the following main features:
- Real-time balance: connects directly to the official
get-user-balanceendpoint; the API Key does not leave the server. - Consumption statistics: supports current conversation, daily, monthly, and overall consumption statistics, splitting Token and amount by model.
- 7-day trend: displays the consumption trends of V4 Pro / V4 Flash dual models, with switching between amount and Token.
- CSV reconciliation: imports the official
amount-*.csvexported from the DeepSeek platform, recalculates local amounts using official unit prices, then compares them. - Price calibration: automatically extracts unit prices from the official CSV and writes them into the local price table.
- Budget alerts: sets a monthly limit and can configure webhook push notifications when exceeded.
- One-click recharge: direct access to the DeepSeek usage page from the panel.
- Light/dark theme: follows the system automatically and supports manually locking day or night mode.
- No data loss: each call is persisted as a JSONL ledger, and after restart, historical amounts are recalculated using the current price table.
Installation and Activation¶
The installation command is as follows. It activates automatically after installation, without modifying configuration files.
pnpm dsh plugin --profile web add ./deepseek-ai-dsh-api-cost-0.1.0.tgz
After installation, start the Web service:
pnpm dsh web
Configuration¶
The configuration file is located at $DSH_HOME/profiles/web/cordis.patch.yml. This file is merged with the built-in defaults; only write the fields that need to be overridden.
- id: api-cost
config:
# 模型价格配置(¥/百万 token)
prices:
my-model:
input: 3.0
cacheRead: 0.1
cacheWrite: 3.0
output: 9.0
# 峰谷计费(默认关闭;北京时间高峰 9:00–12:00、14:00–18:00,谷时段半价)
peak:
enabled: true
peakHours: [[9, 12], [14, 18]]
peakMultiplier: 1.0
offpeakMultiplier: 0.5
# 月度预算告警
budget:
monthlyLimit: 50
webhookUrl: 'https://example.com/hook'
# 余额校准
calibration:
enabled: true
initialBalance: 100
deviationThreshold: 0.05
The plugin includes a built-in default price table for deepseek-v4-flash and deepseek-v4-pro. If official pricing changes, you can automatically calibrate using the CSV during reconciliation.
Usage¶
- View balance: Open
http://127.0.0.1:3080. The bottom-left corner displays a “Balance / Spend” badge. - View details: Hover over the badge to view full details, including balance, costs for the current conversation, today, and this month, Token details, 7-day trend, etc.
- Jump to settings: Click the badge to directly open the “Usage and Consumption” dashboard on the settings page.
- CSV reconciliation: On the settings page, click “Verify official CSV” and select the officially exported
amount-*.csvfile. The local amount is first recalculated using the official unit prices in the CSV, then compared with the official amount. - Export and reset: Supports one-click export of the local ledger CSV. The reset function clears all cumulative records (confirmation required).
Notes¶
- Statistics scope: The plugin only counts calls made after it is enabled; historical sessions are not retroactively included. Existing ledger amounts are recalculated according to the current price table.
- Unconfigured models: Models not configured in
pricesare billed at 0 yuan, while Token usage is still accumulated. - Balance cache: The balance endpoint is cached once per minute to reduce request frequency.
- Security: The API Key is resolved through the credential service and does not enter the browser. Reset/calibration endpoints require the custom header
x-dsh-api-cost: confirmto prevent CSRF. - Time zone: Peak/off-peak billing is determined based on Beijing time (UTC+8) and does not depend on the local time zone.
- Compatibility: Clicking the badge to jump to the settings page is implemented by triggering the settings panel DOM. If Harness later changes the panel structure, this jump may fail, but the settings page itself remains accessible.
Conclusion¶
The plugin provides DSH users with a complete workflow from balance monitoring to bill reconciliation, helping developers control costs. The plugin source code is hosted on GitHub and follows the MIT license.