返回目录
模型与 MCP 插件

dsh-token-plugin

realhenrylan/dsh-token-plugin

DeepSeek Harness 用量与消耗插件(dsh-usage-plugin)—— 每次调用的 token 用量/缓存命中统计、峰谷计费、余额查询、CSV/JSON/PNG 导出,可经桌面端一键安装或命令行 dsh plugin add 安装。

Stars
0
Forks
0
Issues
0
更新
20 天前

PROJECT TOPICS

项目标签

INSTALL REFERENCE

安装参考

未验证
dsh plugin --profile web add github:realhenrylan/dsh-token-plugin

该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。

PROJECT README

README

Published on npm as dsh-token-plugin.

This project is a fork of feiyang-dev/dsh-usage-plugin and continues development under the MIT License. The upstream copyright and license notice is retained in LICENSE.

DeepSeek Harness Usage & Cost Tracker (dsh-usage-plugin)

English · 简体中文

GitHub · MIT License

A community plugin for DeepSeek Harness — records token usage and cost for every model call, with peak/off-peak billing, a calendar heatmap, and CSV / JSON / PNG export.

License Node Platform


Overview

dsh-usage-plugin is a usage & cost tracker plugin in the DeepSeek Harness ecosystem (a DSH plugin shipped as a Host + Client two-in-one package). After installation, the "Usage & Cost" tab appear in the Web UI, right after "Conversation" and "Trace":

Supports Windows / macOS / Linux: paths are handled per platform (node:path), and the folder picker / "reveal in file manager" use each OS's native mechanism (macOS: osascript / open; Linux: zenity / xdg-open). Export does not depend on Windows-only commands.

  • Usage & Cost: records each model call's token usage and cache hits (input miss / cache hit / cache write / output / reasoning / finish reason), and computes cost using DeepSeek's peak/valley or base pricing (peak hours on weekdays are automatically priced by Beijing time 09:00–12:00 and 14:00–18:00; since 2026-08-23 weekends are billed entirely at the off-peak rate; since 2026-09-10 12:00 Beijing time the post-V4.1-Flash peak/valley prices apply — deepseek-flash off-peak cache hit 0.02 / input 1 / output 4 CNY, peak at twice that). Model names come from the actual request parameters, so non-DeepSeek models are shown truthfully instead of "unknown model"; models without an official price are counted as 0. The overview shows a by-model table plus a by-API-provider × model drill-down (each provider grouped with every model's calls and peak/off-peak cost split) and a grand total row. The overview also supports date filtering (Today / Last 7 days / Last 30 days / All, plus a custom start–end range), so the aggregate stats can be scoped to any single day or date range.
  • Usage Calendar: a monthly daily-usage heatmap (colored by cost or call count), hover for details including the peak/off-peak cost split, click a day for its call list and peak/off-peak totals, plus a per-day statistics table with peak cost / off-peak cost / total columns and rollups. Supports date-range filtering (Today / 7 days / 30 days / All plus custom start–end dates): when a range is active, the daily stats table shows every day in range across months, the top cards switch to "Calls in range / Cost in range" with range totals, and the heatmap only colors days inside the range.
  • Cache Hit List: newest-first, fully scrollable, with quick filters (Today / 7 days / 30 days / All) and custom date ranges; the summary line and footer total split peak vs off-peak consumption with a grand cost total. The list is paginated (100 rows per page), so it stays smooth even with large data volumes.
  • Interrupted calls shown truthfully: calls that were aborted / errored / timed out (e.g. manually stopped generation, stream interruption) are shown with a red "Interrupted" badge, the finish reason (Interrupted / Error / Timeout) and a — cost. The official console still counts these as API requests and bills their actual tokens, but the harness does not report their usage to the plugin — so the plugin records them at 0 tokens, keeping the call count aligned with the official console while costs are unaffected. The Overview's "Calls" card adds a · interrupted N (not billed) hint.
  • Local stats vs official console: a fixed notice banner at the top of the panel explains that this panel reflects calls captured locally by the plugin (official prices + peak/off-peak hours), and that the official console (platform.deepseek.com usage page) may show a higher amount because: ① interrupted/failed/timed-out calls are still billed by the console while the plugin records them as 0; ② calls from other API keys on your account (other apps/scripts) do not pass through DeepSeek Harness — the console includes them, the plugin does not; ③ for exact reconciliation, export the official monthly billing CSV and compare. When interrupted calls are detected, the banner also shows a red "Current records include N interrupted call(s) (not billed)" line.
  • Price Table: the official DeepSeek API price table (covering deepseek-flash = DeepSeek-V4.1-Flash and deepseek-v4-pro; the legacy ids deepseek-v4-flash / deepseek-v4-flash-vision-exp stay callable and fold into the Flash tier) — base and peak/valley unit prices shown side by side (peak vs off-peak). The peak/off-peak tables are date-split: the first version applies from 2026-08-17, and the post-V4.1-Flash version applies from 2026-09-10 12:00 Beijing time (deepseek-flash off-peak lowered to cache hit 0.02 / input 1 / output 4 CNY, peak at twice that; deepseek-v4-pro unchanged) — past calls are always billed with the version in force at their own time. Editable in-panel and persisted to pricing.json, with a reset-to-default option.
  • Subscription coding plans (billing channel): every call carries a per-call billing channel — a subscription plan or pay-as-you-go. Built-in support for plans like OpenCode Go / Command Code GOAT (two default plan entries ship with the plugin pre-filled with the official $10/month — edit if your actual fee differs). Register each plan in the panel (fee per cycle + Provider ID / model ID attribution rules); new calls are auto-tagged at write time by exact Provider ID match (ambiguous matches are never guessed), and existing calls can be tagged manually by session ID or date range. Plan calls show their equivalent official price (what the tokens would cost at official per-token rates) alongside a "Subscription ROI" card (equivalent price ÷ monthly fee); summaries and CSV / JSON exports split by channel. The equivalent price is a reference figure, not your actual bill — the actual charge is the flat subscription fee.
  • Export: CSV / JSON / PNG long image (newest-first, up to the latest 2000 records, warns if exceeded; the PNG report includes peak/off-peak cost columns), to any directory (native picker), auto-opens the folder after export.
  • Import: merge-imports JSON / CSV files, deduplicated by time.
  • Persistence: records are written live to <session workspace>/dsh-usage/usage-records.json and restored on restart (cap 100000 records).
  • UI adaptation: panel typography scales with the app's display-size setting (em-relative fonts); wide tables scroll horizontally on desktop (max-content + overflow-x) and fit the screen width on mobile (≤900px, no horizontal scrollbar); popup cards adapt to the viewport.
  • English UI (i18n): the panel follows the harness's own language setting (General Settings → Language) — switch it there and the plugin follows instantly, no separate toggle, no localStorage override. The bilingual dictionary covers the whole panel, the peak/off-peak billing-period hints, and the PNG report; host-level Conversation/Settings tab labels are re-read per render, so they follow the language switch live.
  • Internal/tool calls grouped separately: internal/placeholder calls (e.g. dsh2shell-* with model fake) are excluded from the model cost breakdown and collected in a collapsible "Tool calls (internal)" group below the breakdown, so only real model calls count in the cost tables.
  • Mobile adaptation: tables fit the screen width on ≤900px (no horizontal scrollbar); wide tables collapse the middle columns; the popup and its stat cards / per-model cards adapt to the viewport.

Screenshots

Usage & Consumption

Usage & Consumption

Installation from this checkout

Install directly from the GitHub repository:

dsh plugin --profile web add github:realhenrylan/dsh-token-plugin

The GitHub shorthand refers to https://github.com/realhenrylan/dsh-token-plugin.

Alternatively, install a locally packed checkout:

Clone the GitHub repository, then build a local package and install it through DSH:

git clone https://github.com/realhenrylan/dsh-token-plugin.git
cd dsh-token-plugin
npm pack
dsh plugin --profile web add ./dsh-token-plugin-2.1.0.tgz

If you already have a checkout, run the last two commands from its directory. Use the package filename printed by npm pack if the version differs.

Restart the DSH service after installation. To install the published package, run dsh plugin --profile web add dsh-token-plugin. Desktop recommended listings are maintained separately.

What's in the package

One npm package = a host half (Node-side Cordis plugin: recording, billing, export — see lib/index.js) + a client half (browser-side panel — see lib/client.js, which talks to the host via /usage/api).

The package integrates with DSH through two declarations:

Declaration Purpose
dsh.bundle.patch (cordis.patch.yml) Lets DSH recognize it as a standard bundle plugin package: dsh plugin --profile <name> add <package> installs and wires it in one command, no manual config editing
dsh.client + exports["./client"] Lets the web client auto-load the browser panel at /plugins/<package>/client.js

So for users, installation is one command — no YAML editing, no manual file copying.


Updating and uninstalling

To update, pack the current checkout again and install the resulting tarball using the command above. To uninstall, run dsh plugin --profile web remove dsh-token-plugin and restart DSH.

Releasing (maintainers)

One command handles "bump version + test + pack":

npm run release -- patch   # 2.1.0 → 2.1.1; also minor / major / 2.2.0

The script runs the full test suite first, then writes the new version, syncs the install examples in both READMEs, turns the CHANGELOG "## 未发布 (Unreleased)" heading into the new version heading, runs the plugin contract check, and produces dsh-token-plugin-<version>.tgz. Add --dry-run to rehearse; --no-changelog skips the CHANGELOG heading update. It never commits, pushes, or publishes — it prints the next commands when done.

npm run release:github creates the GitHub Release and uploads the tarball from the existing tag and CHANGELOG section (requires a token in git credentials).

Local publish credentials can live in .npmrc.local at the repo root (gitignored, never packed); publish with npm publish --userconfig .npmrc.local.

Data & locations

Since v1.9.2, records are stored in a fixed, dedicated data directory (fixes #4). The path no longer follows the session workspace / ~/.dsh / desktop-app install dir, so your history never "disappears" (counted as 0) when the workspace changes, and the path shown in the UI equals the on-disk path.

  • Records: <data root>/dsh-usage/usage-records.json
    • Resolution order for the data root (data always lands in the first writable dir of this list, never in the workspace unless all of the below are unwritable):
      1. env var DSH_USAGE_DATA_DIR (if set) — overrides everything;
      2. Windows: %LOCALAPPDATA%\dsh-usage-plugin (falls back to %APPDATA% if LOCALAPPDATA is unset);
      3. user home dir: ~/dsh-usage-data (Windows %USERPROFILE%\dsh-usage-data, macOS/Linux ~/dsh-usage-data);
      4. fallback (rare): current workspace <workspace>/dsh-usage — only used when all system/user dirs above are unwritable, and the panel will show a "persistence disabled" warning.
    • Writes bypass the model sandbox: persistence is done by the host plugin process's own filesystem, not subject to the workspace-write sandbox, so the fixed directory is always writable and data is not lost when switching workspaces.
    • Default on Windows: %LOCALAPPDATA%\dsh-usage-plugin\dsh-usage\usage-records.json
  • Legacy data auto-merge: on first start, records previously scattered in %USERPROFILE%\dsh-usage, ~/.dsh/dsh-usage, and each workspace's dsh-usage (or .dsh-usage-records.json) are merged into the fixed root, deduplicated by record identity — the recordId of new records, or a composite fingerprint (session + timestamp + model + purpose + four token buckets + finish reason) for legacy ones. This is no longer a millisecond-only comparison, so two different requests inside the same millisecond no longer overwrite each other. Records written by older versions stay fully readable: missing recordId / pricingTime / unit and friends are all optional.
  • Writes are atomic: a temporary file in the same directory is written, flushed, and then atomically renamed over the target; a failure leaves the existing file untouched.
  • A corrupt file is never silently zeroed: if the data file exists but cannot be parsed, the plugin no longer treats it as empty data (older versions did — and then overwrote the whole history with that empty array). It renames the original to usage-records.json.corrupt-<timestamp>.json and keeps starting, so the data can be recovered by hand.
  • Price config (edited & saved in the panel): <data root>/dsh-usage/pricing.json
  • Price-table snapshots (appended on every price edit / reset, capped at 200, append-only): <data root>/dsh-usage/pricing-history.json
    • Used only to review "which table applied at that moment"; it never participates in cost calculation. You can also override the built-in legal-holiday list with holidays: ["2027-01-01", ...] in pricing.json.
  • Subscription plan registry (edited & saved in the panel's "Subscription plans" box): <data root>/dsh-usage/plans.json
  • Default export dir: <data root>/dsh-usage/{csv,json,images}/
  • Custom export dir: set in the panel's "Export target directory" or click "Choose directory…"
  • Startup diagnostics (if the plugin fails to activate): dsh-usage-boot.log next to the data root

Metering scope

Usage and cost here are recorded call by call from DeepSeek Harness llm/stream events, plus a session/event listener for search-backend requests. Read the boundaries below before relying on the numbers.

Precisely metered (provider-reported values)

Source Notes
Main agent conversation Four token buckets, cache-hit counts and finish reason per call
Session-title generation purpose: session-title
Context compaction purpose: compaction
In-process subagents They share the main agent's ctx.llm, so they are intercepted too

The billing formula matches the official one: uncached input × miss price + cache hit × hit price + output × output price. There is no separate cache-write price (DeepSeek never reports that field; writing to cache is charged at the miss price), and reasoning is already included in output, so it is never billed twice.

Not precisely metered (flagged separately in the UI)

Source Why it is unreachable What the plugin does
DeepSeek search backend calls from web_search web-search-deepseek issues a native fetch straight to api.deepseek.com/anthropic/v1/messages inside the Harness, deliberately bypassing ctx.llm; upstream only persists the request (web/deepseek-search-llm-request) and discards the response usage entirely (its response type does not even declare a usage field). No data source exposes this spend. Records the exact call count and derives a lower bound for the input side from the request body, all flagged estimated. The output side is never guessed. The overview shows "estimated cost ≥ ¥X (N calls)".
External CLI subagents (claude-code / codex) Separate child processes, fully outside ctx.llm, emitting no events Not counted
Output produced before an aborted request The adapter emits no usage chunk on abort Recorded as a zero-token "interrupted call" so the call count still matches the console
Official billing counts HTTP requests; the plugin counts streams Harness-level retries do not open a new stream Call counts may differ from the official request_count

Bottom line

  • For ordinary chat / coding workloads the plugin's total tracks the official bill closely;
  • With heavy web_search use the plugin's total is materially lower than the official bill — the gap is the search backend, and the panel says so explicitly;
  • In all cases, the DeepSeek console bill is authoritative.

Past prices are never rewritten

Each record freezes the three unit prices in effect when it was written (its unit field). Therefore:

  • Editing the price table afterwards (from the panel or by hand in pricing.json) only affects future records; past costs are not recomputed;
  • Records written by older versions or imported by hand have no frozen snapshot, so their cost uses the current table and follows later edits — the overview and price pages report how many such records exist;
  • To deliberately reprice all history, use "Reprice all history with the current table" on the price page (or call API {"action":"repriceAll"}). That is the only entry point that rewrites historical cost.
  • Billing-channel tags are frozen at write time as well: automatic plan attribution only applies to calls recorded after the matching plan is registered; existing records can only be re-tagged explicitly via the panel's "Mark billing channel" box (by session ID or date range), which never changes amounts.

FAQ

Symptom Cause / Fix
Panel reports Unexpected end of JSON input The plugin row is missing the inject list, so the route isn't registered. Add the inject list per Method B3 and restart
Panel blank / no top tab Plugin not activated. Check dsh-usage-boot.log; confirm the cordis.patch.yml row exists with the correct name
dsh plugin reports pnpm not found Install pnpm: npm install -g pnpm
Install can't reach the npm registry Set a mirror: npm config set registry https://registry.npmmirror.com (or pnpm config set registry ...) and retry
After uninstall, still reports Cannot find package '@feiyang666/...' A package reference remains in the profile. Remove the corresponding row from cordis.patch.yml and the package name from dsh.profile.bundles, then restart
On Desktop 0.2.x every cost is ¥0 and the price page reports that all records lack a frozen unit price 1.18.0 and earlier only recognised the provider ids deepseek-official / deepseek, while the desktop app's official-account provider id is deepseek-account. Since 1.19.0 every deepseek-* id is matched by prefix, new records freeze their unit prices, and historical records are priced correctly too — issue #19

Related Projects

Project Description Installation
Data Vault (dsh-vault) Auto backup / wipe detection / one-click restore — protects chat history and workspace data One-click from the desktop app, or dsh plugin add @feiyang666/dsh-vault
DeepSeek-Harness Official CLI / Web service Quick start below

Running DeepSeek Harness

Quick start (via npm)

Install Node.js, then run:

npx @deepseek-ai/dsh web

This command starts the Web UI at the default address http://127.0.0.1:3080. See the Web UI Guide for details.

Run from source

To run from the repository source:

git clone https://github.com/deepseek-ai/deepseek-harness.git
cd deepseek-harness
pnpm install
pnpm run build
pnpm dsh web

Acknowledgements

  • @ayleen: implemented the full English UI layer (i18n) with reactive language switching, and moved balance presentation to semantic keys (#7).
  • @wuhuqif176: added the Bailian (Qwen) Token Plan quota query to the balance panel (#8).
  • @Martin-soaring-dev: prepared the plugin for public contribution (packaging, plugin-contract checks, docs & CI) and submitted the contribution branch that became the basis for the open-source releases (#6).
  • @mumuer1024: reported and diagnosed the persistence-path drift across workspaces (history "disappearing" / counted as 0) and proposed storing data in a fixed, dedicated directory (#4); also reported that DeepSeek search-backend calls went unmetered and could understate cost by an order of magnitude, with a fully cross-checkable trail against the official bill (#12).
  • @liu3734: reported and diagnosed the Windows-only path handling / spawn issues on macOS (POSIX) and proposed the cross-platform fix (#1).
  • @zhiqiangme: submitted a large PR adding history backfill and a sidebar balance entry (#14). Three of its findings — the cacheWriteTokens fallback double-counting the four buckets, millisecond-only dedup overwriting records, and non-atomic writes silently zeroing a corrupt file — became the basis for the v1.18.0 metering fixes (see CHANGELOG).

Changelog

License

MIT © dsh-usage-plugin

CLASSIFICATION EVIDENCE

分类依据

项目类型插件
功能分类模型与 MCP
规则置信度高

系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek、deepseek-harness。