dsh-provider-quote: Query current provider balance and model unit price in DSH

Preface

When switching model providers or relay stations in DSH, two practical problems often arise: how much balance remains in the account, and roughly what is the price per token for the currently selected model. This information is often scattered across various vendor consoles, the OpenRouter catalog, or cc-switch’s “Provider Inquiry” scripts, and the conversation interface itself does not aggregate and display it.

miku05231’s dsh-provider-quote integrates similar capabilities directly into DSH: querying balances and unit prices for the currently active provider. The approach references cc-switch’s “Provider Inquiry” but is implemented as a DSH plugin attached to the host API and Web client.

What is this

  • Name: miku05231/dsh-provider-quote (npm package name @local/dsh-provider-quote)
  • Maintainer: miku05231
  • Category: Network Tool (SkillHub Directory)
  • Version (package.json): 0.4.0; License MIT
  • DSH Engine Requirement: >=0.2.0-rc.2

The plugin answers three types of questions, with data sources clearly mapped in the README:

Question Data Source
How much money do I have left? Automatically dispatches vendor balance adapters based on baseURL, or configures a usage_script compatible with cc-switch
How much is this model? OpenRouter public price catalog https://openrouter.ai/api/v1/models (USD / 1M tokens), can be overridden locally with priceOverrides
Which models can I use? Provider’s OpenAI-compatible GET /models

Core Features

Host Side: Inquiry Engine and HTTP Routes

The host portion of the bundle contains pure inquiry logic (lib/pricing.js) and DSH integration (lib/host.js). Agents can ask for prices directly via the tool provider_quote, for example:

  • provider_quote() — Default scope
  • provider_quote({ all: true }) — All providers
  • provider_quote({ provider: 'openrouter' }) — Specified provider
  • provider_quote({ models: true }) — Model-related

External HTTP routes include:

  • GET /api/provider-quote/summary (?refresh=1 skips the ~30s quote cache)
  • GET /api/provider-quote/refresh (Same as above, path alias)
  • GET /api/provider-quote/ping — Self-check version, module URL, number of catalog cached models

Optional query parameters: scope=session|default, sessionId, provider, model. When scope=session&provider=… is provided, “In Use” corresponds to the session’s model selection; if only sessionId is provided or no model is selected, it follows the global default for a new session.

Client Side: Capsule and Settings Page

client.js mounts UI in two places, sharing the same store to avoid duplicate requests:

  1. Below the conversation input box (slot conversation.composer.dock): A persistent capsule, e.g., ● Balance 12.4 USD, displaying only the balance of the provider selected in the current session; switching providers in the model selector switches it immediately; clicking triggers an immediate re-inquiry (?refresh=1); silent refresh every 5 minutes. Hovering reveals the provider, source (Current Session / Global Default), and failure reasons.
  2. Bottom of Settings → Models page (slot settings.models.footer): Current provider balance, current model unit price, overview of other providers, with a “Refresh Inquiry” button (The settings page has no session context and follows the global default).

Session Selection vs. Global Default

In DSH, “Current Provider” has two sets of semantics, which the plugin handles separately to avoid “the capsule shows A, but the refresh checked B”:

  • Session Selection: Each session’s modelSelection (next ?? lastUsed), used for the input box model selector and the capsule.
  • Global Default: agentDefaultModel.currentSelection(), which only determines the default model for new sessions; the settings panel, provider_quote tool, and sessions where no model has been selected follow this path.

Display always follows the current session; clicking refresh passes scope=session&sessionId=…&provider=…&model=… to the host.

Balance Adapters

When adapters: auto (default), it prioritizes the host of baseURL, followed by sequential fallbacks; failures log the attempted URLs and HTTP status. Built-in IDs include openrouter, deepseek-official, relay-user-balance, one-api, new-api, openai-billing, as well as script:<host> (paste cc-switch’s usage_script, supports {{baseUrl}} / {{apiKey}}).

Scenarios involving relay stations, New API, etc., are specifically explained in the README: For example, New API using only an API key to query balance might get a 401 or misread the “unlimited quota” placeholder value 100000000; starting from v0.4.0, after identifying the placeholder value, it only reports the actual “used”, and for accurate balance, accessTokenEnv needs to be configured to point to the panel access token (profile:read).

Unit Price and Price Catalog

Model IDs are matched sequentially by priceOverrides, OpenRouter slug, full ID, bare name, and normalized name; if no match is found, it labels “Price not matched” and provides up to 3 catalog candidates, without guessing. The catalog defaults to a 6-hour cache (catalogTtlMs); upon fetch failure, it retains the last successful catalog and marks it stale.

Provider Source: Automatically scans configurations in profiles with providers: { id: { baseURL, apiKeyEnv, models } }; apiKeyEnv is resolved via ctx.credentials and plaintext is not persisted; it can also be supplemented using the plugin’s own config.providers; built-in mappings like deepseek-official → https://api.deepseek.com.

Installation and Enablement

The installation method comes from the README; you need to use plugin_manager in the session to specify the workspace directory (do not manually write package.json or run pnpm in the profile directory):

plugin_manager action=install_bundle target=<Absolute path to this plugin, e.g., ~/dev/dsh-provider-quote>

After installation, check the returned application and warnings: applied indicates it is active. DSH must be restarted after host code changes to load the new code.

Configuration is written in the config of the plugin line in cordis.patch.yml. Common keys include:

Key Default Meaning
enabled true Turn off the entire line
adapters auto 'auto' or array of adapter IDs
timeoutMs 12000 Single HTTP timeout
catalogTtlMs 21600000 Price catalog cache (6h)
autoRefreshMinutes 0 Background preheating interval, 0 is off
scripts {} host → cc-switch compatible scripts

Typical Usage

Agent Tool Inquiry (In a DSH session where the plugin is installed and enabled, called by the agent):

provider_quote()
provider_quote({ all: true })
provider_quote({ provider: 'openrouter' })
provider_quote({ models: true })

Custom Balance Script (Same format as cc-switch, written into scripts):

scripts:
  relay.example.com: >-
    ({ request: { url: "{{baseUrl}}/user/balance", method: "GET",
                  headers: { "Authorization": "Bearer {{apiKey}}", "User-Agent": "cc-switch/1.0" } },
       extractor: function (response) { return { isValid: response.is_active || true, remaining: response.balance, unit: "USD" }; } })

New API Accurate Balance (Example field names from README):

providers:
  xianapi-ds:
    baseURL: https://www.xianapi.cloud/v1
    accessTokenEnv: XIANAPI_DS_ACCESS_TOKEN

Unit Price Anchoring (Write according to candidates when no match is found):

priceOverrides:
  deepseek-flash: { openrouterId: deepseek/deepseek-chat }
  my-local-model: { input: 0.3, output: 0.9, cacheRead: 0.03, cacheWrite: 0.4 }

Browser / Client: Use the capsule below the input box for daily balance checks of the current session; use the bottom panel of Settings → Models page to view all providers and unit prices. If necessary, click “Refresh Inquiry” or trigger refresh=1 via the capsule.

Applicable Scenarios and Notes

Suitable for developers who long-term use multiple providers, relay stations, or OpenRouter in DSH: Quickly confirm balance before conversation, compare with OpenRouter reference prices when selecting models (use priceOverrides to align with actual payment if relay stations have multipliers).

Please note before use:

  • The plugin runs with the permissions of the current DSH process and will initiate external HTTP requests based on configuration and use ctx.credentials to resolve API keys / access tokens; before installation, you should read the GitHub Repository source code and MIT license to ensure credential naming and outbound requests comply with your security policy.
  • Unit prices come from the OpenRouter public catalog and are only for reference for relay stations; balance interfaces vary by vendor. When unable to query, the README requires providing explainable failure information rather than silent blanks.
  • The SkillHub directory page and GitHub are maintained by the community and have no official affiliation with DeepSeek / Hithink RoyalFlush; star counts and other metadata are subject to the directory (currently GitHub stars are 0).

Conclusion

dsh-provider-quote integrates “how much remains in the current provider and roughly what is the price of the model” into the DSH interface and the provider_quote tool, and aligns with cc-switch inquiry scripts and the OpenRouter catalog, reducing the need to switch back and forth between consoles and documentation.

  • Directory Page: https://www.skillhub.cn/plugins/miku05231/dsh-provider-quote
  • GitHub: https://github.com/miku05231/dsh-provider-quote
羽毛球分组比赛记分
小程序二维码

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

Xiaoye