Preface

The DSH plugin ecosystem supports flexible feature extension. When developing or experimenting with LLMs, it is necessary to monitor token usage and costs across different projects. The dsh-token-cost plugin solves the problem of tracking token consumption by project and calculating costs in RMB by analyzing local session logs.

What Is This

This is a DSH plugin maintained by gdy01, used to display LLM token usage for each project and convert tokens to RMB costs. Costs are split into three categories: input (non-cached), cached, and output. The calculations are based on the models’ official standard pricing.

Core Features

  1. Read local logs: Scans session.jsonl.zstd or session.jsonl files in the DSH session directory (~/.dsh/sessions or $DSH_HOME/sessions).
  2. Aggregate statistics: Aggregates data by session cwd (current working directory) and model.
  3. Web interface integration: Adds a 💰 button at the bottom of the DSH Web sidebar. Clicking it shows project totals and expandable per-model details.
  4. Zero dependencies: Uses Node’s native node:zlib to decode Zstandard-compressed logs, with no runtime npm dependencies.
  5. Local API: Provides an HTTP API accessible only via the local loopback interface.

Installation and Enablement

You must install the dsh-token-cost subdirectory in the plugin directory; do not install the parent folder. Because the path contains spaces, the install command must be wrapped in quotes.

dsh plugin --profile web add "file:/Users/dg/Documents/dsh plugin/dsh-token-cost"

If you are in the target directory, you can use $PWD:

cd /Users/dg/Documents/dsh plugin/dsh-token-cost
dsh plugin --profile web add "file:$PWD"

If you previously installed the wrong parent folder, remove it first and then install the correct one:

dsh plugin --profile web remove "dsh plugin"
dsh plugin --profile web add "file:/Users/dg/Documents/dsh plugin/dsh-token-cost"

After installation, restart dsh web and refresh your browser. A 💰 button will appear at the bottom of the sidebar. You can also use the included install script:

./scripts/install.sh

How It Works

The plugin scans the DSH session directory and extracts information by replaying the data:
* session.cwd → determines the project.
* request/header → determines the model currently in use.
* assistant/chunk { type: 'usage' } and assistant/message.usage → extracts input, cached, and output token counts.

The plugin de-duplicates usage samples for the same (turn, step), ensuring the data is consistent with DSH’s own token counting logic.

Pricing Table

By default, it uses DeepSeek’s official standard pricing (CNY / 1M tokens):

Model Input (non-cached) Cached Output
deepseek-chat / deepseek-v4-flash 2 0.5 8
deepseek-reasoner / deepseek-v4-pro 4 1 16

For models not listed in the pricing table, the plugin reports their token counts but does not calculate costs. You can override the pricing configuration in the cordis.patch.yml config file.

API Endpoints

The plugin provides the following local endpoints:

  • GET /dsh-token-cost/api/stats — Get full JSON statistics by project and model.
  • GET /dsh-token-cost/api/prices — Get the currently effective pricing table.
  • GET /dsh-token-cost/healthz — Health check.

Notes

  • The plugin runs on Node.js >= 22.
  • The API only allows local loopback access, with security guaranteed by the DSH proxy.
  • The license is MIT.