Introduction¶
The dedicated API Key for Token Plan (prefixed with sk-sp-) can only invoke models and cannot query quota; the console also has no publicly exposed quota endpoint. This plugin reuses your already-authenticated official CLI, reads the output of bl usage token-plan --output json, and simultaneously aggregates local DSH session statistics for Token Plan usage.
Features¶
Toolbar Capsule¶
A single capsule in the toolbar displays the plan usage percentage to two decimal places. The color changes with usage: green below 50%, amber 50–70%, orange 70–90%, red ≥90%. When the plan is expired, the user is not logged in, or data cannot be read, the capsule is hidden entirely and takes no space.
Click Popover¶
Clicking the capsule opens a popover showing local Token usage (total / call count / model count / stats window) plus plan quota (used / remaining / reset time / countdown). Press Esc or click outside to dismiss.
Per-Model View¶
The Settings page has a row of model chips (All Models or individual toggles). You can also switch filters in place by clicking “Model Count” inside the popover. Totals, call counts, and the bar chart all follow the active filter.
Settings Page Charts¶
Settings → Bailian Quota: the stats window is selectable from Today / Last 7 Days / Last 30 Days / This Month / Last Month / Custom Date. A three-segment stacked bar chart (cache hit / cache miss / output) shows daily breakdown on hover. The plan quota card includes a progress bar and detail rows.
Auto-Refresh¶
Both the panel and the popover re-read every 60 seconds (Token counts grow with conversation); they also refresh immediately when the window becomes visible again.
Installation¶
Prerequisite: log in to the Bailian CLI.
npm i -g bailian-cli
bl auth login # browser login; or bl auth login --open-api for AK/SK
bl usage token-plan --output json
As long as it outputs {"per1MonthPercentage":…,"per1MonthResetTime":…,"hasQuotaData":true}, you’re good.
Method 1: Install from GitHub (recommended)
In DSH’s “Plugins → Add Plugin”, enter:
github:KNtnx/dsh-bailian-quota
Or via command line:
dsh plugin --profile web add github:KNtnx/dsh-bailian-quota
Method 2: Local directory
git clone https://github.com/KNtnx/dsh-bailian-quota.git
dsh plugin --profile web add link:./dsh-bailian-quota
Replace web with your actual profile (Desktop edition usually uses desktop). After installation, restart dsh web.
Two Data Sources¶
| Metric | Source | Notes |
|---|---|---|
| Used / Remaining / Reset | bl usage token-plan |
The console only returns the ratio and reset time, not raw token counts |
| Total tokens / Call count / Model count / Daily chart | Local DSH statistics | Replays request/header and assistant/message entries from $DSH_HOME/sessions/**/session.v4.jsonl.zstd, only accumulating qwen-token-plan* routes |
Therefore, token counts reflect “Token Plan calls made from this machine via DSH” — they are not the console billing figures and do not include other clients; the UI labels this as DSH Statistics.
On Read Failure¶
If bl loses login, is uninstalled, times out, or returns malformed output — the capsule will not silently freeze on stale numbers:
- The capsule retains the last read percentage, but the status dot turns red with a
!badge; hovering shows the reason; - The popover and Settings page display a notice bar in the “Plan Quota” section (e.g., “bl is not logged in or the session has expired” + “Data frozen at 2026-11-21 20:09” + a Retry button); the full message is available in the bar’s
titleattribute; - After network recovery or re-running
bl auth login, the next poll (≤30 s) or a click on “Retry” restores normal display.
Configuration¶
| Setting | Default | Description |
|---|---|---|
DSH_BAILIAN_BL |
Auto-detect | Explicit path to the bl binary (used when not found in PATH, ~/.local/bin, /usr/local/bin, or fnm install dirs) |
| Stats window | Last 7 Days | Selected in Settings; stored in browser localStorage (dsh.bailianQuota.window); the popover follows read-only |
| Refresh | 60 s | Quota cache TTL is 60 s; the ↻ button in the popover corner and “Refresh” in Settings force a re-read |
Privacy¶
- Only executes
bl usage token-plan --output jsonand reads local session logs; - Session logs are incrementally cached by file mtime under
$DSH_HOME/storages/bailian-quota/; nothing is uploaded; - Both HTTP routes accept loopback requests only;
- Does not read
~/.bailian/config.jsonand never touches the API Key.
Troubleshooting¶
| Symptom | Action |
|---|---|
| Capsule not showing | Plan expired, bl not logged in, or the console did not return hasQuotaData. Run bl usage token-plan once to verify |
| Numbers not updating | Cache is 60 s; click ↻ or “Refresh” in Settings. If still stuck, restart dsh web |
| Token usage always 0 | Only qwen-token-plan* routes are counted; confirm the current session is using this provider |
bl not found |
Install bailian-cli, or set DSH_BAILIAN_BL=/path/to/bl |
Development¶
node --check index.js
node --check client.js
dsh plugin --profile web add link:$(pwd)
Plugin file layout:
package.json: plugin manifest (dsh.bundle.patch+dsh.client)cordis.patch.yml: host-side line insertionindex.js: host side — bl CLI read, session replay, HTTP routesclient.js: browser side — capsule, popover, settings page, chartslocale/: marketplace display stringsdocs/DETAIL.md: plugin detail page
License¶
This repository is licensed under the MIT License.