Introduction¶
DeepSeek Harness (DSH) adopts a plugin architecture to provide flexible extension capabilities for agent development. When using multi-model and multi-provider services, tracking token consumption and costs is a common pain point. dsh-token-ledger-pro is a plugin that integrates server-side billing with real-time client-side display, merged from the original dsh-custom-cost-meter (billing statistics panel) and dsh-spend (spend statistics). It supports Chinese and English, providing complete cost statistics, balance queries, and budget alerts.
Core Features¶
The plugin provides the following core capabilities:
- Automatic collection: Automatically collects token usage for each LLM request (based on DSH session events) and bills it in real time according to model pricing.
- Real-time display: Displays the current model, account balance, session/today/this month spending, and a budget bar in real time to the right of the input box tool row (next to the model selector). The bar color changes with thresholds: default turns orange at ≥80% and red at ≥100%.
- Balance query: Built-in official balance APIs for DeepSeek / OpenAI / Anthropic / Kimi / Zhipu / Volcano Ark (Doubao) / Alibaba Cloud (Qwen). Providers not built in can use a custom HTTP endpoint + JSONPath extraction. Default 1-minute cache (
balanceCacheTtl). - Price catalog: Built-in price catalog for 16 providers and 136 models, covering DeepSeek, Doubao/Volcano Ark, OpenAI, Anthropic, Gemini, Tongyi Qianwen, Tencent Hunyuan, Kimi, MiniMax, Zhipu GLM, SiliconFlow, xAI, Mistral, Meta Llama, Cohere, and OpenRouter.
- Smart matching: Looks up prices in the order of exact match → prefix match → provider default price fallback → cross-provider global matching.
- Unpriced handling: When a model is not in the catalog, it automatically falls back to the provider default price and displays an “Unpriced” badge, instead of silently showing ¥0.
- Special pricing: Supports DeepSeek peak/off-peak pricing (Beijing time peak hours ×2; starting 2026-08-23, off-peak pricing for whole weekend days); cache pricing (
cacheRead/cacheWrite) is billed separately. - Data persistence: Aggregates daily/this month/session data and retains the latest 2,000 detail records (atomic JSON writes; not lost after restart).
- Remote synchronization: Supports synchronizing the price catalog from a remote source via
priceSyncUrl.
Installation and Activation¶
Install using the official DSH command-line tool:
dsh plugin --profile web add dsh-token-ledger-pro
After installation, restart the DSH Web service and force refresh the page in the browser (Ctrl+F5).
Configuration¶
After the initial installation, edit the configuration file ~/.dsh/profiles/web/cordis.patch.yml. Add a balance configuration in the config block of dsh-token-ledger-pro to query balances.
Official API Configuration Example¶
The plugin automatically matches the corresponding balance configuration based on the provider of the currently selected model.
- id: dsh-token-ledger-pro
config:
monthlyBudget: 100
balance:
deepseek:
type: deepseek
apiKey: "sk-你的DeepSeek密钥"
currency: "CNY"
openai:
type: openai
apiKey: "sk-你的OpenAI密钥"
currency: "USD"
anthropic:
type: anthropic
apiKey: "sk-ant-xxx"
currency: "USD"
moonshot:
type: moonshot
apiKey: "sk-xxx"
currency: "CNY"
zhipu:
type: zhipu
apiKey: "xxx.xxx"
currency: "CNY"
hunyuan:
type: tencent
secretId: "AKID你的腾讯云SecretId"
secretKey: "你的腾讯云SecretKey"
currency: "CNY"
qwen:
type: aliyun
accessKeyId: "LTAI你的阿里云AccessKeyId"
accessKeySecret: "你的阿里云AccessKeySecret"
currency: "CNY"
balanceCacheTtl: 60
Custom HTTP Endpoint¶
For providers not built in or proxy services, you can use a custom endpoint:
- id: dsh-token-ledger-pro
config:
balance:
myproxy:
type: custom
endpoint: "https://你的中转站/api/balance"
headers:
Authorization: "Bearer sk-xxx"
valuePath: "data.balance"
currency: "CNY"
Price Override¶
Create lib/prices.override.json in the plugin directory to override local prices.
{
"deepseek": {
"default": { "input": 2, "output": 8, "cacheRead": 0.5, "cacheWrite": 2 },
"models": { "deepseek-chat": { "input": 2, "output": 8 } }
}
}
Data and API¶
The plugin persists data to a local JSON file and provides HTTP APIs for querying.
- Data file path:
~/.dsh/profiles/<profile>/data/dsh-token-ledger-pro.json - API endpoints:
GET /dsh-token-ledger-pro/summary?session=<sessionId>: session/today/this month/budget/current model pricing status.GET /dsh-token-ledger-pro/balance?provider=<provider>: account balance.GET /dsh-token-ledger-pro/prices: price catalog.GET /dsh-token-ledger-pro/config/POST /dsh-token-ledger-pro/config: read/update budget and unknown model policy.GET /dsh-token-ledger-pro/history?limit=50: recent details.
Notes¶
- Key security: Keys are stored in plaintext in the local configuration file. Do not disclose them.
- Provider support: Volcano Ark/Doubao (Volcano Ark) requires AK/SK signatures, is not built in yet, and using a custom endpoint is recommended.
- Display status: The panel displaying “balance –” indicates that it is not configured or that the request failed; displaying “Unpriced” indicates that the model is not in the catalog but has been estimated using the default price.
- Activation condition: If no cost is displayed after switching models, confirm that DSH has been restarted and that the plugin status is active in “Settings → Plugins”.
- Billing time: DeepSeek peak-hour billing is based on Beijing time (
Asia/Shanghai).
Conclusion¶
By combining server-side billing with real-time client-side display, this plugin solves the cost tracking problem in multi-model development. Its built-in price catalog and smart matching mechanism lower the configuration barrier. For more details and source code, please visit the project repository.