Vai al contenuto principale
L

dsh-spend-meter

linhuantanly/dsh-spend-meter

Per-turn DeepSeek spend, live official pricing, and current balance for DeepSeek Harness Web.

Installazione

dsh plugin --profile web add github:linhuantanly/dsh-spend-meter

README

dsh-spend-meter

简体中文

A spend monitor for DeepSeek Harness Web. It shows the cost of every root turn—including main-agent steps, subagents, compaction, session-title generation, and other DeepSeek calls—and keeps the current balance, session total, and pricing freshness visible under the composer.

Turn ¥0.0231 · 5 calls ▾

Balance ≈¥96.38 · Session ¥1.27 · Price updated just now

How it differs from dsh-turn-cost

dsh-turn-cost is a good lightweight option with bundled CNY prices, no network, and no credential access. dsh-spend-meter serves a different contract: it refreshes official pricing, reads the official balance, freezes an auditable price claim per request, and includes auxiliary and descendant model calls.

Do not install both plugins: their per-turn UI overlaps.

Features

  • Root-turn attribution across main steps, child agents, compaction, title generation, and other DSH model calls.
  • Exact provider usage buckets from DSH rc.7; reasoning is already part of output and is not charged twice.
  • Official CNY/USD price refresh on startup and every 30 minutes, plus manual refresh.
  • Official /user/balance refresh at startup, after root turns, and every 60 seconds while the page is visible.
  • Request-time peak/off-peak selection and immutable historical price claims.
  • Explicit fallback estimates and unknown-cost states when provider usage is absent.
  • Integer pico-unit accounting (1e-12 currency unit), so totals never accumulate floating-point or per-turn rounding error.
  • Safe sidecar persistence at ~/.dsh/storages/dsh_spend_meter.json; no third-party events are written into DSH session logs.

Formula

call cost =
  cache-read tokens × cache-hit rate
  + (uncached-input tokens + cache-write tokens) × cache-miss rate
  + output tokens × output rate

The request start time selects the price tier. Currency follows the first official currency returned by /user/balance: CNY uses the CNY price page and USD uses the USD price page. The plugin never performs FX conversion or adds unlike currencies.

Install

Install from npm:

dsh plugin --profile web add dsh-spend-meter
dsh web

You can also install an absolute path to a local tarball or checkout:

dsh plugin --profile web add /absolute/path/to/dsh-spend-meter-0.1.0.tgz
dsh web

Requires @deepseek-ai/dsh >= 0.1.0-rc.7 < 0.2.0.

Uninstall

dsh plugin --profile web remove dsh-spend-meter

Uninstalling cannot damage a session. To remove the optional sidecar data, stop DSH and delete ~/.dsh/storages/dsh_spend_meter.json manually.

Network and privacy

The Host contacts only these fixed official endpoints:

  • https://api-docs.deepseek.com/zh-cn/quick_start/pricing/
  • https://api-docs.deepseek.com/quick_start/pricing/
  • https://api.deepseek.com/user/balance

The API key is resolved per balance operation through DSH credentials and remains in the Host Authorization header. It never reaches the browser, logs, or sidecar storage. Prompts, responses, tool arguments, and provider response bodies are never persisted.

Only the latest official balance snapshot is cached. The per-session sidecar stores request classification, model, usage, timestamps, price claim, accuracy, and amount.

Failure semantics

  • Pricing unavailable or structurally changed: retain the last valid live snapshot; otherwise use the bundled 2026-08-19 snapshot and show stale pricing.
  • Balance unavailable: retain and mark the last official snapshot stale.
  • Missing usage with observed output: estimate and mark ; otherwise record unknown rather than zero.
  • Storage failure: never block the model stream; the call may be absent from the ledger and one redacted warning is logged.
  • The plugin never blocks, cancels, or mutates model requests.

Development

npm install --ignore-scripts --legacy-peer-deps
npm test
npm run verify

Tests use sanitized fixtures and mock streams and make no paid model calls. See docs/architecture.md.

License

MIT. See NOTICE for acknowledgements.

Plugin correlati