Skip to main content

TokenLedger

123Stars10Forks1Issues2Watchers

Automatically categorizes DSH Web request transit stations and project ownership. Tracks token usage, balance, and subscription quotas. Zero configuration, no credentials required.

Evidence5/5methodologySourceInstallMaintenanceDSH versionSecurity scan
Machine-auditedInstall commandRepo verifieddsh-plugin topicLicenseREADMEAI wiki
Language
JavaScript
License
MIT
Branch
main
billingdeepseek-harnessdsh-pluginnewapisub2apitoken-usage

Install

cmdweb profile
$ dsh plugin --profile web add dsh-tokenledger

Run the command above in your terminal to install this plugin via the dsh CLI. You can switch Profile in the top-right corner. New to dsh? Read the beginner tutorial

Install via your agent

Install the DeepSeek Harness plugin zh667/TokenLedger for me: review the repository at https://github.com/zh667/TokenLedger first, then run the install command and verify the plugin loads successfully.

Paste this instruction to the DSH Web GUI assistant — it will install and verify for you.

One-Line Positioning

Categorize DeepSeek Harness Token usage by actual service request relays, with balance, subscription quotas and project-level statistics; ready to use out of the box, requiring neither relay address configuration nor any new credentials.

Core Features

  • Relay Attribution: Normalize origins by provider's baseURL for grouping; multiple keys under the same relay are automatically consolidated into one row, with the relay name being the actual domain rather than your custom routing alias
  • Project Attribution: Group by the directory where the session was started; if the host workspace has a title, use that; otherwise use the directory name; sessions created in subdirectories are also counted
  • Auto-Discover Relays: Read baseURL from host's provider configuration; no need to re-enter in the plugin; read-only, never accesses credentials nearby
  • Multi-Vendor Balance Reading: Covers DeepSeek, New API family, Sub2API, Moonshot/Kimi, Zhipu GLM / Z.ai, OpenRouter and other account types; one regular API key per vendor is sufficient
  • Subscription Quota Windows: "Plan-selling" vendors like OpenCode Go, Kimi For Coding, MiniMax Coding Plan, Z.ai Coding Plan are displayed as independent windows for 5 hours/day/week/month, each with progress bar and reset time
  • Export & Diagnostics: CSV/JSON export of usage, index health, unassigned rows shown separately, cost estimation bucketed by effective date

Technical Implementation

  • Language: JavaScript (ESM Node.js)
  • Key Dependencies: One optional peer dependency @deepseek-ai/schemastery (for registering settings namespace); runtime uses only Node built-in node:sqlite, native fetch and node:module, zero external runtime dependencies
  • Architecture Pattern: Dual-end Cordis plugin; node end registers via cordis.patch.yml and mounts with sessionPersistence as required dependency, webServer (compatible with old name httpServer) waits via nested ctx.inject; browser end injects sidebar footer slot sidebar.footer.action with hand-written __ModuleLoader__ bundle, React provided by host
  • Entry Files: src/index.js (Cordis entry apply/inject/name) + src/plugin.js (core implementation) + cordis.patch.yml (bundle patch)

Use Cases

DSH Web users who want to directly answer "Which relays/projects did this month's Tokens go to, what's the remaining balance for a specific relay, when does the subscription reset" and don't want to fill in extra configuration or manage extra keys for usage statistics. Especially suitable for users who have configured multiple relays, grouped multiple keys for the same relay, or are using plan-selling accounts like Sub2API / OpenCode Go.

Prerequisites & Compatibility

DependencyMinimum VersionDescription
DeepSeek Harness (DSH)>= 0.1.0-rc.6Plugin verified under this version's host web profile; older latest tag points to earlier 0.0.1-rc.x line with different service names
Node.js>= 22Runtime uses Node built-in node:sqlite; v22 issues ExperimentalWarning, upstream hint not suppressed by this plugin
PlatformCross-platformTested on macOS / Windows / Linux; Windows verified loading from published tarball, scanning real session logs under $DSH_HOME, panel rendering in session flow
Native Modulenode:sqliteNode built-in module, no C++ compilation dependency; loaded via dynamic import; missing only loses settings namespace registration capability

Installation

dsh plugin --profile web add github:zh667/TokenLedger

Configuration Options

ConfigTypeDescriptionDefault
relaysRoute name → URL or objectOnly fill when auto-discovery fails; key is DSH provider route name, value can be bare URL or {baseUrl,id,displayName,type} objectNot set; auto-discover from host
officialOriginsString arrayList of origins marked as vendor official domains rather than relays, to distinguish "direct" vs "relay"[]
endpointsArrayBalance interface declarations for non-built-in vendors; see "Custom Endpoints" below[]
fingerprintBooleanWhether to actively detect which stack each relay runs; off by default, probes on first balance check if neededfalse
databaseStringSQLite index file path; defaults to tokenledger.sqlite in host home directory via patchtokenledger.sqlite
sweepIntervalMsNumber (ms)Interval for background session log scanning, 0 to disable timer60000
sweepOnStartBooleanWhether to scan immediately on startuptrue
ratesAnyRate table for cost estimation; format in pricing.js; unset models show dash instead of 0Not set

Custom Endpoints (endpoints array) fields:

FieldDescription
originMust be the same origin as a configured provider; used as key to look up that account
displayNamePanel display name
pathMust be absolute path starting with single slash; protocol-relative URLs like //host/x are rejected
rawWhen set to true, sends bare key without Bearer prefix
fieldsValue paths (dot notation) for each data item in response JSON, e.g., total: data.balance
windowsSubscription quota window list, each item containing kind and value paths

Boundaries enforced in code: GET only, no request body, no declarable credentials, cross-origin redirects fail directly, response body has size limit and timeout, custom endpoints cannot override built-in reading methods.

FAQ

Q: Do I need to restart dsh web after installation?

A: Yes. After installing, upgrading or uninstalling, you must restart the running dsh web, then do a hard refresh in the browser for the "Usage Ledger" entry to appear at the sidebar footer.

Q: What are the commands for upgrading or uninstalling?

A: Upgrade with dsh plugin --profile web update dsh-tokenledger, uninstall with dsh plugin --profile web remove dsh-tokenledger; both operate on web profile just like installation.

Q: Do I need to manually fill in relay addresses?

A: Not in most cases. The plugin reads baseURL from host's provider configuration and auto-categorizes by origin. Manual relays configuration is only needed in two edge cases: settings service not mounted in the composition, or provider is an agent preset mounted in agent.cordis.yml.

Q: Which key is used for balance and subscription quota reading?

A: By default reuses the API key you've already configured on that route; the only exception is OpenRouter, whose quota interface only accepts Management Key—using inference key returns 401, and the panel will directly state which key is needed.

Q: Where is data stored? Is it safe?

A: Summary index is stored in SQLite file under DSH home directory (default tokenledger.sqlite), can be discarded and rebuilt; this plugin never reads or stores prompts, tool parameters, or response content; API keys always go through Authorization header, never into URL query strings, browser never gets them.

Q: What is the "Unknown Route" row?

A: It represents requests whose routes can no longer be found in current provider configuration—perhaps renamed, deleted, or run on another machine at the time. Data isn't lost; reconfiguring the same route name triggers index rebuild, historical traffic automatically repositions.

Q: How to troubleshoot "my relay not showing up"?

A: Run /tokenledger diagnostics in DSH; it will print current route attribution and routes in index; for 404 troubleshooting, follow the hints from this output.

Getting Started Difficulty

Beginner — no configuration needed to see usage and relay distribution; only need to edit settings.yaml when wanting to override auto-discovery results, declare interfaces for non-built-in vendors, or maintain rate tables.

Known Issues & Limitations

  • Must restart dsh web after installation or upgrade, and browser must hard refresh; without restart routes won't register and won't error (dshworks documents this as a common pitfall of host half-loading in doc/HOST-CONTRACT)
  • pnpm caches github:user/repo#main string; to force update to main requires full 40-character commit SHA; short SHA directly reports Could not resolve
  • Can't add native config card for this plugin in DSH settings page yet: upstream dsh-host-apiproxy hardcodes seven whitelisted namespaces for exposure, other namespaces return settings-not-exposed; tokenledger currently uses settings.yaml form read/written by host-side ctx.settings, browser config panel is a blocking item
  • Reinstalling same spec won't refresh main; before modifying package.json confirm it won't fail parsing (add resolves entire list first)
  • node:sqlite triggers ExperimentalWarning on Node v22, upstream warning, not suppressed by this plugin
  • Custom endpoint (endpoints) path must be absolute path starting with single slash; protocol-relative URLs like //host/x are rejected at construction time

Read the usage guide →

Install steps, key points, FAQ and compatibility for this plugin — auto-derived from indexed fields.

Listing badge

Listed on deepseek-plugin.org
[![Listed on deepseek-plugin.org](https://img.shields.io/badge/listed_on-deepseek--plugin.org-007EC6)](https://deepseek-plugin.org/plugins/zh667/TokenLedger)

Paste this markdown into your GitHub README to link back to this listing. The badge only states the listing — not a security endorsement.

← Back to plugin directory