dsh-key-balance
A native-looking DeepSeek API balance indicator for the DeepSeek Harness (DSH) message composer.
The chip sits in the composer control row, immediately before the Send button, and shows the remaining funds of the DeepSeek API key already configured in the current DSH profile — for example Balance: $12.45. It refreshes once a minute, on tab focus, and on click. Hover or focus reveals the full breakdown: total, granted and topped-up amounts, the last successful update time and whether the funds are available.


Repository: github.com/LabrotWOW/dsh-key-balance.
Features
- Inline, not a panel. Registered through the public
conversation.input.rightslot and styled only with DSH theme tokens, so it follows light and dark themes, fonts and spacing. It never covers the send, attach or input controls. - Official balance only. Calls
GET https://api.deepseek.com/user/balancewithAuthorization: Bearer <key>; no model is involved, so checking the balance costs zero tokens. - The key never leaves the Host. It is resolved per request through the DSH
credentialsservice and never sent to the browser, logged, copied or written to disk by the plugin. The client receives numbers, a currency code, an availability flag and a timestamp. - Honest states. Loading, low funds, rejected key, missing key, unsupported provider, rate limit, timeout and network errors each have their own label. A failed refresh keeps the last successful value on screen; without one it shows
Balance: —, never a fabricated zero. - Localized. English, Russian and Simplified Chinese UI strings follow the DSH interface language.
- No background waste. One request at startup and one per minute; typing or sending a message does not trigger requests. Manual refresh is rate-limited to once every 3 seconds, concurrent requests are coalesced and a 10-second cache absorbs tab switches.
Install
Directly from GitHub (recommended — no npm account or registry step needed):
dsh plugin add github:LabrotWOW/dsh-key-balance
If the package is published to npm later:
dsh plugin add dsh-key-balance
Then refresh the DSH window. The chip appears in the composer as soon as a DeepSeek API key is configured for the official provider.
For a local checkout during development, install the bundle folder from the Plugin Manager or with the DSH tool:
plugin_manager action=install_bundle target="<absolute path to this folder>"
To temporarily disable the plugin:
plugin_manager action=set_plugin target=dsh-key-balance enabled=false
Requirements
- DSH
0.2.2-rc.5or newer within the0.2.xline (declared inengines.dsh). - The active model provider must be the official DeepSeek API route (
deepseek-official) with its base URL onhttps://api.deepseek.com. - A configured API key, normally
DEEPSEEK_API_KEYin DSH credentials. If the provider uses a different key variable, the plugin follows it automatically.
Configuration
None. The plugin reads the active provider configuration and the matching credential reference; there are no settings to fill in and no key to re-enter. This is deliberate: the key stays wherever DSH already stores it.
States
| Situation | Chip |
|---|---|
| First load | Balance: … with a small spinner |
| Success | Balance: $5.22 (symbol derived from the currency) |
Low balance or is_available: false |
Warning color, low-funds note in the tooltip |
| Key rejected (401/403) | Balance: no access plus an explanation |
| Key not configured | Balance: not configured |
| Third-party provider or proxy | Balance: unsupported |
| Network error or timeout | Balance: —; the last successful value stays dimmed |
| Rate limited (429) | Balance: rate limited |
| Empty or malformed response | Balance: error |
The tooltip is measured against the chip rectangle and promoted to the browser top layer (Popover API), so the docked composer cannot clip or cover it; without that API it degrades to a fixed overlay anchored to the chip.
Security and privacy
- The balance request runs inside the DSH Host process. The plugin never receives the raw key on the client side and never sends it anywhere except
https://api.deepseek.com/user/balance. - Requests are made only for the official
deepseek-officialroute whose base URL origin is exactlyhttps://api.deepseek.com. Other providers and proxies are reported as unsupported until the provider owner explicitly adds support; nothing is guessed or probed. - Error messages are sanitized: no key fragment, request headers or raw response body is logged or returned.
- No telemetry, analytics, remote configuration or auto-update channel. The only network destination is the official DeepSeek balance endpoint.
- The client talks to the Host over a private, authenticated DSH connection channel; the channel accepts only the
balanceendpoint with an optionalforceflag.
See SECURITY.md for the full threat model and reporting instructions.
How it works
Client (web) Host (DSH)
conversation.input.right
└─ BalanceIndicator ── RPC "balance" ──▶ queryBalance()
(60 s timer, click) ├─ settings.describe() → provider + base URL + apiKeyEnv
├─ credentials.resolve(apiKeyEnv)
├─ GET https://api.deepseek.com/user/balance
└─ { currency, total, granted, topped-up, available, checkedAt }
index.js— Host half: provider guard, credential resolution, request timeout, cache, single-flight and the RPC handler mounted on the connection service.client.js— Client half: the slot registration, the chip, the tooltip and the refresh lifecycle.locale/*.json+detail/DETAIL*.md— Plugin Manager metadata in English, Russian and Chinese.
Compatibility and limitations
- Only the official DeepSeek API route is supported. The DSH account (OAuth) route and third-party providers are intentionally not queried because they do not share this endpoint.
- The endpoint is called with
Authorization: Bearer, as documented by DeepSeek for account APIs; chat requests usex-api-keyinstead. - The layout targets the public composer slots. A future DSH redesign may require a slot update; the plugin does not use DOM selectors or layout hacks.
- Currencies
USD,CNYandEURhave symbols; any other currency is shown by its ISO code.
Development
Requires Node.js 22+ (no runtime dependencies).
node --check index.js
node --check client.js
node scripts/host-test.mjs # Host statuses, caching, key non-disclosure
node scripts/client-test.mjs # state table, currencies, slot and style registration
npm test # all checks above except the real request
npm pack --dry-run # inspect the publish tarball
scripts/host-test.mjs and scripts/client-test.mjs are dependency-free; run them locally with npm test. The published npm archive contains only the runtime files listed in files.
License
MIT © dsh-key-balance contributors. See LICENSE.
还没有评论,来写第一条。