dsh-openrouter-spend: Viewing actual OpenRouter spending in DSH

Preface

When using DeepSeek Harness (DSH) with OpenRouter for reasoning tasks, the standard token statistics within a session only reflect usage and do not directly map to the “actual amount deducted” from your OpenRouter account. Local estimates based on price lists often deviate from the actual billing. The following is an introduction to the community plugin dsh-openrouter-spend: it fetches total_usage (actual USD deduction) via OpenRouter’s native Analytics API to display daily spending, breakdowns by key/model, and summary information such as prepaid balances below the Composer and within Settings.

What is this

dsh-openrouter-spend is a Web-side plugin for DeepSeek Harness, maintained by RyabykinIlya. It is categorized as “Model Inference” in the SkillHub directory. The current npm version is 0.6.0, the license is MIT, and it requires Node >= 22.19.

The data source declared by the plugin is the billing result from OpenRouter’s official interface, rather than local tokens multiplied by unit price. The meaning of the numbers is clearly defined in the README: spending comes from total_usage grouped by UTC day, API key, and model via POST /api/v1/analytics/query; “Today” refers to the current UTC day; the balance is derived from GET /api/v1/credits as total_credits − total_usage.

Core Features

Spend Chip below Composer

A spend chip appears below the input box, displaying session/day: the current session’s spend for today on the selected API key, alongside the total spend for that key today. Both always correspond to the same key (see repository ADR 0006). The chip is displayed alongside the session’s token and context statistics.

Popover Details

Clicking the chip opens a popover where you can set time ranges and API key filters. It allows you to view per-model spending for the day, a daily bar chart for the selected window, as well as prepaid balance and lifetime spend. Starting from version 0.4.0, it includes credit-related alerts and display states for refresh failures; the README includes mockup descriptions for the limit-notice.

Settings → OpenRouter spend

Here you can save or clear the Management API key, select the display currency (USD, or RUB converted via cbr.ru exchange rates), set the refresh interval, and filter by API key. View preferences (display currency, filter by key, refresh interval override, credit warning toggle) are stored in the browser’s localStorage; credit warnings are disabled by default and must be manually enabled in Settings.

Quota and Balance Warnings (Optional)

When credit warnings are enabled, the popover will show the remaining limit for the tracked key: consumption ratio, estimated remaining duration at the current burn rate, and when the cap resets. The dot on the chip will change from amber to red as it approaches the limit, and a toast notification will appear when the severity level increases.

The account prepaid balance is judged by “runway”: alerts are triggered when the balance cannot cover three days at the account’s median burn rate (less than one day, or critical based on the last three-day average). The balance block in the popover provides statements like $6.58 left · under a day at this rate · shared by all keys and toasts a reminder to recharge (see ADR 0007, 0010).

One-click Key Limit Increase

The limit block and related toasts in the popover support increasing the spend limit for a key via the same Management key: increases are allowed up to a maximum of 10 times the current cap; keys without limits must be set on the OpenRouter side first. Suggested amounts vary based on consumption patterns; the display currency acts as a read-only echo (RUB echo is hidden if cbr.ru is unreachable). See ADR 0008.

Refresh and Multi-tab

The host side caches summaries based on refreshSeconds and merges concurrent refresh requests, ensuring that multiple tabs trigger only a single query to OpenRouter within the same refresh window. In case of a refresh failure, the last successful data is retained, and the popover displays the reason, a countdown to the next automatic retry (15 seconds after the first failure, then 30 seconds, followed by the regular schedule), and provides a Retry now option.

Installation and Activation

The runtime environment must be the DeepSeek Harness web profile; the plugin depends on the credentials, webServer, and connection services and will remain inactive in profiles without these services (e.g., headless).

Except for the Management API key, standard inference keys cannot be used for management interfaces; error example: 403 Only management keys can perform this operation. Management keys are created in the OpenRouter console under Settings → Management API Keys → Create New Key (see OpenRouter documentation).

Install from npm (web is the default Web GUI profile; replace the name if using a different profile):

dsh plugin --profile web add dsh-openrouter-spend

Install a specific tag from GitHub (pure JavaScript, no build required):

dsh plugin --profile web add github:RyabykinIlya/dsh-openrouter-spend#v0.6.0

Once installed, open Settings → OpenRouter spend and paste the Management API key.

Configuration Description

Each field can be overridden in the profile’s cordis.patch.yml; upon activation, the schema validates inputs and flags illegal fields. The table below is excerpted from the README; defaults and boundaries are subject to the repository.

Field Default Description (Summary)
credentialRef OPENROUTER_MGMT_API_KEY Credentials reference storing the Management key
apiBase https://openrouter.ai/api/v1 OpenRouter REST root URL
refreshSeconds 60 (10–3600) OpenRouter summary refresh interval (seconds)
historyDays 30 (2–366) Summary window history days (including today)
cbrUrl https://www.cbr.ru/scripts/XML_daily.asp RUB exchange rate source
rateRefreshSeconds 3600 (60–86400) Exchange rate reading interval
timeoutMs 15000 (1000–120000) Single request timeout for OpenRouter / cbr.ru
warnConsumedFraction 0.4 Period cap consumption fraction to trigger warning
criticalConsumedFraction 0.8 Fraction to trigger critical status
burnWindowDays 7 (1–30) Trailing days read when estimating runway

burnWindowDays is read by hour and by key; if it exceeds 5000 rows, the read is rejected rather than truncated. The runway estimation will report the rejection and point to this setting; reducing burnWindowDays is the fix. The 7-day and 30-day ranges cover at most historyDays days; to have a full 30-day window, historyDays must be kept at ≥ 30.

Use Cases and Notes

This is suitable for developers who are already using OpenRouter within DSH Web and want to see billing-consistent daily spend, model and key dimension analysis right next to the Composer, as well as manage Management keys and display preferences in Settings.

Before installing, it is recommended to review the GitHub repository source code and the MIT license independently. DSH plugins run under the current dsh process permissions; Management keys possess account management capabilities and should be stored securely via credentials references. Do not commit them to version control.

Community directories like SkillHub have no official affiliation with DeepSeek / High-Flyer. The plugin is published independently by the maintainer. DeepSeek Harness itself follows an “everything is a plugin” extension approach, and this plugin is one implementation focused on OpenRouter billing visualization.

Links

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye