GeekRicardo/dsh-balance
dsh-balance
dsh-balance is a community DeepSeek Harness plugin. Read the repository README before installing.
Install
npx @deepseek-ai/dsh plugin --profile web add github:GeekRicardo/dsh-balanceRestart `dsh web` after install. Bundle APIs can change during the developer preview.
README badge
[](https://dshhub.dev/plugins/geekricardo-dsh-balance)Paste this into your README. The star count updates with every catalog sync.
From the README
Excerpt from GeekRicardo/dsh-balance, cleaned of badges and images.
dsh-balance
DeepSeek Harness web 插件:在输入框下方状态栏展示当前供应商的余额/用量,按 provider 实时切换(2 秒轮询),余额/用量 5 分钟缓存。
支持的供应商
| provider | 供应商 | 展示内容 | 密钥 | 接口 |
|---|---|---|---|---|
deepseek / deepseek-official / deepseek-vision | DeepSeek 官方(含 dsh-vision-router 的“DeepSeek+视觉” wrapper) | ● 本会话 ¥X.XX · ● 余额 ¥465.46 | DEEPSEEK_API_KEY | GET api.deepseek.com/user/balance |
kimi-coding | Kimi For Coding | 5小时 3% 4h15m · 7天 31% 6d0h · 5分钟前 | KIMI_CODING_API_KEY(兼容 KIMI_CODE_API_KEY/KIMI_API_KEY) | GET api.kimi.com/coding/v1/usages |
opencode-go | OpenCode Go | 5小时 8% 3h · 7天 3% 5d0h · 30天 1% 27d · 5分钟前 | OPENCODE_GO_API_KEY(兼容 OPENCODE_API_KEY) | GET opencode.ai/zen/go/v1/usage |
zai-coding-cn / zai | 智谱 GLM Coding Plan | 5小时 3% 4h15m · 7天 31% 6d0h · 5分钟前 | ZAI_CODING_CN_API_KEY / ZAI_API_KEY | GET open.bigmodel.cn 或 api.z.ai/api/monitor/usage/quota/limit |
minimax-cn / minimax | MiniMax Coding Plan | 5小时 3% 4h15m · 7天 31% 6d0h · 5分钟前 | MINIMAX_CN_API_KEY / MINIMAX_API_KEY | GET api.minimaxi.com 或 api.minimax.io/v1/api/openplatform/coding_plan/remains |
openrouter | OpenRouter | ● 余额 $8.42 | OPENROUTER_API_KEY | GET openrouter.ai/api/v1/credits |
openai-codex | OpenAI Codex(订阅) | 5小时 15% 3h · 7天 30% 4d2h · 5分钟前 | OPENAI_CODEX_ACCESS_TOKEN(可选 OPENAI_CODEX_ACCOUNT_ID) | GET chatgpt.com/backend-api/wham/usage |
| 其他 provider | — | 不显示(返回 null) | — | — |
deepseek与deepseek-official是 DeepSeek 官方的两条 provider 路由(DSH 自带dsh-llm-deepseek与 pi-ai catalog),余额接口相同,都展示官方余额。
为什么不是 cc-switch 的全部供应商
cc-switch 的用量查询实现里,能在 DSH 实际触发的是以上 7 家(pi-ai 有对应 provider id,模型选择器能切到)。以下两类未接入:
- OAuth 订阅类(Claude / Gemini / Grok):cc-switch 走各自桌面 OAuth 会话 token(
~/.claude、~/.gemini、Grok session)查询订阅额度,而 DSH 里这些 provider 走 API key 认证,插件拿不到订阅 token,无法干净接入。 - pi-ai 无对应 provider(SiliconFlow / StepFun / Novita / 火山 / ZenMux):DSH 模型选择器里没有这些 provider id,加了也永远不会触发。
deepseek与deepseek-official是 DeepSeek 官方的两条 provider 路由(DSH 自带dsh-llm-deepseek与 pi-ai catalog),余额接口相同,都展示官方余额。
实时性
- 2 秒轮询:切换模型/切换对话后最多 2 秒更新。
- 按 provider 判断:用
agentDefaultModel.currentSelection()(当前选中,切换即更新),不依赖「最近一次请求的模型」。 - 5 分钟缓存:余额/用量实际查询每 5 分钟一次(host 端按 provider 缓存),切走再切回强制刷新一次。
- 切换对话:client 按
sessionId重新加载;DeepSeek 本会话花费按 session 分别累计(llm/streamtoken × models.dev 单价估算)。
一键安装
curl -fsSL https://raw.githubusercontent.com/GeekRicardo/dsh-balance/main/install.sh | bash
脚本做的事(可先 --dry-run 预览):
- 在
~/.dsh/profiles/web/package.json写入依赖"dsh-balance": "github:GeekRicardo/dsh-balance"; - 把
dsh-balance追加进dsh.profile.bundles; cd ~/.dsh/profiles/web && pnpm install;- 校验 bundles 已注册,提示重启。
重启 DSH 并硬刷新页面后生效:
pm2 restart dsh-web # 若用 pm2 托管;否则用你的启动方式重启
卸载
# 1. 从 ~/.dsh/profiles/web/package.json 的 dsh.profile.bundles 移除 "dsh-balance"
# 2. 移除 dependencies 里的 "dsh-balance"
# 3. cd ~/.dsh/profiles/web && pnpm install
# 4. 重启 DSH
前置条件
- DeepSeek Harness 已初始化 web profile(
~/.dsh/profiles/web存在)。 ~/.dsh/.credentials.yaml里配置对应供应商的密钥(见上表)。- Node.js ≥ 20、pnpm 可用。
工作原理
| 半区 | 职责 |
|---|---|
| Host | 监听 llm/stream 按 session 累计 DeepSeek 官方模型的 token;经 credentials 读密钥,按 provider 查对应接口;5 分钟缓存;注册 /dsh-balance/status HTTP route |
| Client | 在 conversation.composer.dock 槽位渲染状态栏,fetch 轮询该 route(2s),按 provider 分发渲染 |
DeepSeek 计费口径(重要)
…

