Back to home@doublemolu

dsh-costometer

花知多少 · Cost-O-Meter — DeepSeek Harness cost & balance meter: account balance, recharge history, per-conversation spend & tokens, 50-yuan segmented progress bar, low-balance guard, 8 languages & currencies with auto FX rates (CNY base).

Stars
1
Language
JavaScript
Created
Aug 28, 2026
Updated
Sep 1, 2026

Introduction

dsh-costometer · 花知多少

English | 中文

A permanent DeepSeek Harness (DSH) cost & balance meter: account balance, recharge history, per-conversation spend and token usage, a segmented 50-yuan progress bar, and a recharge shortcut — all in a card docked above the Settings button in the left sidebar.

Works with both the wide sidebar (full card) and the collapsed 56px rail (status dot).

About the name

dsh-costometer = dsh (DeepSeek Harness) + cost + -ometer (a measuring instrument) — a "money-spend meter". Its Chinese title is 花知多少 (huā zhī duōshǎo), a playful take on "how much have you actually spent?" — the plugin answers that question at a glance: balance, every conversation's cost, recharge history, and a low-balance guard.

Features

  • Account balance — total, granted (赠送) and topped-up (充值) amounts, refreshed automatically. Uses the free DeepSeek GET /user/balance endpoint — no tokens consumed.
  • Per-conversation spend — two figures:
    • 本次用量 (latest single model call): tokens + estimated cost of the most recent call.
    • 本会话累计 (conversation total): folded from the durable session log, so it survives DSH restarts. Cost is estimated per call using the actual model and DeepSeek's official CNY peak/off-peak pricing.
    • 本会话累计调用模型次数: how many times the model was called in this conversation.
  • Recharge history最近充值 (last top-up time + amount) and 累计充值 (total topped up), tracked locally by observing balance growth (the official API exposes no recharge history).
  • 50-yuan segmented progress bar — the track represents your topped-up amount (50 yuan per segment); the green fill shows the remaining balance proportionally. Consumption depletes from the right; the rightmost segment turns red below ¥15; when a 50-yuan block is fully used it disappears with a balloon-pop effect and the fill smoothly stretches to the new width. Resizes with the sidebar.
  • Recharge button — a separate button below the bar that opens the DeepSeek open platform top-up page in a new tab.
  • Low-balance alerts — amber warning below ¥10, red alert below ¥3, and a "conversation spend exceeds balance" notice.
  • 8 languages & currencies — 简体中文 / 繁體中文 / English (US/UK) / Deutsch / 日本語 / 한국어 / Русский; each language defaults to its currency (CNY/TWD/USD/GBP/EUR/JPY/KRW/RUB) with auto-updated exchange rates against CNY (free API, zero token cost).
  • Position guard — the card registers at the top of the sidebar footer; if another plugin registers into the sidebar footer or replaces the whole sidebar, a popup asks whether to allow the displacement or keep the balance card first.
  • Theme-aware — uses DSH theme tokens, adapts to light/dark themes.

Installation

Prerequisites

  • DeepSeek Harness installed and running (web profile).
  • A DeepSeek API key stored in DSH credentials (DEEPSEEK_API_KEY) — normally set from Settings → Models. The plugin reuses the same credential the chat model uses.

Option 1 — install from this repo (git)

# in your dsh profile directory (~/.dsh/profiles/web)
dsh plugin --profile web add git+https://github.com/doublemolu/dsh-costometer.git

Option 2 — clone and link locally

git clone https://github.com/doublemolu/dsh-costometer.git
cd ~/.dsh/profiles/web
pnpm add file:/absolute/path/to/dsh-costometer

Register the plugin row

Add the row to your profile composition ~/.dsh/profiles/web/cordis.patch.yml:

- insert:
    - id: balance-dock
      name: dsh-costometer

Restart DSH

Plugin-set changes take effect on restart. After restart the card appears above the Settings button automatically — it is a permanent plugin and survives restarts (no manual re-run needed).

Usage

Sidebar stateWhat you see
Wide sidebarFull card: balance, granted/topped-up split, latest call usage, conversation total, model-call count, segmented progress bar, recharge button
Collapsed rail (56px)Small status dot (green / amber / red) with a tooltip summary
  • Balance refreshes every 15s; conversation totals every 8s (cached fold of the session log). Use the ⟳ button on the card to refresh immediately.
  • Click 充值 ↗ to open https://platform.deepseek.com/top_up.
  • Hover the progress bar to see 剩余 ¥xx / 充值 ¥xx; hover 本会话累计 to see per-model breakdown.
  • A ▼/▲ ¥xx indicator next to the balance shows recent changes; the card footer shows the last refresh time.

Configuration (v1.1.0+)

All tunables live in $DSH_HOME/dsh-costometer.json (auto-generated with defaults on first run). Edit and save — the plugin picks changes up within ~10s.

{
  "segmentBase": 50,
  "redThreshold": 15,
  "warnLow": 10,
  "warnDanger": 3,
  "fxCny": 7.1,
  "lang": "zh-CN",
  "currency": "CNY",
  "prices": {
    "deepseek-v4-flash": { "peak": { "in": 3.0, "inHit": 0.10, "out": 9.0 }, "off": { "in": 1.5, "inHit": 0.05, "out": 4.5 } },
    "deepseek-v4": { "peak": { "in": 3.0, "inHit": 0.10, "out": 9.0 }, "off": { "in": 1.5, "inHit": 0.05, "out": 4.5 } },
    "deepseek-chat": { "peak": { "in": 2.0, "inHit": 0.20, "out": 3.0 }, "off": { "in": 1.0, "inHit": 0.10, "out": 1.5 } },
    "deepseek-reasoner": { "peak": { "in": 4.0, "inHit": 1.0, "out": 16.0 }, "off": { "in": 2.0, "inHit": 0.5, "out": 8.0 } }
  }
}
KeyMeaningDefault
segmentBaseProgress-bar segment amount (yuan)50
redThresholdRightmost segment turns red below this (yuan)15
warnLow / warnDangerLow-balance alert thresholds (yuan)10 / 3
fxCnyOnly used for the secondary approximate USD figure of cost estimates (estUsd); costs themselves are priced directly in CNY7.1
langUI language: zh-CN / zh-TW / en-US / en-GB / de / ja / ko / ruzh-CN
currencyDisplay currency: CNY / TWD / USD / GBP / EUR / JPY / KRW / RUB (auto-updated rates against CNY)CNY
ratesBuilt-in fallback exchange rates (1 CNY → currency); live rates auto-fetch from a free API (multi-endpoint fallback), 6h cache, zero token costbuilt-in
pricesOfficial CNY peak/off-peak pricing per model, per million tokens (peak / off sets)official

How it works

  • Host half (lib/index.js) registers same-origin HTTP routes on the DSH web server:
    • GET /dsh-balance/balance — resolves the DEEPSEEK_API_KEY credential and calls the official balance endpoint with Node's native fetch (no child process).
    • GET /dsh-balance/spend — live usage from an llm/stream interceptor + a durable fold of assistant/message events from the session log (per-call model, official pricing, peak/off-peak discount).
    • GET /dsh-balance/config — client-facing tunables.
    • GET /dsh-balance/guard-ask — position-guard popup via the user-questions service.
  • Client half (client.js) is a classic-script bundle registered through window.__ModuleLoader__.load, rendering the card in the sidebar.footer.action slot and polling the routes with the browser's native fetch.

Cost estimation notes

  • Costs are estimated directly in CNY using DeepSeek's official CNY peak/off-peak pricing per million tokens (deepseek-v4-flash / deepseek-v4 / deepseek-chat / deepseek-reasoner; unknown models fall back to deepseek-chat).
  • Peak vs off-peak is selected per call by its timestamp (off-peak 16:30–00:30 UTC).
  • fxCny is not the pricing currency — it only produces the secondary approximate USD figure (estUsd). Adjust the prices section in the config file to tune the estimate.

Security & credentials

Your DeepSeek API key is never stored, committed, or transmitted by this plugin:

  • The repository contains no key material — code only references the credential name DEEPSEEK_API_KEY. No .credentials.yaml, .env, or any secret file is committed.
  • At runtime the key is resolved locally through the DSH credentials service (credentials.resolve('DEEPSEEK_API_KEY')) — the same credential store the chat model uses (normally ~/.dsh/.credentials.yaml on your machine).
  • The key travels only on your machine: credential store → plugin → child-process environment variable (never command-line arguments) → a TLS request to the official api.deepseek.com endpoint.
  • The key is never sent to the browser, never logged, and never sent to GitHub or any third party.
  • Error messages never include the key (child-process errors are truncated and contain no authorization header).

Tip: the plugin is only as safe as your key itself. If you ever shared the key elsewhere, rotate it in the DeepSeek platform and update it in Settings → Models.

Common issues

SymptomCause / fix
Card shows 未配置 DEEPSEEK_API_KEYStore the key in Settings → Models (or export DEEPSEEK_API_KEY in the launching environment)
Card shows HTTP 401 …The stored API key is invalid or expired
No card after installThe plugin row is missing from cordis.patch.yml, or DSH was not restarted
Balance never updatesnode or curl not on PATH (both are normally present)

License

MIT