DeepSeek Harness Token Usage Statistics Plugin

Introduction

DeepSeek Harness (DSH) provides basic logging and runtime information by default, but often lacks an intuitive summary panel for fine-grained management of model inference costs, cache hit rates, and TPS. Existing solutions typically rely on manual statistics or scattered log analysis tools, making it impossible to see usage and trends broken down by route and time dimensions in real time during development. The plugin introduced below adds a global sidebar panel to DSH that aggregates request counts, token usage, cache hit rates, and TPS, and provides a GitHub-style heatmap with multi-dimensional filtering.

What It Is

dsh-usage-stat is a statistics plugin for DeepSeek Harness. Developed by maintainer vaspike, it falls under the model inference plugin category. It adds a “Usage Stat” panel to the left sidebar of DSH, displaying real-time KPIs for requests and tokens, per-route model statistics, and a heatmap view, helping developers quickly identify usage anomalies and cost bottlenecks during debugging and deployment.

Core Features

KPI Metrics

  • Request count: Includes provider counts. Breakdown by step/retry/compaction/auxiliary calls is available on hover.
  • Token summary: Total tokens (including reasoning tokens), input token ratio, output token ratio, cache hit rate, average TPS, and time to first token (TTFT).
  • Time dimension: Supports Today / Yesterday / Last 7 days / Last 30 days / All, as well as custom date ranges.

Filtering

  • Time presets and custom ranges.
  • Multi-select filtering by provider, model, and session. When no session is selected, the scope defaults to global.

Usage Heatmap

  • GitHub-style daily usage heatmap.
  • Supports 90 / 180 / 365-day windows (default 365).
  • Cell size adapts to panel width; clicking a cell navigates to the corresponding date; dates outside the window are displayed with reduced opacity.

Model Route Statistics

  • Displays per provider × model route: request count, total tokens, output tokens, cache hit rate, and TPS.
  • Provides a bar chart with input / cache read / cache write breakdown and shows the total billed input.

Theme Compatibility

  • Styles use only --dsw-alias-* semantic tokens, adapting to light/dark themes and user-defined themes.

Installation and Enablement

Install via the plugin marketplace or manually in DeepSeek Harness:

  1. In the DSH interface, go to Plugins → Add plugin.
  2. Enter dsh-usage-stat (npm) or the path to a local checkout directory.
  3. After installation, refresh the interface. A “Usage Stat” panel will appear in the left sidebar.

The plugin requires DeepSeek Harness 0.2.x.

How Counting Works

The plugin folds committed session events into ledgers keyed by day, session, and (provider, model):

Event Type Source Event Description
Step step/end Assistant-message routing attributed to the step
Retry llm/retry-started Actually dispatched attempts
Compaction compaction/summary Usage reported by the provider
Auxiliary session/title-llm-request Auxiliary calls such as title generation

Token buckets use a mutually exclusive TokenUsage calculation:

  • Input excludes cache reads/writes; cache hit rate = cacheRead / (input + cacheRead + cacheWrite).
  • Total tokens = input (including cache) + output.
  • TPS = output tokens / decode time; TTFT = step start → first non-empty text/reasoning delta, both derived from timestamps in assistant/message.

Reasoning tokens are only visible for routes that explicitly report them (e.g., DeepSeek Reasoner); a value of zero indicates it was not reported. Cache write tokens are only visible for APIs that explicitly report cache creation (e.g., Anthropic); implicit prefix caching providers only report reads.

Persistence and Restart

Each contributed event is appended to a JSONL ledger keyed by (sessionId, seq), with historical override markers. On restart, history is replayed and backfilled via sessionPersistence/sessionQuery to avoid double counting. The ledger is located at $DSH_PROFILE_DIR/usage-stat/ledger.jsonl (or ~/.dsh/usage-stat/ledger.jsonl) and can be overridden via the dataFile configuration. Deleting a provider or model does not lose history: routes are recorded as strings at request time, so deleted routes remain filterable.

The plugin provides real-time coverage for auxiliary calls flagged for usage tracking (e.g., title calls, failed compaction attempts) via llm/stream listeners. Loop requests remain unchanged. The browser panel reads an authenticated route via /usage-stat/api/snapshot and refreshes every 30 seconds.

Known Limitations

  • Attempts that did not produce an assembled assistant-message (e.g., mid-way cancellations) are not counted toward usage; such steps appear with an unknown route.
  • Auxiliary call usage is only counted while the plugin is running and cannot be backfilled from logs.
  • Session formats requiring migration are skipped during backfill.
  • Daily buckets use the host’s local timezone.

Typical Usage

  1. Open the Usage Stat panel in DSH; by default it shows global usage across all time.
  2. Narrow the scope using time presets or a custom date range, e.g., “Last 7 days.”
  3. Select items of interest in the provider/model/session filters and observe request counts, total tokens, and cache hit rates per route.
  4. In Model Route Statistics, click a route to view the detailed bar chart and assess the composition of input / cache read / cache write versus billed input.
  5. In the heatmap, scroll to a specific date and click a cell to jump to that day’s view to observe usage fluctuations.

Use Cases and Notes

This plugin is suitable for developers and operations personnel who need fine-grained tracking of model inference costs, cache efficiency, and TPS. It can be used during development debugging and production monitoring.

Before installation, it is recommended to review the source code and license to ensure compliance with project and organizational security and compliance requirements. The plugin runs with the current DSH process permissions; obtain the package or code from trusted sources only.

Summary

dsh-usage-stat provides a global statistics panel for requests, tokens, cache, and TPS in DeepSeek Harness. Combined with the heatmap and multi-dimensional filtering, it enables rapid identification of usage anomalies and cost bottlenecks during development and deployment. More details can be found on the catalog page and the GitHub repository.

Catalog Page | GitHub

羽毛球分组比赛记分
小程序二维码

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

Xiaoye