Introduction¶
When using the dsh-go mobile App for model inference, developers often face two pain points: first, they cannot monitor the current session and overall usage in real time; second, it is difficult to quickly estimate costs, especially when switching models or using multiple service providers. Existing statistics often require manually checking logs or relying on third-party tools, which is neither intuitive nor timely.
dsh-go-usage-balance is a native plugin that integrates balance, token usage, and cost estimation into the App’s native interface by adding a status bar above the input box, a panel in the conversation “Plugins” tab, and a usage footnote at the bottom of each reply. All data is preferentially read from local session logs. Balance is queried only from the DeepSeek official API. No data is collected or uploaded, and there is no telemetry.
What It Is¶
dsh-go-usage-balance is a native plugin for the dsh-go mobile App, developed by maintainer yexin9. It provides balance querying, token usage statistics, and cost estimation. It supports DeepSeek models with peak/off-peak pricing color coding, remote pricing for GPT, Gemini, and other models, and has zero dependencies.
The plugin runs in the dsh-go bridge environment and requires dsh-go App 1.3.0 / bridge 0.4.0. It supports DSH versions 0.2.1-rc.2 through 0.2.x only.
Core Features¶
Status Bar Above the Input Box¶
Once the plugin is installed, a status bar appears above the input box, displaying cost and token counts for three scopes: current turn, conversation, and today. Format example:
本次¥0.08·对话¥2.60·今日¥1.06
Tapping the status bar opens the panel.
Panel¶
The panel contains a balance, a cost table, and a tokens table, grouped by current turn, this conversation, today, and the last 7 days. At the bottom of the panel are two buttons: “Refresh” and “Pricing”.
The “Details” section in the panel shows input/output/token cache/hit rate/request count for the current conversation and today, the current model’s pricing, and the last 8 turns of dialogue (including the model name for each turn).
Footnote on Each Reply¶
A footnote appears at the bottom of each reply, showing the input/output token count for that turn. Format example:
↑94k ↓65.8k
Color and Pricing¶
- DeepSeek models: green background during off-peak hours, orange background during peak hours.
- Other models: blue background.
- When pricing is unavailable: gray background.
DeepSeek model prices are calculated based on official peak/off-peak rates. Other model prices are fetched from pi-ai catalog, models.dev, LiteLLM, and OpenRouter, merged and deduplicated, displayed in USD, accumulated separately from RMB.
Language and Units¶
The panel follows the App’s language setting (caps.locale) to display in Chinese or English. Units, table headers, and tooltips all switch accordingly.
Data and Scope¶
Token Usage¶
- For the current session, it preferentially reads the engine’s existing
tokenUsageprojection (ctx.sessionProjections), consistent with other statistics scope. - For other sessions, it performs incremental statistics based on session logs, reading only files that have changed. Active session logs are decompressed only once, then accumulated via real-time events. A single log exceeding 16 MB will be skipped with a notification.
- Sessions unused for more than 8 days and not currently running are collapsed into a single summary (total, cost, turn count), without retaining per-turn details or deduplication sequences. When reopened, the summary serves as the baseline, and only new events are accumulated.
- Sub-agents count toward “today” but not toward “this conversation”. Dates are divided by the host’s local timezone.
Balance¶
- Preferentially reuses DSH’s account service (
ctx.deepseekAccount) to fetch balance. If the account is not logged in or times out (6 seconds), it falls back to the localDEEPSEEK_API_KEYto queryhttps://api.deepseek.com/user/balance. - Successful results are cached for 5 minutes. On API failure, it retries with exponential backoff, continuing to display the last known value in the meantime.
- Balances from other API providers (OpenRouter, new-api, etc.) are out of scope for this plugin.
Cost (Estimated)¶
DeepSeek models use official pricing. Other models use remote catalog pricing (USD).
DeepSeek prices are defined in the PRICES constant in lib/index.js. Modify this location when the official prices change. Custom models can also be added manually. The merged dataset contains approximately 7,200 entries and occupies about 4 MB of memory after loading. It is loaded only when a non-DeepSeek model is encountered.
Remote pricing is fetched from pi-ai catalog → models.dev (official providers preferred, resellers as fallback only) → LiteLLM → OpenRouter, merged and deduplicated across sources. Models not found in any catalog will display “Pricing not found” and will not count toward cost.
RMB and USD are displayed and accumulated separately, with no currency conversion. If the catalog provides a cache write unit price, it is included (e.g., Anthropic). Tiered pricing is estimated at the base tier. Public holidays are treated as business days, so peak-hour detection may be slightly inaccurate.
Polling and Stability¶
- Single timer + idle throttling: All views share one timer. When active, it polls every 15 seconds. After 2 minutes of inactivity, it automatically drops to 60 seconds. It starts when the first view appears and stops when the last one closes.
unref()ensures it does not prevent process exit. - Lifecycle cleanup: On plugin uninstall, the timer is cleared, subscriptions are discarded, and in-flight requests are aborted (
AbortController). No background tasks are left behind. After all views close, the subscription count drops to zero and the timer stops. - Refresh race condition: A manual “Refresh” aborts the in-flight balance request and forces a re-fetch. Results from stale requests are discarded by generation number, so they cannot overwrite newer values or cause request buildup.
- Caching and auto-update: Balance cached for 5 minutes; pricing cached for 24 hours (expired entries are auto-refreshed in the background by polling, or force-refreshed via the “Pricing” button); logs updated incrementally by mtime; catalog not re-scanned within 1 minute.
- Failure backoff: Balance starts at 30 seconds, doubling each time, capped at 10 minutes; remote pricing starts at 30 seconds, doubling each time, capped at 6 hours. At any given moment, only one request per type is in flight.
- No false positives: Balance distinguishes between “querying / temporarily unavailable / not configured”. Pricing distinguishes between “querying / not listed”. When a cached value exists, the old value continues to display. Missing balance fields or parse errors display “—”, never faking ¥0.00.
- Bounded fallbacks: Account service has a 6-second timeout; direct balance API has a 10-second timeout; pricing download has a 60-second timeout. After timeout, the failure backoff path is taken, preventing indefinite hangs.
Installation and Activation¶
The phone’s local engine ships with the dsh-go bridge built in. Install directly:
dsh plugin --profile web add github:yexin9/dsh-go-usage-balance
For remote hosts (servers / PCs), you must first install the bridge using the dsh-go installer, then install this plugin. Otherwise, the native UI will not appear.
After installation, switch hosts in the App (or restart the App) to trigger a plugin manifest re-read.
Update¶
dsh plugin --profile web add github:yexin9/dsh-go-usage-balance
Re-run the same command to pull the latest commit.
Uninstall¶
dsh plugin --profile web remove dsh-go-usage-balance
The cache file $DSH_HOME/cache/dsh-go-usage-balance/prices.json can be deleted directly.
Local Development Install¶
dsh plugin --profile web add /path/to/dsh-go-usage-balance
Typical Usage¶
- After installing the plugin, find the “Usage & Balance” panel in the “All Features” section or the “Plugins” tab of the conversation detail page.
- During a conversation, the status bar above the input box displays cost and token counts for the current turn, conversation, and today. Tap to open the panel.
- In the panel, review the balance, cost tables, and details. Observe model pricing and the last 8 turns of dialogue.
- A token footnote appears at the bottom of each reply for quick reference of that turn’s input/output volume.
- When switching models, the panel immediately recalculates prices and costs for the new model. DeepSeek models will change color based on peak/off-peak pricing.
- Tap the “Pricing” button to force a re-fetch of the remote pricing catalog.
Applicable Scenarios and Notes¶
- Suitable for users who need real-time visibility into usage and cost in dsh-go, with multi-model switching support.
- The plugin runs with the current dsh process permissions. Review the source code and license (MIT) before installing.
- Only supports the dsh-go bridge environment. The native UI will not display when connected via DSH Remote.
- Costs are estimates and may differ from official billing. Sources of discrepancy include cache reads/writes, peak hours, holidays, tiered pricing, and reseller markups.
- If the older
local-usage-balanceplugin is also installed, two status bars will appear. Uninstall the older version.
In Summary¶
dsh-go-usage-balance integrates balance querying, token usage statistics, and cost estimation into the dsh-go native interface. Data is preferentially read locally, balance is queried only from the DeepSeek official API, multi-model pricing catalogs are auto-updated, making it ideal for inference scenarios where real-time usage and cost tracking on mobile is needed.
- Plugin directory page: https://www.skillhub.cn/plugins/yexin9/dsh-go-usage-balance
- GitHub: https://github.com/yexin9/dsh-go-usage-balance