前言¶
DeepSeek Harness 的默认界面不显示每轮对话的金额,开发者要自己估算。dsh-turn-cost 在每轮底部显示「本轮 ¥…」,并支持悬停查看明细。它不把一轮当成一个整体,而是按每条 assistant 节点的 usage + 模型 + 时间分别计价再求和,这样在跨模型、跨峰谷时段、混用免费路由时更准确。
插件简介¶
- 名称:dsh-turn-cost
- 维护者:Lyqqt
- 分类:模型推理
- 功能:在每轮对话底部显示费用,支持悬停查看明细;支持 OpenRouter 端点区间与 generation 实际扣费查询。
安装与启用¶
从 GitHub 直接装进 profile:
dsh plugin --profile desktop add github:Lyqqt/dsh-turn-cost
或者克隆后本地安装:
git clone https://github.com/Lyqqt/dsh-turn-cost.git
powershell -ExecutionPolicy Bypass -File .\dsh-turn-cost\install.ps1
装完后在插件中心可以看到「费用」条目。宿主半(价格目录路由)需要重启一次 DeepSeek Harness 才加载,客户端半有 HMR。验证方法:浏览器打开 http://127.0.0.1:<port>/dsh-turn-cost/prices.json,应返回 {"ok":true,...}。
显示位置¶
- 每轮底部:
conversation.chat.turnTail,渲染在 usage / 时间那一行之前,显示「本轮 ¥… · X 次」。 - 输入框底栏:
conversation.composer.dock的会话总量「总 ¥…」。
悬停展开明细,列出每个请求的模型、用量、价格来源。
计价口径¶
deepseek-official路由:使用内置人民币峰谷表,北京工作日 09:00–12:00、14:00–18:00 按峰时(2 倍),周末与法定节假日按谷时。- 其他路由(openrouter / 自定义):使用 models.dev 挂牌价(USD/M),按
provider|model匹配;:free后缀直接记 0。 - 手写
overrides:用户配置,优先级最高。 priceModules/registerPriceSource:用户代码,优先级最高。
显示区间与实际扣费¶
同一 OpenRouter 模型在不同端点的价格可能相差 10–30 倍。插件通过 generation id 调用 OpenRouter 的 /api/v1/generation?id=… 接口获取实际提供方与费用。最近 generationLookback 轮会逐请求查实际值,全部命中时读数变成实际计费,显示「OpenAI · ¥…(实际)」。拿不到(老会话、没配 key、请求被清理、超时)时,退回到端点区间显示,并加「预估」前缀。
配置¶
配置写在 profile 的 ~/.dsh/profiles/<profile>/cordis.patch.yml 里:
- id: turn-cost
name: dsh-turn-cost
config:
currency: CNY
usdToCny: 7.2
proxy: socks5://127.0.0.1:1080
refreshHours: 24
unknownDisplay: dash
showRequests: true
priceNote: '价格来自 openrouter'
sources:
modelsDev: true
openrouter: true
pricers:
openrouter: true
aliases:
'@preset/ds41f-cheap': 'openrouter|deepseek/deepseek-v4.1-flash'
overrides: []
priceModules: []
常用字段说明:
- enabled:默认 true,关闭后不渲染。
- currency / usdToCny:显示币种与汇率。
- proxy:宿主拉取价格目录用的代理。
- refreshHours:目录缓存新鲜度。
- providers:默认 15 家,只把这些 models.dev provider 写进目录。
- providerMap:DSH 路由 id → models.dev provider id。
- aliases:模型别名,值为 provider|model 或裸模型 id。
- overrides:手写单价,优先级最高。
- priceModules:.mjs 价格模块路径。
- endpointRanges:总开关,关掉后所有 pricer 不参与,只显示模型价。
- pricers:按 id 关掉某个 pricer,如 { openrouter: false }。
- generationLookup:用 generation id 查实际提供方与费用(需要 OpenRouter key)。
- generationLookback:只查最近多少轮。
自定义价格:四层,按需选最轻的¶
- 只想改数字:使用
overrides,精确到路由或子串匹配。 - 批量拉价目表:使用
priceModules,宿主侧.mjs。 - 新增 pricer:客户端插件里注入
turnCostPricers,实现match与quote。
示例:
export function apply(ctx) {
ctx.inject(['turnCostPricers'], (scope) => scope.turnCostPricers.register({
id: 'my-relay',
match: (target) => target.provider === 'my-relay',
quote({ request, target, price, usage, config, ladder }) {
return { min: 0.01, max: 0.03, count: 2, note: '自定义两档' }
},
}))
}
适用场景与注意¶
- 适合需要精确查看每轮费用、跨模型计价、使用 OpenRouter 或自定义路由的开发者。
- 插件以当前 dsh 进程权限运行,安装前应检查源码与许可证。
- 宿主半只在 profile 启动时读一次 entry config,加
proxy等配置后需要重启 DeepSeek Harness 才生效。不想重启时,可修改~/.dsh/turn-cost/config.json,每次重建会重读该文件。
总结¶
dsh-turn-cost 在 DeepSeek Harness 中提供每轮费用显示,支持明细展开、OpenRouter 端点区间查询与 generation 实际扣费,配合多层自定义机制,适合需要精细化成本控制的开发者。插件目录页与 GitHub 仓库见下方链接。