hj01857655/dsh-plugins--packages-dsh-cost-track ↗★ 0

dsh-cost-track

Track token spend and enforce budgets for every model call your dsh agent makes. 适合需要严格监控和限制API调用成本、防止Token超支的用户。

パッケージ
dsh-cost-track
互換性
未検証
Cordis ピア範囲
~4.0.4
バージョン
0.6.1
ライセンス
MIT
最終更新
2026/10/16

同名パッケージの別リポジトリ

インストール

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:hj01857655/dsh-plugins#5a7f8533f4dcd4f85ec3ebd7e9fa0a071445bf65&path:packages/dsh-cost-track

ドキュメント

README 全文を読む ↗

dsh-cost-track

npm version npm downloads CI license node GitHub stars dsh plugin

Track token spend and enforce budgets for every model call your dsh agent makes.

Install

dsh plugin --profile web add dsh-cost-track

Or from source:

dsh plugin --profile web add github:hj01857655/dsh-cost-track

What it does

  • Records every model call. Prompt tokens, completion tokens, and the model id are priced and appended to .cost/ledger.jsonl (append-only).
  • Prices calls. A built-in table covers DeepSeek's models. Override with your own rates for custom models.
  • Budgets. Set a monthly spend limit. When cumulative spend crosses the threshold, the plugin warns. With enforce: true, subsequent model calls are blocked.
  • Time-range queries. Filter spending by today, this week, this month, or an arbitrary date range.
  • Per-session breakdown. See which conversation burned the most tokens.
  • Panel. A settings page shows today's spend, this month's spend, per-model breakdown, recent sessions, and the budget bar.

CLI

dsh-cost-track summary                          # show spend summary
dsh-cost-track budget --monthly 50 --enforce    # set $50/month budget with enforcement
dsh-cost-track record --model deepseek-chat --prompt-tokens 1000 --completion-tokens 500 --session s1

Pricing

Default rates (per million tokens, USD):

ModelPromptCompletion
deepseek-chat$0.14$0.28
deepseek-reasoner$0.55$2.19

Override by writing .cost/pricing.json:

{
  "my-model": { "promptPerMillion": 1.0, "completionPerMillion": 2.0 }
}

Panel

A Cost page inside Settings. The host registers GET /api/cost-track.panel and rebuilds the payload from the ledger on every request, so the panel always reflects what is on disk. A headless host has no web connection and simply skips the route.

The panel shows:

  • Today / this month spend with a progress bar against the budget
  • Per-model token and cost breakdown
  • Recent sessions ranked by cost
  • Budget status (OK / warning / exceeded) with the enforcement toggle

Layout

PathRole
src/index.tsHost half — apply(ctx), exposes the costTrack service
src/cost.tsCore cost tracker — record, query, aggregate
src/pricing.tsBuilt-in price table + custom pricing loader
src/budget.tsBudget checking and enforcement logic
src/store.tsAppend-only .cost/ledger.jsonl
src/cost-view.tsPayload → view model, shared by host route and browser half
src/cli.ts / src/bin.tsCommand-line entry, usable without dsh
src/routes.tsPanel route on the host's web connection
src/client/view.tsxBrowser half — pure rendering
src/client/index.tsxBrowser half — fetch and settings registration
src/client/locales.tszh / en dictionaries

Develop

npm ci
npm run typecheck
npm run build
npm test

License

MIT