Skip to main content

dsh-balance-meter

19Stars2Forks5Issues0Watchers

DeepSeek account balance and session cost in the composer dock, with auto-fetched official pricing and peak/off-peak support.

Evidence5/5methodologySourceInstallMaintenanceDSH versionSecurity scan
Machine-auditedInstall commandRepo verifieddsh-plugin topicLicenseREADMEAI wiki
Language
JavaScript
License
BSD-3-Clause
Branch
master
balancecost-trackingdeepseekdeepseek-harnessdshdsh-plugindsh-web-uiplugin

Install

cmdweb profile
$ dsh plugin --profile web add dsh-balance-meter

Run the command above in your terminal to install this plugin via the dsh CLI. You can switch Profile in the top-right corner. New to dsh? Read the beginner tutorial

Install via your agent

Install the DeepSeek Harness plugin Ghost011118/dsh-balance-meter for me: review the repository at https://github.com/Ghost011118/dsh-balance-meter first, then run the install command and verify the plugin loads successfully.

Paste this instruction to the DSH Web GUI assistant — it will install and verify for you.

一句话定位

在 DSH Web 界面的输入框旁边显示 DeepSeek 账户余额和当前会话估算花费,按你实际调用的模型(flash/pro)自动按官方单价计价,并支持官方 API、中转接口、本地记账三种余额来源。

核心能力

  • 在输入框下方的状态条显示余额 + 本场会话花费 chip,点击展开按币种、按 token 分桶的明细
  • 调用 DeepSeek 官方的 "获取用户余额" 接口读取真实账户余额(赠送 + 充值)
  • 自动从每个会话的请求头识别本次对话用的是 flash 还是 pro 模型,按对应官方单价核算花费
  • 每 6 小时自动抓取一次官方价格页,价格调整和 2026-08-17 的峰谷定价上线都无需更新插件
  • 支持三种余额来源:DeepSeek 官方 API、第三方中转兼容端点(API Key 留在本地仅作 Bearer 凭据)、本地手工记账(适用于无余额接口的场景)
  • 在插件设置面板可切换来源、调整余额查询间隔、修改本地余额基线

技术实现

  • 语言: TypeScript(含 React 18 + TSX 客户端)
  • 关键依赖: @deepseek-ai/cordis(DSH 的插件运行时/DI 容器)、@deepseek-ai/dsh-credentials(凭据通道)、@deepseek-ai/dsh-settings(设置面板 schema)、@deepseek-ai/schemastery(配置 schema)
  • 架构模式: 双端插件——主机侧把 BalanceService 注册成 cordis 服务并挂载 /api/balance 等 HTTP 路由;浏览器侧把一个 React 组件注册到 DSH 的 conversation.composer.dock 槽位里,每 30 秒轮询主机接口
  • 入口文件: 主机侧 src/index.ts,浏览器侧 src/client/index.ts

适用场景

经常用 DSH 跑 DeepSeek 对话、希望随时知道"还剩多少钱、本场花多少"的用户;用第三方中转 API 但还想看到账户余额(plugin 会按你指定的中转路径解析数字余额并明确标注为"中转");以及没有余额接口、只能自己在设置面板里维护当前余额基线的场景。

前置依赖与兼容性

依赖最低版本说明
DeepSeek Harness^0.1.0-rc.6必须是 web profile;plugin 通过 cordis.patch.yml 把 balance 行注入 web profile roster
Node.js^22.19.0 或 >=24.0.0来自 package.json engines 字段
DeepSeek API Key—走 DSH 凭据通道存储(默认引用 DEEPSEEK_API_KEY),无 Key 时 chip 显示"不可用"
平台跨平台纯 HTTP 请求,无原生模块依赖

安装方式

dsh plugin --profile web add github:Ghost011118/dsh-balance-meter

安装后重启 dsh web 并刷新浏览器页面。

配置项

插件默认零配置即可工作。如下设置可在 DSH 设置面板中调整,也可以在 cordis.patch.yml 的组合配置里覆盖:

配置类型说明默认值
余额来源官方 / 中转 / 本地决定余额从哪里读;旧配置只改了 API 地址时会被自动标为"中转"官方
API Key 凭据引用字符串DSH 凭据通道里保存 DeepSeek API Key 的引用名DEEPSEEK_API_KEY
API 基础地址URL官方默认 https://api.deepseek.com;改了就视为中转官方地址
余额端点路径字符串中转模式下的余额查询路径或完整 URL/user/balance
中转余额字段路径字符串当中转不返回 DeepSeek 格式时的数字余额点路径(如 data.balance)未设置
中转余额币种字符串中转数字余额的币种CNY
本地当前余额数字 (≥0)手工记账模式的起始/重置余额;改动后会建立新基线未设置
本地余额币种字符串本地记账的币种,必须与会话花费币种一致CNY
余额刷新间隔(秒)0-3600两次向余额接口查询的最小间隔30
计价模式auto / flash / proauto 从请求头自动识别本次会话用的模型;显式选 flash/pro 则强制按该预设计价auto
官方价格刷新间隔(小时)数字每隔多少小时重新抓取官方价格页6
启用余额显示开关关闭后隐藏 chip 并停止轮询;插件设置面板里有这个开关开启

常见问题

Q: 安装后在哪里看到余额 chip?

A: 重启 dsh web 并刷新页面后,输入框下方的状态条会出现一个 "余额 CNY x.xx · 本场 CNY y.yy" 的按钮。点击展开可以看按币种(赠送 + 充值)和按 token 分桶(输入 / 缓存读 / 输出)的明细。

Q: 显示 "no API key for provider route deepseek-official" 怎么办?

A: 宿主从 DSH 凭据存储(~/.dsh/.credentials.yaml)读取 DeepSeek API Key——也就是 Web 上 Models 页面写入的那个 Key。在凭据文件里加上 DEEPSEEK_API_KEY: sk-... 即可,DSH 运行中编辑也能热重载;plugin 的余额查询与 LLM 路由都走同一套凭据通道。

Q: 余额卡在 "不可用",必须点击才能刷新吗?

A: 不需要。该问题在新版本中已修复:错误视图不会被当作新鲜缓存复用,每次 30 秒轮询都会重新查询 provider,所以只要底层条件恢复(余额可达、网络恢复、Key 已写入),chip 会自己恢复正常显示。

Q: 我用第三方中转 API,怎么显示余额?

A: 在插件设置里把"余额来源"切换为"中转"。DeepSeek 兼容格式的中转可直接返回 balance_infos;其他格式需要填写"中转余额字段路径"(如 data.balance)。plugin 会明确把中转来源标为"中转",绝不会伪装成官方余额。API Key 始终留在 DSH 主机,只作为 Bearer 凭据发往中转端点。

Q: manual 模式的数据存在哪里?安全吗?

A: 账本存在 DSH settings 命名空间下的 balance.manualLedger 字段里,标记为隐藏的密钥字段——不另建明文文件,也不会随普通余额响应发给浏览器。账本记录基线、剩余余额、本地累计扣费、以及每个会话的累计 token 检查点。

Q: 重启 DSH 或者插件会重复扣费吗?

A: 不会。manual 模式只扣除"上次成功持久化的 token 检查点"之后的正向 token 增量——轮询和重启都不会对同一份累计会话消耗重复扣费。

Q: 缓存写入(cache write)token 会扣费吗?

A: 不会。DeepSeek 不对缓存写入单独计费,plugin 默认按 0 元/百万 tokens 计算。

Q: 2026-08-17 的峰谷定价会自动切换吗?

A: 会。plugin 每 6 小时抓取一次官方价格页,解析当前单价和峰/闲两套单价;2026-08-17 之后按当前北京时间(09:00-12:00、14:00-18:00 高峰,其余闲时)自动按对应单价核算。该日期之前即使页面已列出峰谷表,也仍按当前单一价格计价。

上手难度

入门 — 零配置即可用,余额来源、API Key、刷新间隔都能在 Web 设置面板里点选;唯一需要前置准备的是在 Web 的 Models 页面写入 DeepSeek API Key。

已知问题与限制

  • API Key 解析按"凭据通道 → 启动环境变量 → process.env"的顺序回退。当凭据 seam 已挂载时,仅 export DEEPSEEK_API_KEY 不会生效(seam 优先级更高)
  • 中转模式必须显式配置"中转余额字段路径"才能识别数字余额;中转响应若不包含 DeepSeek 兼容的 balance_infos,未配置字段路径时会显示"中转余额错误"
  • manual 模式要求部署有可写的 DSH settings provider,否则无法持久化本地账本
  • 计价模式设为 auto 时,如果某会话还没有产生过任何请求头,plugin 会回退到 flash 单价
  • cacheWriteTokens 默认按 0 计费,不支持单独开启(DeepSeek 官方不单独对缓存写入计费)

Read the usage guide →

Install steps, key points, FAQ and compatibility for this plugin — auto-derived from indexed fields.

Listing badge

Listed on deepseek-plugin.org
[![Listed on deepseek-plugin.org](https://img.shields.io/badge/listed_on-deepseek--plugin.org-007EC6)](https://deepseek-plugin.org/plugins/Ghost011118/dsh-balance-meter)

Paste this markdown into your GitHub README to link back to this listing. The badge only states the listing — not a security endorsement.

← Back to plugin directory