hj01857655/dsh-plugins--packages-dsh-cost-track ↗★ 0
dsh-cost-track
追踪Token消耗并为Agent的每次模型调用强制执行预算 适合需要严格监控和限制API调用成本、防止Token超支的用户。
同名包的其他仓库
安装
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:hj01857655/dsh-plugins#5a7f8533f4dcd4f85ec3ebd7e9fa0a071445bf65&path:packages/dsh-cost-track说明文档
阅读完整 README ↗dsh-cost-track
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):
| Model | Prompt | Completion |
|---|---|---|
| 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
| Path | Role |
|---|---|
src/index.ts | Host half — apply(ctx), exposes the costTrack service |
src/cost.ts | Core cost tracker — record, query, aggregate |
src/pricing.ts | Built-in price table + custom pricing loader |
src/budget.ts | Budget checking and enforcement logic |
src/store.ts | Append-only .cost/ledger.jsonl |
src/cost-view.ts | Payload → view model, shared by host route and browser half |
src/cli.ts / src/bin.ts | Command-line entry, usable without dsh |
src/routes.ts | Panel route on the host's web connection |
src/client/view.tsx | Browser half — pure rendering |
src/client/index.tsx | Browser half — fetch and settings registration |
src/client/locales.ts | zh / en dictionaries |
Develop
npm ci
npm run typecheck
npm run build
npm test
License
MIT