DamonKoy/dsh-plugins--packages-dsh-usage-cost0

dsh-usage-cost

DeepSeek Harness 用量与成本统计插件:统计流式调用的 Token 用量与预估美元成本,记录每日统计并在超支时预警。

AI 分析

核心用途是监控和控制大模型 API 的使用成本。适合需要实时统计 Token 消耗、估算费用并在超出预算时获得警告的 DSH 用户。

包名
dsh-usage-cost
版本
0.1.0
最近更新
2026年8月15日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:DamonKoy/dsh-plugins#fd97e01fb1c26454f27310dd42a6f8d7b66e8e29&path:packages/dsh-usage-cost

dsh-usage-cost

Usage and cost tracking plugin for DeepSeek Harness, inspired by Codex 0.144's "usage limit" credits reminder: watch every model call and keep a running token/cost tally, with warnings before the budget runs out.

English | 中文

What it does

  • Stream-level usage accounting: hooks the llm/stream waterfall and accumulates inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens from every usage chunk without buffering or altering the stream; one call counts once.
  • Per-model cost estimation: prices each call in USD from a built-in table (DeepSeek: $0.28/M in, $0.42/M out, $0.028/M cache read, $0.42/M cache write; others: $2/M in, $8/M out), overridable per provider/model key in the config.
  • Per-turn settlement: on agent/turn-stopping, usage accumulated since the last settlement is appended (deltas only) to ~/.dsh/dsh-usage-cost/stats.json, bucketed by date and by model.
  • Budget warnings: with dailyBudgetUsd / sessionBudgetUsd set, crossing the threshold logs once per date and once per session: [dsh-usage-cost] 今日用量超预算 / 本次会话用量超预算.
  • usage_report model tool: read-only report of today, the current session, the per-model breakdown and the budget state (dailyExceeded / sessionExceeded flags).
  • Package-private RPC: usage-cost/status returns the same report.

Install

dsh plugin --profile web add link:~/dsh-plugins/packages/dsh-usage-cost

Restart dsh web. Active by default, records usage with no config.

Config

Optional file ~/.dsh/dsh-usage-cost.json:

{
  "prices": {
    "deepseek-official/deepseek-v4-flash": {
      "inputPerM": 0.28,
      "outputPerM": 0.42,
      "cacheReadPerM": 0.028,
      "cacheWritePerM": 0.42
    }
  },
  "dailyBudgetUsd": 2,
  "sessionBudgetUsd": 0.5
}
FieldDefaultMeaning
prices{}Per-model overrides in USD per 1M tokens, keyed by provider/model
dailyBudgetUsdunsetWarn when today's cost exceeds this
sessionBudgetUsdunsetWarn when this process's cost exceeds this

Config is re-read on every use, so edits apply without a restart.

Stats file

Written synchronously at every turn settlement (small file, no races); costs are estimates from the price table, not provider invoices:

{
  "byDate": {
    "2026-08-16": { "calls": 3, "inputTokens": 1200, "outputTokens": 800, "costUsd": 0.00068 }
  },
  "byModel": {
    "deepseek-official/deepseek-v4-flash": { "calls": 3, "inputTokens": 1200, "outputTokens": 800, "costUsd": 0.00068 }
  }
}

Notes

  • Session tally is in-memory for the process lifetime; the daily file is the durable record.
  • The llm/stream listener calls next() first and only reads chunk fields; stream, options and chunks are never modified.
  • Warnings fire once per date and once per session to avoid log spam.
  • Prices and budgets are user-side estimates; adjust them to your billing.

License

MIT