Introduction¶
When running a session using the DSH (DeepSeek Harness) Web client, the built-in statistics row below the input box only displays turns, duration, and token count. The actual cost of this round is unknown until you check the official platform; the account balance is often overlooked and only noticed when a request fails due to insufficient funds.
@kidli1412/dsh-session-cost solves these two problems: it integrates the current session’s token cost estimation (CNY pricing per model) and the DeepSeek API balance into the built-in statistics row. Below is an introduction to its implementation, installation, and configuration.
What is this¶
@kidli1412/dsh-session-cost is a community plugin maintained by KIDLi1412 for the DSH Web client (manifest client.platform: web), under the MIT license, current version 0.1.9. It belongs to the “everything is a plugin” ecosystem of DSH.
The plugin is split into two sides:
- Server-side:
GET /api/session-cost/summary?session=<id>incrementally aggregates session events and prices by model;GET /api/session-cost/balancequeries the DeepSeek balance; also registers thesession-costsettings namespace for the config card to read/write. - Browser-side: Registers the
conversation.composer.dockslot, appends the cost/balance segment to the DOM of the built-in statistics row, and registers a plugin configuration card in the settings page.
Core Features¶
Session Cost Estimation¶
Costs are calculated per model on the server side: first, each model’s input/output/cache hit tokens are aggregated from the session event logs (semantically consistent with the tokenUsage projection of dsh-token-meter), then calculated using the CNY unit price table in lib/cost.js. When a session mixes multiple models, each model is priced separately; no rough average is taken.
The cost refreshes every 30 seconds, and also automatically triggers a refresh when token usage changes. Hovering allows viewing the detailed breakdown per model; when crossing multiple pricing periods, it displays the fee split for peak/off-peak/legacy pricing.
DeepSeek Balance Query¶
The balance reuses the official interface GET {baseURL}/user/balance, with credentials parsed via DSH’s credentials. The query includes a 2-minute memory cache and single-flight debounce, refreshing every 5 minutes; ?refresh=1 can force bypassing the cache. Hovering displays the balance composition (top-up/gifted).
Display and Interaction¶
The cost/balance segment is appended to the same row as the built-in statistics row. Since DSH rc.7, the built-in statistics row has a width limit of 748px with truncation by ellipsis, so the appended segment would be clipped; the plugin automatically widens the statistics row to full container width and removes clipping, with the same effect as zh_pro’s “Show all statistics,” but without depending on it.
The ⟳ button manually refreshes, forcing an upstream query, and briefly displays “Updated HH:MM” upon success. The hover tooltip looks roughly like this:
本会话费用估算: ¥0.1234
deepseek-v4-flash · 输入 12,345 tokens · 输出 1,234 tokens · ¥0.0152
余额: ¥36.44
充值余额: ¥30.00
赠送余额: ¥6.44
更新于 10:32
费用为估算值:token 用量来自会话日志,单价见官方定价页(…)。
Pricing and Estimation¶
The default unit price table is taken from the Chinese version of the official pricing page (effective from 2026-08-17), unit is CNY / million tokens:
| 模型 | 输入(缓存未命中)空闲 / 高峰 | 输入(缓存命中)空闲 / 高峰 | 输出 空闲 / 高峰 |
|---|---|---|---|
| deepseek-v4-flash | ¥1.5 / ¥3.0 | ¥0.05 / ¥0.10 | ¥4.5 / ¥9.0 |
| deepseek-v4-flash-vision-exp | ¥1.5 / ¥3.0 | ¥0.05 / ¥0.10 | ¥4.5 / ¥9.0 |
| deepseek-v4-pro | ¥4.5 / ¥9.0 | ¥0.15 / ¥0.30 | ¥13.5 / ¥27.0 |
| deepseek-chat(V3 遗留,默认) | ¥2(平峰) | ¥0.5 | ¥3 |
| deepseek-reasoner(V3 遗留,默认) | ¥4(平峰) | ¥1 | ¥16 |
V4 models implement peak-valley pricing: peak hours are Beijing Time 9:00–12:00 and 14:00–18:00 on weekdays, peak price is twice the off-peak price; from 2026-08-23 00:00, weekends are charged at off-peak prices throughout the day. The plugin prices each usage sample based on the time slot it belongs to; samples before 2026-08-17 00:00 are charged at the old flat rate (LEGACY_PRICING).
Two points worth noting:
- cacheWrite has no equivalent in DeepSeek (context cache auto-hits are billed), defaulting to the cache miss input price (per time slot) to avoid underestimation.
- V3 legacy models are not listed on the official page; keeping the last known flat rate.
After price changes, you can update DEFAULT_PRICING in lib/cost.js, or override it via the plugin config pricing, supporting flat rate or time-slot format:
# ~/.dsh/settings.yaml or profile plugin config
session-cost:
pricing:
deepseek-v4-flash:
input: 1
cacheRead: 0.02
cacheWrite: 1
output: 2
# or time-slot (offpeak/peak each override, omitted fields inherit default):
# deepseek-v4-pro:
# offpeak: { input: 4.5, output: 13.5 }
# peak: { input: 9, output: 27 }
Installation and Enablement¶
Install from npm:
dsh plugin --profile web add @kidli1412/dsh-session-cost
Install from GitHub:
dsh plugin --profile web add github:KIDLi1412/dsh-session-cost
Install via link for local development, changes take effect immediately:
dsh plugin --profile web add link:path/to/dsh-session-cost
After installation, restart dsh web and do a browser hard refresh (Ctrl+Shift+R). After the above steps, open any session, and you can see the cost and balance at the end of the built-in statistics row. To remove:
dsh plugin --profile web remove @kidli1412/dsh-session-cost
Settings¶
Settings entry: Settings → Plugins → Plugin Config → Session Cost Display.
- Low balance threshold: Default 10 CNY. Below this value it shows red, at or above it shows black. Configuration is persisted to
~/.dsh/settings.yamlvia thesession-costsettings namespace and takes effect immediately. - LocalStorage configuration for versions 0.1.1 and earlier will be automatically migrated on first load.
- Starting from 0.1.5, the “Independent status bar” display mode (a separate line below the stats bar) was removed, keeping only the merged stats bar. The
displayModekey in old configs will be ignored.
Compatibility and Security¶
Compatibility:
- The manifest declares 0.1.2-alpha.4, 0.1.2-alpha.5, 0.1.2-rc.1 as compatible via dsh.compatibility.dshReleases.
- Node requires ^22.19.0 || >=24.0.0 (consistent with DSH); the host requirement shown by dsh-market is engines.dsh: ^0.1.2-rc.1.
- Version 0.1.8 adapted to DSH 0.1.2: starting from rc.1, live sessions no longer carry the .events array; the plugin changed to read session.seq and read session.eventAt(seq) item by item, consistent with the official dsh-token-meter.
Security:
- Both endpoints are loopback-only precise routes (peer socket address + Host double-check), called from the browser same-origin.
- API Key is not written to disk: requested via credentials parsing the apiKeyEnv of the llm-deepseek namespace (default DEEPSEEK_API_KEY).
- Balance cache is stored only in memory with a TTL of 2 minutes.
Applicable Scenarios and Notes¶
Suitable for individuals and AI agent developers who use the DSH Web client to connect directly to the DeepSeek API and want to keep track of session costs and account balance at any time.
Pay attention to two points before use:
1. The cost is an estimate. Token usage comes from usage samples reported by the provider in the session logs, and the unit price table is a hard-coded default value. After official price adjustments, you need to update DEFAULT_PRICING or use the pricing config to override.
2. The plugin runs with the permissions of the current dsh process, capable of reading session logs and using the host’s credentials seam. Before installing any third-party plugin, it is recommended to check the source code and license; this plugin is MIT.
Overall, this plugin puts “how much spent and how much left” in a position visible in every session, with a configuration cost of just one installation command. Source code and documentation can be found on GitHub: https://github.com/KIDLi1412/dsh-session-cost