Introduction¶
Developers using DSH (DeepSeek Harness) to connect to the DeepSeek API usually have to answer two questions: how much balance is left in the account, and how many tokens were actually consumed during this period. The former requires checking the DeepSeek platform console, while the latter either involves browsing through conversation logs to calculate manually or relying on estimation—yet DeepSeek does not have a public usage interface (testing /user/usage returns 404), making estimates unreliable.
dsh-api-balance implements these two tasks as a module within the DSH settings panel: balance and availability are queried directly via the official interface, while token usage is aggregated from real usage data in local session logs. Throughout the process, the API Key exists only on the backend; the browser only receives the balance data.
Below, we introduce its features, principles, installation methods, and notes.
What is it¶
dsh-api-balance is a DSH plugin maintained by gaozhiwei521, version 0.1.0, under the MIT license. It focuses on a specific task: adding an “API Balance” module to the DSH “Settings” panel to query the account balance, availability, and real Token usage of the configured provider (DeepSeek) in real-time, supporting manual refresh.
Core Features¶
- “Settings → API Balance” interface: Large available balance number + availability status badge + usage card (cumulative/today Tokens, session count, usage log), supports manual refresh.
- Usage is real data: Consumption data comes from the real token usage of each call in the local session logs (input/output/cache/inference), not estimation.
- API Key exists only on the backend: The browser only gets balance data.
- Automatic hiding: Automatically hides the bonus balance item when the account has no bonus balance (0).
- Theming: Styles use global
--dsw-alias-*theme tokens, consistent with the dark theme.
How It Works¶
The plugin is divided into front-end and back-end layers:
| Layer | Implementation |
|---|---|
Backend lib/index.js |
Registers two routes: GET /dsh-balance/query reads DEEPSEEK_API_KEY via credentials.resolve(), calling {baseURL}/user/balance; GET /dsh-balance/usage aggregates real token usage from local session logs, with 60s caching. |
Frontend lib/client.js |
Registers settings.section slot (id is api-balance, label is “API Balance”), rendering the balance, status, and usage interface. |
baseURL and apiKeyEnv follow the override of the llm-deepseek configuration segment in “Settings → Models”. If you have modified the Key reference or baseURL in the model settings, the plugin will automatically follow them without requiring additional configuration.
Installation and Enabling¶
The plugin is declared as a DSH bundle (patch points to ./extensions/dsh/cordis.patch.yml, client platform is web), and it is recommended to use the native DSH plugin command to install it to the web profile from GitHub:
dsh plugin --profile web add github:gaozhiwei521/Deepseek-Harness-Api-monitor
After installation, you need to restart DSH (exit “DSH Chat” and reopen it), and then you can see the interface in “Settings → API Balance”.
Migration Note: If you previously used the manual Copy-Item installation method below, please first remove the api-balance insert block in cordis.patch.yml and delete ~\.dsh\profiles\node_modules\dsh-api-balance\ to avoid duplicate registration with the bundle.
Manual Installation and Uninstallation¶
After DSH upgrades, the plugin might be lost; at this point, you can use the old manual installation method:
# 1) Move the package to profiles\node_modules
Copy-Item 'E:\deepseekwork1\dsh-api-balance\package.json' "$env:USERPROFILE\.dsh\profiles\node_modules\dsh-api-balance\" -Force
Copy-Item 'E:\deepseekwork1\dsh-api-balance\lib' "$env:USERPROFILE\.dsh\profiles\node_modules\dsh-api-balance\lib" -Recurse -Force
# 2) Confirm that the end of cordis.patch.yml has the api-balance insert block (re-append if upgrade overwrote it)
# 3) Restart DSH (exit "DSH Chat" and reopen; or kill the backend process and let the desktop watchdog restart it)
The commands above copy package.json and the lib directory to DSH’s profiles directory, then manually confirm the patch file and restart to take effect.
Uninstalling only requires one command:
dsh plugin --profile web remove dsh-api-balance
If installed via the old manual method, uninstallation involves three steps: 1. Delete the api-balance insert block in cordis.patch.yml; 2. Delete ~\.dsh\profiles\node_modules\dsh-api-balance\; 3. Restart DSH.
Testing¶
There are two sets of tests in the source code directory, covering backend logic and frontend module structure respectively:
node 'E:\deepseekwork1\dsh-api-balance\test\unit.test.mjs' # Backend logic (13 items)
node 'E:\deepseekwork1\dsh-api-balance\test\client-load.test.cjs' # Frontend module structure
Applicable Scenarios and Notes¶
Suitable users: Developers who connect to the DeepSeek API in DSH and want to see balance and consumption directly in the interface, without logging into the platform console or trusting estimates.
Notes before use:
- Only supports the DeepSeek official account balance interface; balance interfaces for other vendors are not yet integrated.
- Defaults to reading
DEEPSEEK_API_KEY; if you have changed the Key reference or baseURL in “Settings → Models”, the plugin automatically follows. - After installation, DSH must be restarted to see the interface in “Settings → API Balance”.
- The plugin runs with the current dsh process permissions and will read local credentials (e.g.,
DEEPSEEK_API_KEY) and local session logs. It is recommended to review the source code and license (MIT) yourself before installation to ensure reliability.
Summary¶
dsh-api-balance solves a very specific problem: viewing DeepSeek account balance and real token consumption without leaving DSH, while the Key stays on the backend. If you are using DSH to connect to DeepSeek, you can give it a try.
- Directory page: https://www.skillhub.cn/plugins/linshufan21/dsh-Api-monitor
- GitHub: https://github.com/gaozhiwei521/Deepseek-Harness-Api-monitor
Final note: The directory page above is an independent site maintained by the community and has no official affiliation with DeepSeek / Fanghu.