安装
在 DeepSeek Harness 里通过 dsh-market 安装
dsh plugin --profile web add dshmarket
或使用命令行
dsh plugin --profile web add github:gdy01/dsh-token-cost
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络。请先审阅源码,并尽量锁定 commit(github:owner/repo#sha)。
README
一个 DSH 插件:按项目展示 LLM Token 用量,并按模型标准价格自动换算成人民币花费,分为:
- 输入(未命中) —— 未命中缓存的输入 token
- 命中 —— 缓存命中的输入 token(
cacheReadTokens) - 输出 —— 输出 token
未知模型会照常列出 token 数,但费用显示为「—」,方便你直接补充价格,无需改代码。
功能
- 读取本地 DSH 会话日志(
~/.dsh/sessions或$DSH_HOME/sessions)。 - 按项目(会话
cwd)和模型聚合统计。 - 在 DSH Web 侧边栏底部增加 💰 按钮;面板展示项目汇总和可展开的模型明细。
- 零运行时 npm 依赖:使用 Node 自带的
node:zlibZstandard 解码。 - HTTP API 仅允许回环访问(
/dsh-token-cost/*)。
安装
请安装子目录 dsh-token-cost,不要安装上一级的 dsh plugin 目录。上一级目录没有 package.json,装错不会出现侧边栏按钮。
推荐使用绝对路径(路径里有空格,必须加引号):
dsh plugin --profile web add "file:/Users/dg/Documents/dsh plugin/dsh-token-cost"
或在该目录内执行:
cd /Users/dg/Documents/dsh plugin/dsh-token-cost
dsh plugin --profile web add "file:$PWD"
如果之前装错了 dsh plugin 目录,先卸载再重装:
dsh plugin --profile web remove "dsh plugin"
dsh plugin --profile web add "file:/Users/dg/Documents/dsh plugin/dsh-token-cost"
安装后重启 dsh web 并刷新页面,侧边栏底部会出现 💰 按钮。
也可以直接运行仓库里的安装脚本:
./scripts/install.sh
原理
宿主插件扫描 DSH sessions 目录下的每个 session.jsonl.zstd / session.jsonl,重放:
session.cwd→ 项目request/header→ 当前模型assistant/chunk { type: 'usage' }与assistant/message.usage→ 输入 / 命中 / 输出 token
同一 (turn, step) 的用量会去重(后面的 assistant/message 会替换之前的 usage chunk),与 DSH 自身 token-meter 的口径一致。
价格表
内置 DeepSeek 官方人民币价格(元 / 百万 tokens):
| 模型 | 输入(未命中) | 命中 | 输出 |
|---|---|---|---|
deepseek-chat / deepseek-v4-flash |
2 | 0.5 | 8 |
deepseek-reasoner / deepseek-v4-pro |
4 | 1 | 16 |
可在 profile 的 cordis.patch.yml 中覆盖(patch 行会替换整个 config,所以需要保留的价格都要写全):
- id: token-cost
config:
prices:
deepseek-chat:
input: 2
hit: 0.5
output: 8
deepseek-reasoner:
input: 4
hit: 1
output: 16
deepseek-v4-flash:
input: 2
hit: 0.5
output: 8
deepseek-v4-pro:
input: 4
hit: 1
output: 16
API
GET /dsh-token-cost/api/stats—— 完整的按项目/按模型 JSONGET /dsh-token-cost/api/prices—— 当前价格表GET /dsh-token-cost/healthz—— 存活检查
License
MIT