DSH (DeepSeek Harness) adopts an “everything is a plugin” architecture. When developing or using agents, accurately understanding the cost of each request is critical. The dsh-cost plugin is placed directly at the bottom of the conversation interface. By calculating “request time × model unit price at that time,” it provides accurate per-request billing and distinguishes peak and off-peak periods, solving the problem of traditional statistics being too coarse.

Core Features

The plugin is injected based on DSH’s conversation.composer.dock slot and provides the following capabilities:

  1. Accurate per-request billing: It does not apply the current price to the entire period. Instead, it records the exact time and model when each request occurred and accumulates costs at the unit price in effect at that time.
  2. Time-based pricing: Costs are divided into peak, off-peak, and historical tiers. Starting from 2026-09-10 12:00 (Beijing Time), the Flash series has reduced pricing, with different unit prices for off-peak and peak periods; earlier periods are billed at the old prices.
  3. Time-based detail cards: Click the “Cost” pill at the bottom to expand peak/off-peak/historical detail cards, with a small bar at the bottom showing the amount share.
  4. Model attribution and image token accounting: It automatically splits call counts and costs by model, and tracks tokens for visual input (images) separately.
  5. Account balance: The pill displays the current balance. Clicking the pill immediately refreshes the balance and cost details (the coin icon performs a spinning animation). The default refresh interval is every 5 minutes.
  6. Official-style appearance: It uses a 14px icon and a “pill” style with border-radius:24px, displayed next to DSH’s official statistics row on the same line without wrapping.

Installation and Enablement

The plugin ships with dsh.bundle.patch, so there is no need to write a profile patch manually. After installation, restart the dsh web process to take effect.

dsh plugin --profile web add github:david0702/dsh-cost

After installation, refresh the client page to see the new Cost pill.

Verify Installation

Run the following command in the browser console to confirm that the plugin has been added to the DSH Boot composition:

__DSH_BOOT__.entries.map((e) => e.id).filter((id) => /cost/i.test(id))
// 期望输出: ["@david0702/dsh-cost"]

Development and Hot Reloading

For local development, it is recommended to use pnpm link to link the repository directly into the profile, avoiding “copy and repository drift.”

dsh plugin --profile dev add /path/to/dsh-cost

The activation mechanism for changes to different files is as follows:

Changed file Activation method
lib/client.js Hot update: Changes take effect after saving; refresh the browser to see them. No service restart is required
lib/index.js Restart required: The host plugin does not support hot loading; you must restart dsh web
package.json (dsh field) Restart required: The profile composition is synthesized at startup

Permissions and Security Risks

Permission Scope

  • Network: Accesses only https://api.deepseek.com (used to fetch the balance).
  • Credentials: Reads the environment variable DEEPSEEK_API_KEY, used only for balance requests and not exposed to the browser.
  • Client: Sends requests only to the same-origin endpoints /api/dsh-cost/read and /api/dsh-cost/balance, and does not load third-party scripts.

Security Risks

The /api/dsh-cost/* routes registered by the plugin are exact routes (kind: 'exact'), taking precedence over the official /api prefix guard (kind: 'prefix').
This means that if dsh web is running on a machine and DEEPSEEK_API_KEY is configured, other processes on the same machine may be able to read the current session costs and account balance without credentials. Avoid binding dsh web to untrusted networks.

Compatibility Notes

The plugin depends on specific DSH versions and conventions:
* Client: Uses the conversation.composer.dock slot, props.useProjection, and similar APIs.
* Host: Uses ctx.webServer.register and ctx.credentials.resolve.

Before installing, check dsh.compatibility.dshReleases in package.json. Currently verified compatible versions include 0.1.5-rc.1 and 0.2.0-rc.2.

Summary

dsh-cost is a tool for DSH users that provides fine-grained cost observability. It displays costs and balance intuitively through the pill component, and, through exact routing and API Key isolation, provides convenience while preserving basic configuration flexibility.