dsh-platform-balance
Manifest validDeepSeek Platform wallet balances in USD and CNY, CBR RUB conversion with an 18:00 MSK rate cache, and current-session and current-day spend estimates in a floating card and session header pill.
dsh-platform-balance
A DeepSeek Harness Web GUI plugin. The card and the session-header pill follow the provider selected in the current session and show its balance and spend:
- DeepSeek Platform — the wallet balance in every currency the platform reports (USD and CNY), converted into Russian rubles at the official Central Bank of Russia (CBR) rate, and estimated spend for the current session and the current day in CNY and RUB;
- OpenCode Go — the connected account's plan and three usage windows (5 hours, week, month) with limit/used/remaining in USD and RUB, the account's rolling 24-hour cost, and an estimated session spend in USD and RUB;
- any other provider — the provider name and the model, the current CBR rates, and the note that the provider is not supported yet.
The UI follows the GUI language and ships English, Russian, and Simplified Chinese dictionaries; any other language falls back to English. Errors coming from the host are localized by stable codes, so a language switch needs no reload.
Two pieces of UI appear:
- a floating card in the bottom-right corner — the mode-specific balance block, the CBR rate row with its quote date and refresh time, and the session/day spend. The card collapses to a single line and lifts itself above the message composer so it never covers the send button;
- a pill in the header of an open session — DeepSeek:
≈ 153 ₽ · session 5,58 ₽ · day 15,25 ₽; OpenCode Go:≈ $48.09 · session $0.02 · day $1.20; unsupported:Ollama · qwen3.5:9b. Clicking it collapses or expands the card. The pill exists only inside a conversation; the card is visible on every screen.
Modes and provider detection
The browser half reads the model selection recorded for the open session
(next, falling back to lastUsed) and sends its provider/model to the host. With no session (home
screen, a fresh session before its first request), the host answers from the deployment default model
(agentDefaultModel.currentSelection()). The host maps the result to one display mode:
| Provider id | Mode |
|---|---|
exactly opencode-go | OpenCode Go |
contains deepseek (deepseek-official, deepseek-account, …) | DeepSeek |
| everything else, including an empty/unknown id | Unsupported |
DeepSeek and OpenCode Go are independent sources: when OpenCode Go is selected the DeepSeek wallet
block is hidden, and the card title becomes OpenCode Go · balance.
Data sources
| What | Where it comes from |
|---|---|
| DeepSeek balance | DSH account service (deepseekAccount.getBalance, browser sign-in, no API key); when the account is signed out — DEEPSEEK_API_KEY via https://api.deepseek.com/user/balance |
| OpenCode Go plan and quota | GET https://opencode.ai/console/api/go/status with the OpenCode Go API key: product (go, go-plus, go-teams), period end, and fiveHour/week/month meters in micro-cents |
| OpenCode Go fallback | GET https://opencode.ai/zen/go/v1/usage (public endpoint, percentages only) when the console API is unavailable |
| OpenCode Go today | GET https://opencode.ai/console/api/usage/summary?range=24h: the account's cost/requests/tokens for the rolling 24 hours, the same figure the Console page shows for Today |
| OpenCode published allowances | Built-in snapshot of the OpenCode Go plan table (docs/console/go#usage-limits): the monthly dollar limit of each model on Go, Go Plus and Go Teams |
| OpenCode prices | GET https://opencode.ai/inference/go/v1/models with the same key: per-model USD prices and peak-hour multipliers |
| CBR rate | Official CBR XML feed https://www.cbr.ru/scripts/XML_daily.asp, USD and CNY against RUB |
| DeepSeek spend | DSH session logs (ctx.sessionPersistence): request token usage × official DeepSeek prices in CNY |
| OpenCode Go spend | The same session logs × the OpenCode model catalog prices in USD |
The OpenCode Go key is resolved from the credential reference of the llm-pi-ai provider route
opencode-go (the profile sets OPENCODE_GO_API_KEY) through the credentials service, with the
environment variable as a fallback. The plugin never reads DEEPSEEK_API_KEY for OpenCode requests:
the DeepSeek key is not accepted by the Go plan. The key never enters a JSON response.
The plugin sends no data anywhere except those requests. Its HTTP routes are loopback-only and same-origin, so another browser tab cannot read the balances.
OpenCode Go mode
- The console percentage is authoritative for every window (5 hours, week, month). The raw
limitMicroCents/usedMicroCentsmeters are a single normalized pool per plan (Go: $12 / $30 / $60), not the per-model dollar limit, so the card converts the percentage into the current model's published allowance instead: DeepSeek V4.1 Flash has $100/month on Go, so its 5-hour cap is $20, the weekly cap $50, and the monthly cap $100; the used/remaining money ispercentage × cap(plus the CBR RUB conversion). - Models with a smaller published cap burn the pool faster, and the percentage is account-wide
(blended if several models were used), so on a mixed-model account the dollar figure is a close
approximation. A model missing from the published table falls back to the plan's maximum cap
($100 Go, $240 Go Plus, $105 per member Go Teams); the raw normalized-pool amounts stay in the API
as
poolLimitUSD/poolUsedUSDfor diagnostics. The subscription price ($10) is not the 100% amount of the quota. - The day row is the account's own rolling 24-hour cost from the console summary (the Console's "Today": cost, requests, tokens), converted to RUB — not an estimate.
- The plugin deliberately does not show the console's trailing-30-day summary: that window spans more than one billing period, so it cannot be compared with the quota meters and would only mislead.
- The session row is an estimate: the plugin prices recorded token counts with the OpenCode model
catalog (
cost.textrates andmultipliers, so DeepSeek peak hours ×2 are honored). The catalog is cached in$DSH_HOME/cache/platform-balance/opencode-models.jsonfor a day; a model missing from the catalog contributes calls/tokens but no money. - When the console API is unavailable but the public usage endpoint answers, the card shows the quota percentages and notes that exact amounts are unavailable.
- When there is no key, the card explains which credential reference is missing
(
OPENCODE_GO_API_KEY). - Only the quota windows, the 24-hour summary, and the model catalog are read. The account's prepaid Credit balance (the "Credits" card in the Console) is not shown: the billing endpoint answers HTTP 403 to an API key and needs browser cookies.
Unsupported providers
A provider that is neither DeepSeek nor OpenCode Go keeps a compact card: the provider name and model
(best-effort display names from the LLM catalog, falling back to ids), then only the current CBR rates
(USD and CNY), then the localized text This provider is not supported yet. The pill shows
Provider · model. No account is queried and no spend is scanned in this mode.
Language and errors
All UI copy is registered through the DSH locale service as the platform-balance namespace with
complete en, ru, and zh dictionaries (zh is Simplified Chinese). The widget re-renders on a
language switch, <html lang> drives the number/date formatting (ru-RU, zh-CN, en-US), and
English is the fallback chain root for any other language.
Host failures are structured:
{ "ok": false, "error": { "code": "opencodeAuth", "params": { "status": 403 } } }
The browser translates the code with the active dictionary; the optional detail field keeps the
untranslated technical cause for the element tooltip. The API never returns a bare Russian sentence.
CBR rate and its cache
- The rate is stored in
$DSH_HOME/cache/platform-balance/cbr.json(default~/.dsh/cache/platform-balance/cbr.json) and survives restarts. - It is refreshed every day at 18:00 Moscow time (a host-side timer). The same instant is the freshness boundary of the cache.
- With no cache file the rate is fetched on the first request (and warmed once right after the plugin starts).
- When the network is unavailable, the last saved rate stays on screen and is marked as stale: the rate rows and RUB conversions remain visible. After a failed fetch, requests back off for 2 minutes so a one-minute poll never waits on a 10-second timeout each time; a background retry happens 15 minutes later and the refresh button tries immediately.
- Only USD, CNY, and the currencies of the platform wallets are sent to the browser; the cache file keeps the full CBR document. OpenCode Go mode converts USD only.
Spend is an estimate
Neither provider reports a request's cost in the session log, so spend is estimated from token counts and prices:
- DeepSeek (
lib/pricing.js): the official DeepSeek CNY price list, taking into account peak and off-peak hours (peak is 09:00–12:00 and 14:00–18:00 Beijing time, ×2 price); the switch to peak pricing on 2026-08-17; the Flash price cut on 2026-09-10 (and peak pricing on weekdays only); anddeepseek-v4-prorequests being served at Flash prices from 2026-09-14; - OpenCode Go (
lib/opencode-pricing.js): the account's own model catalog fetched from the inference API, including the per-model peak multipliers (for DeepSeek models: weekdays 09:00–12:00 and 14:00–18:00 Beijing time, ×2).
Numbers in the UI are prefixed with ≈: this is an estimate, not a bill. Only routes that actually
spend a connected balance are priced: DeepSeek platform routes (deepseek-account,
deepseek-official, or any provider id containing deepseek) and opencode-go. Sessions on other
providers — a local ollama, a free third-party gateway, another API — never spend either balance, so
their requests are counted separately as otherCalls/otherTokens, add nothing to the money totals,
and the widget notes them as unbilled.
Paid summarization calls (compaction/summary) are included. Forked sessions (subagents with an
inherited history) skip the copied parent prefix in their log, so the daily total is not counted
twice and a forked session reports only its own work.
The "day" is the local calendar day of the machine running DSH (Europe/Moscow, for example). It covers every stored session, including subagent sessions, with inherited fork prefixes excluded. Day totals are cached per session revision, per calendar day, and per OpenCode price-catalog revision, so a repeated request re-reads only changed logs and a midnight rollover re-aggregates the cached day buckets without re-reading the whole session corpus.
Install
The plugin is a regular DSH bundle package:
# from the git repository
dsh plugin --profile web add github:keltanas/dsh-platform-balance
# or from a local checkout
dsh plugin --profile web add ~/projects/dsh-platform-balance
dsh plugin (a pnpm wrapper) adds the dependency and appends the bundle to
~/.dsh/profiles/web/package.json. The profile then reloads itself (patchReload: live) and an
open page picks up the browser half over HMR; a restart of dsh web is not needed for a first
install. If host-half source code changes later, Node caches the imported module, so restart
dsh web (for example systemctl --user restart dsh.service) to apply those changes.
Verify without a browser:
curl -s http://127.0.0.1:3080/api/platform-balance/overview | jq .
curl -s "http://127.0.0.1:3080/api/platform-balance/overview?provider=opencode-go&model=deepseek-v4.1-flash" | jq .
curl -s "http://127.0.0.1:3080/api/platform-balance/session?id=<session-id>" | jq .
Remove:
dsh plugin --profile web remove dsh-platform-balance
Compatibility with dsh-usage-dashboard
If @cassius0924/dsh-usage-dashboard is installed, its floating widget duplicates the balance
card — keep only one of them. Bring that plugin back with
dsh plugin --profile web add @cassius0924/dsh-usage-dashboard@0.9.2.
HTTP API
All routes are GET, loopback-only and same-origin, with cache-control: no-store. The optional
provider/model query parameters carry the current session's model selection; omit them to let the
host use the deployment default model. refresh=1 bypasses every TTL cache.
GET /api/platform-balance/overview[?provider=<id>&model=<id>][&refresh=1]
DeepSeek mode:
{
"ok": true,
"data": {
"generatedAt": 1790000000000,
"mode": "deepseek",
"provider": { "id": "deepseek-official", "name": "DeepSeek" },
"model": { "id": "deepseek-flash", "name": "DeepSeek-Flash" },
"balance": {
"source": "account",
"isAvailable": true,
"wallets": [
{ "currency": "USD", "total": "0.00", "granted": "0.00", "toppedUp": "0.00", "rate": 82.9803, "rub": 0 },
{ "currency": "CNY", "total": "12.34", "granted": "0.00", "toppedUp": "12.34", "rate": 12.4009, "rub": 153.03 }
],
"totalRub": 153.03
},
"cbr": {
"date": "13.11.2026",
"fetchedAt": 1790000000000,
"stale": false,
"rates": { "USD": 82.9803, "CNY": 12.4009 },
"error": null
},
"spend": {
"currency": "CNY",
"estimated": true,
"pricing": { "...": "current DeepSeek price era table" },
"day": { "dayKey": "2026-11-12", "costCNY": 2.5, "rub": 31.0, "calls": 37, "tokens": 1234567, "opencodeCalls": 0, "opencodeTokens": 0, "otherCalls": 5, "otherTokens": 42000 }
}
}
}
OpenCode Go mode:
{
"ok": true,
"data": {
"generatedAt": 1790000000000,
"mode": "opencode-go",
"provider": { "id": "opencode-go", "name": "OpenCode Go" },
"model": { "id": "deepseek-v4.1-flash", "name": "DeepSeek V4.1 Flash" },
"cbr": { "date": "13.11.2026", "fetchedAt": 1790000000000, "stale": false, "rates": { "USD": 82.9803, "CNY": 12.4009 }, "error": null },
"account": {
"ok": true,
"source": "console",
"fetchedAt": 1790000000000,
"plan": { "product": "go", "renewalProduct": "go", "periodEndsAt": "2026-12-04T17:59:17.000Z", "cancelAtPeriodEnd": false, "currency": "usd" },
"allowance": { "planId": "go", "modelId": "deepseek-v4.1-flash", "monthlyUSD": 100, "source": "model" },
"windows": {
"fiveHour": { "limitUSD": 20, "usedUSD": 0.054, "remainingUSD": 19.946, "poolLimitUSD": 12, "poolUsedUSD": 0.032582, "percent": 0.27, "remainingPercent": 99.73, "status": null, "startsAt": "2026-11-14T13:11:13.000Z", "resetsAt": "2026-11-14T18:11:13.000Z", "limitRub": 1659.61, "usedRub": 4.48, "remainingRub": 1655.13 },
"week": { "...": "same shape, limitUSD 50" },
"month": { "...": "same shape, limitUSD 100" }
},
"today": { "costUSD": 1.632624, "costRub": 134.97, "calls": 1085, "inputTokens": 2708643, "outputTokens": 1086965, "cacheReadTokens": 191382784, "cacheWriteTokens": 0 }
},
"spend": {
"currency": "USD",
"estimated": true,
"pricing": { "ok": true, "fetchedAt": 1790000000000, "models": 4 },
"day": { "dayKey": "2026-11-14", "costUSD": 1.2, "rub": 99.58, "calls": 18, "tokens": 456789, "opencodeCalls": 18, "opencodeTokens": 456789, "otherCalls": 2, "otherTokens": 1200 }
}
}
}
Unsupported mode (no balance/spend/account keys):
{
"ok": true,
"data": {
"generatedAt": 1790000000000,
"mode": "unsupported",
"provider": { "id": "ollama", "name": "Ollama" },
"model": { "id": "qwen3.5:9b", "name": "qwen3.5:9b" },
"cbr": { "date": "13.11.2026", "fetchedAt": 1790000000000, "stale": false, "rates": { "USD": 82.9803, "CNY": 12.4009 }, "error": null }
}
}
GET /api/platform-balance/session?id=<sessionId>[&provider=<id>&model=<id>][&refresh=1]
{
"ok": true,
"data": {
"sessionId": "session-...",
"mode": "opencode-go",
"currency": "USD",
"estimated": true,
"costUSD": 0.02,
"rub": 1.66,
"calls": 12,
"tokens": 34567,
"otherCalls": 0,
"otherTokens": 0,
"lastAt": 1790000000000
}
}
DeepSeek mode answers with costCNY instead of costUSD; unsupported mode answers with
currency: null and null counters. Errors always come as
{ "ok": false, "error": { "code": "…", "params": { "…": "…" }, "detail": "…" } }.
Layout
lib/index.js host plugin: HTTP routes, three display modes, TTL caches, CBR timer, warm-up
lib/cbr.js CBR XML fetch/parse, on-disk cache, 18:00 MSK schedule
lib/wallet.js DeepSeek account balance with a DEEPSEEK_API_KEY fallback
lib/opencode-go.js OpenCode Go console status / public usage fallback, key resolution, account cache
lib/opencode-allowances.js published per-model monthly allowances of Go/Go Plus/Go Teams
lib/opencode-pricing.js OpenCode model catalog with USD prices and peak multipliers, disk cache
lib/usage.js session-log reading, per-session and per-day cost aggregation (CNY + USD)
lib/pricing.js official DeepSeek prices and peak/off-peak windows
lib/http.js JSON responses and same-origin checks
lib/client.js browser half: localized card and pill for all three modes
cordis.patch.yml bundle layer: one Loader row carrying both halves
test/ node:test — CBR, prices, usage, wallets, HTTP, OpenCode account/catalog, client smoke
The host half uses the webServer, credentials, and sessionPersistence services plus the optional
deepseekAccount, agentDefaultModel, llm, and settings services. The browser half needs no npm
dependencies: React and react/jsx-runtime come from the DSH shared module table, and localization
rides the DSH locale service.
Development
git clone https://github.com/keltanas/dsh-platform-balance.git
cd dsh-platform-balance
node --test # 132 tests, no network required
node --check lib/*.js # syntax check
After editing lib/client.js, refresh the page: HMR rebuilds the bundle from the file's mtime.
Host-half edits are cached by Node after the first import and apply on the next dsh web restart.
Limitations
- Spend is an estimate, not billing; the DeepSeek price table and the OpenCode catalog can lag behind provider price changes.
- The OpenCode Go console status endpoint is an internal console API (it does not need browser
cookies when called with an API key, but it is not part of the documented public inference API).
If it becomes unavailable, the plugin still shows quota percentages from the public
/zen/go/v1/usageendpoint, without exact money amounts. - The account's prepaid Zen balance and any "Extra Usage" credit are not shown: the billing endpoint is cookie-authenticated and is not queried by the plugin.
- The published allowance table is a snapshot of the OpenCode docs; a new model not in it falls back to the plan base cap, and blended multi-model percentages are approximated by the current model's cap.
- A custom provider that proxies DeepSeek under an id without
deepseekin it is treated as a third party and is not billed; a custom provider id is never treated as OpenCode Go unless it is exactlyopencode-go. - A wallet whose currency has no CBR rate converts to
null(— ₽in the UI). - No balance history or "days left" forecast; the account-wide trailing-30-day spend is not shown because it spans billing periods, and the prepaid Credit balance is only available to browser cookies (the plugin does not read them).
- The day boundary follows the DSH host's time zone, not the browser's.
- A
link:install keeps the checkout path as a runtime requirement; a git install is self-contained. - The HTTP routes accept loopback hosts only; a non-loopback DSH bind exposes no balance API.
License
MIT — see LICENSE.
Comments
Loading…
Similar plugins
Account balance beside the Harness mark, per-session spend beside each Session row, and a running-session spend list for DeepSeek Harness (dsh).
★ 0
MIT
JavaScript
dsh plugin --profile web add dsh-balance-spendby The-five-stooges
Shows the DeepSeek account balance as a row in the sidebar footer with a refresh button, and opens a popover with the balance card, daily token and estimated-cost charts over a 7/30-day window, a per-
★ 0
MIT
JavaScript
Sep 18, 2026
dsh plugin --profile web add dsh-deepseek-usageDeepSeek balance and token usage panel for DSH, with official platform billing, a daily usage calendar, and local session-log estimates for all providers using editable per-model pricing.
★ 1
MIT
JavaScript
dsh plugin --profile web add deepseek-usageReal DeepSeek account balance and official spend tracker in the session header, with peak/off-peak badge, monetary alert with auto-stop, and one-click top-up.
★ 0
dsh plugin --profile web add dsh-balance-trackerby boy1141
Shows the DeepSeek account balance and unused bonus credit in the session header, refreshing every 20 seconds and whenever the window regains focus.
★ 0
MIT
JavaScript
Nov 7, 2026
dsh plugin --profile web add dsh-plugin-balance-chipby LZ-jun
Shows the DeepSeek account balance and the current peak / off-peak phase in the sidebar, and estimates per-session and per-turn cost using the official peak and off-peak rates.
★ 0
MIT
JavaScript
Oct 16, 2026
dsh plugin --profile web add dsh-balance-usage