跳到正文

dongsheng123132/dsh-cost

30最近提交 2026年8月14日

dsh-cost DSH 插件

dsh-cost 是一款 DSH 插件,基于持久化会话日志计算会话费用。它将每条使用记录归因到对应的 provider/model 路由,应用用户自定义的价格表,并明确保留缺失用量和缺失价格的情况。提供两个工具(dsh_cost_report 和 dsh_cost_check)以及一个内置的 stdio MCP 服务器用于费用查询。

如何安装 dsh-cost DSH 插件

dsh plugin --profile <name> add github:dongsheng123132/dsh-cost

来源命令需要人工核对。复制不会执行命令。

dsh-cost DSH 插件数据来源

dsh-cost DSH 插件快照日期:2026年8月16日

discovered

dsh-cost DSH 插件能做什么

  • 基于 DSH 日志中的持久化 assistant/message.usage 记录计算会话费用
  • 将每条用量记录归因到对应的 provider/model 路由
  • 应用用户自定义的价格表(prices.json),支持输入、输出、缓存读取和缓存写入四个独立桶的每百万 token 定价
  • 提供两个插件工具:dsh_cost_report(费用报告、路由分解、证据完整性、预算状态和 tokenMeter 压力快照)和 dsh_cost_check(开放/关闭失败模式的预算决策)
  • 内置 stdio MCP 服务器,暴露 cost_report 和 cost_check 端点,仅接受受限且消毒过的输入
  • 支持离线账本模式:dsh-cost --events session-events.json --prices prices.json --budget --fail-closed
  • 通过真实的 Cordis Loader 保留工具和 tokenMeter 注入(命名空间插件,无默认导出)

dsh-cost DSH 插件适合哪些场景

  • 在 DSH 会话中追踪多个 provider/model 路由的 token 费用
  • 设置预算限制并选择失败时开放或关闭的策略
  • 生成包含路由分解和证据完整性统计的费用报告
  • 使用 MCP 服务器从外部工具查询费用,无需暴露消息体或凭据
  • 对导出的 DSH 会话事件文件进行离线费用审计

dsh-cost DSH 插件适合谁

  • 需要监控和控制跨 provider token 支出的 DSH 用户
  • 希望使用自定义价格表按项目或客户归集费用的开发者

dsh-cost DSH 插件的限制

  • 费用仅基于持久化的 assistant/message.usage 记录计算;没有 provider 用量的调用会记为 missingUsageCalls
  • 价格表中缺失的路由会记为 unpricedCalls;只要存在缺失或未定价的调用,低于预算的结果就显示为 'unknown'
  • 未内置任何供应商价格,用户必须自行提供 prices.json 文件
  • 需要 Node.js 22+(由徽章标明)
  • MCP 服务器拒绝提示词、消息体、凭证和其他额外字段,仅接受受限且消毒过的用量行

dsh-cost DSH 插件的仓库 README 摘录

以下文字摘自 dsh-cost DSH 插件的上游仓库 dongsheng123132/dsh-cost 的 README,版权归原作者,仅作引用。

Evidence-first token cost ledger and budget checks for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness). `dsh-cost` folds the durable DSH session log. It attributes each committed `assistant/message.usage` record to the active `request/header` provider/model route, then applies a user-owned price book. Missing usage and missing prices remain explicit: partial evidence never becomes a reassuring fake total. ## Install ```bash dsh plugin --profile <name> add github:dongsheng123132/dsh-cost ``` The bundle mounts two tools: - `dsh_cost_report` — durable session cost, route breakdown, evidence completeness, optional budget status, and the current `ctx.tokenMeter` pressure snapshot. - `dsh_cost_check` — explicit fail-open/fail-closed budget decision. It does not claim to intercept future calls automatically. The same evidence core is available through the bundled stdio MCP server as `cost_report` and `cost_check`. MCP accepts only bounded, sanitized usage rows (`provider`, `model`, disjoint token buckets, or an explicit `missingUsage` marker); it rejects prompts, message bodies, credentials and other extra fields. The formal Codex plugin manifest lives at `.codex

阅读完整 README仓库许可: MIT

dsh-cost DSH 插件常见问题

如何安装 dsh-cost?

在 DSH 环境中运行 `dsh plugin --profile <name> add github:dongsheng123132/dsh-cost` 即可下载并挂载该插件。安装后,你可以在 DSH 会话中使用 `dsh_cost_report` 和 `dsh_cost_check` 工具。

如何配置价格表?

将插件仓库中的 `prices.example.json` 文件复制一份,把其中的零占位符替换为从你的供应商合同中获取的每百万 token 实际价格。然后在插件配置中通过 `priceBookFile: C:/absolute/path/prices.json` 指定该文件的绝对路径。你还可以用 `defaultBudget: 5` 设置默认预算(单位自定)。

能否在不运行 DSH 会话的情况下离线使用 dsh-cost?

可以。运行离线账本模式:`dsh-cost --events session-events.json --prices prices.json --budget 5 --fail-closed`。事件文件可以是原始数组或包含 `events` 数组的对象。退出码 2 表示超出预算或当 `--fail-closed` 生效时未知状态。

MCP 服务器有什么用?

内置的 stdio MCP 服务器提供与 `cost_report` 和 `cost_check` 相同的费用计算功能,但仅接受受限且消毒过的用量行(provider、model、token 桶或显式的 missingUsage 标记)。它拒绝提示词、消息体、凭据和其他额外字段,因此可以安全地从外部工具使用,不会暴露敏感数据。

如果某些 provider 调用没有用量记录,或者价格表中缺少某些路由,会发生什么?

没有 provider 用量的调用会被列为 `missingUsageCalls`,价格表中缺少的路由会被列为 `unpricedCalls`。如果存在任何缺失或未定价的调用,即使已知费用低于预算,预算检查也会返回 'unknown' 而非 'within'。这确保了部分证据永远不会变成虚假的 reassuring 总数。