Saltar al contenido principal
L

sapi-budget

lanstzz/sapi-budget

Cost display for AiSpot (sapi) relays: crawls the provider's group list from its public pricing endpoints instead of hardcoding it, lets you pick the active group from a dropdown in the conversation header, and shows a per-turn cost at the end of each turn plus a session total that recurses through every subagent subtree. Switching groups re-prices all history instantly, because the host publishes token buckets only and the browser applies the live rates.

Instalar

dsh plugin --profile web add github:lanstzz/sapi-budget

README

sapi-budget

A DeepSeek Harness plugin that syncs the per-group model prices from an AiSpot (sapi) deployment and shows what each conversation costs — a session total in the conversation header and a per-turn cost at the end of every assistant turn.

The group list is crawled from the provider, never hardcoded, so it follows the provider as groups appear and disappear. You pick the active group from a dropdown in the conversation header, and every historical number is re-priced immediately — no reload, no replay.

What it shows

  • Session total in the conversation header, including every descendant subagent (subtree(s) = own(s) + Σ subtree(children)).
  • Per-turn cost at the end of each assistant turn.
  • A hover breakdown listing the model, the tokens per bucket, and the total.

Money is never published by the host. The projection carries token buckets only, and the browser prices them against the live catalog — that is what makes a group switch re-price history instantly.

Install

dsh plugin add github:Lanstzz/sapi-budget

Or from a local checkout:

dsh plugin add /absolute/path/to/sapi-budget

Then restart the app: the bundle is loaded at startup.

Runs on macOS, Windows and Linux. There is no platform branch anywhere in the plugin: the host half is plain JavaScript that registers routes and a session projection and writes nothing to disk, pricing comes from public HTTP endpoints, and the stored group choice lives in the browser's localStorage. The UI uses only theme tokens, so it follows the host's light and dark palettes.

Configuration

All optional. Set them in your profile patch (cordis.patch.yml):

- id: sapi-budget
  name: 'dsh-sapi-budget'
  config:
    baseUrl: https://aispot.swj0227.icu   # any compatible deployment
    group: ''                             # '' = let the provider pick the cheapest
    currency: USD
    refreshMinutes: 30

The group is normally chosen in the UI and persisted in the browser's localStorage (sapi-budget.group); the config value is only a fallback.

Pricing data

Three public, unauthenticated endpoints on the provider:

EndpointUsed for
/api/pricingmodel list, ratios and tiered_expr expressions
/api/statusquota unit and exchange rate
/api/user/groupsgroup names and per-group ratio multipliers

Tiered expressions are evaluated by a hand-written tokenizer and recursive-descent parser in pricing.js. There is no eval and no new Function.

Accuracy notes

  • Tiered models are marked as estimates (估算 / estimate) in the UI.
  • A subagent's spend is priced at the root session's model rate, because cross-session model attribution is not available on the host side. Those rows are labelled as estimates too.
  • Subagents that finished before the plugin was installed have no readable projection. They are reported as unknown, never as $0.00.

Layout

FileRole
index.jsHost half: pricing service, three HTTP routes, the sapiCost session projection, and the sapi_price agent tool
client.jsBrowser half: the two slot entries, the group picker, and the tooltip bubble
pricing.jsCatalog fetching and the tiered_expr evaluator
test/45 host tests + 59 client tests
probe-tooltip.mjsStructural check that the breakdown does not ride on a native title

Development

node --check index.js && node --check client.js && node --check pricing.js
node --test test/index.host.test.js   # 45 pass
node --test test/client.test.js       # 59 pass
node probe-tooltip.mjs                # exit 0

HANDOFF.md records the architecture decisions and the traps that cost real time (including why the cost breakdown must never be a multi-line native title on macOS).

Licence

MIT — see LICENSE.

Plugins relacionados