spoon-man569
dsh-token-price
DSH 实时 Token 花费与账户余额显示插件(每轮花费 · 总花费 · 余额)
- Stars
- 2
- Language
- TypeScript
- Created
- Aug 15, 2026
- Updated
- Aug 15, 2026
Introduction
dsh-token-price
English | 汉语
Live token cost + account balance readouts for the DeepSeek Harness Web chat UI.
What it shows
- Per-turn cost — a ¥ figure after each assistant reply's stats line
(
01:27 · 用时 · 首 token · tok/s), revealed on the same hover. - Total cost — the running session cost under the composer's stats line, summed per turn at each turn's own peak/off-peak rate.
- Account balance — your DeepSeek account balance (CNY) from
GET /user/balance.
Prices are the official DeepSeek USD rates (peak/off-peak, cache-hit aware) bundled in
src/prices.ts; the browser converts to ¥ with a live USD→CNY rate.
Install
One command (requires pnpm):
dsh plugin --profile web add dsh-token-price
The package declares dsh.bundle + dsh.client, so this installs and activates both halves in
one step: the host half (balance service + tokenCost projection) and the browser half (the readouts).
Configuration
- id: token-price
name: dsh-token-price
config:
balanceBaseURL: https://api.deepseek.com
balanceApiKeyEnv: DEEPSEEK_API_KEY
balanceRefreshIntervalMs: 60000
requestTimeoutMs: 5000
balanceApiKeyEnv names the credential holding your DeepSeek API key (the same one the
dsh-llm-deepseek adapter uses). The balance reads "未获取" until the key is set; failures are
logged with ctx.logger.
Pricing
Per-model prices (src/prices.ts / prices.json) mirror the official page
(Models & Pricing):
- schema v2, USD per 1M tokens, with
peak/offPeakperiods; - peak windows in Beijing time: 09:00–12:00 and 14:00–18:00 (off-peak is half price);
- each period prices cache-hit input, cache-miss input, and output separately.
The USD→CNY rate is fetched live in the browser (open.er-api.com, then frankfurter.app — both free
and CORS-enabled), cached in localStorage for 6 hours, with a bundled fallback constant.
How it works
- The host registers a
tokenCostsession projection that folds per-turn disjoint token usage (uncached / cache-read / cache-write / output) from the durable session log, so per-turn cost stays exact across model switches and compaction. - The browser bills each turn at its own time's peak/off-peak price, converts with the live rate, and renders ¥.
- The balance is fetched host-side (the key never reaches the browser) and rides the projection.
Development
npm install
npm run build # esbuild bundles + tsc declarations -> lib/
After changing source, rebuild and restart the DSH web process (the profile links this package and
loads the lib/ artifacts).
License
MIT