DeepSeek Harness Per-Turn Cost Plugin: dsh-turn-cost

Preface

DeepSeek Harness’s default UI does not display the cost per conversation turn, leaving developers to estimate on their own. dsh-turn-cost shows “This turn: ¥…” at the bottom of each turn and supports hover to view a breakdown. It does not treat a turn as a monolith; instead, it prices each assistant node individually based on its usage, model, and timestamp, then sums the results. This approach yields more accurate figures when spans cross models, peak/off-peak time windows, or mixed free routing.

Plugin Overview

  • Name: dsh-turn-cost
  • Maintainer: Lyqqt
  • Category: Model Inference
  • Features: Displays cost at the bottom of each turn with hover-to-expand details; supports OpenRouter endpoint-range and generation actual-billing queries.

Installation & Activation

Install directly from GitHub into a profile:

dsh plugin --profile desktop add github:Lyqqt/dsh-turn-cost

Or clone and install locally:

git clone https://github.com/Lyqqt/dsh-turn-cost.git
powershell -ExecutionPolicy Bypass -File .\dsh-turn-cost\install.ps1

After installation, you will see a “Cost” entry in the plugin center. The host-side half (price catalog routing) requires restarting DeepSeek Harness once to load; the client-side half supports HMR. To verify: open http://127.0.0.1:<port>/dsh-turn-cost/prices.json in a browser — it should return {"ok":true,...}.

Display Location

  • Bottom of each turn: conversation.chat.turnTail, rendered just before the usage / timestamp line, showing “This turn: ¥… · X requests”.
  • Input bar footer: the session total “Total: ¥…” in conversation.composer.dock.
    Hover to expand the breakdown, listing each request’s model, usage, and price source.

Pricing Methodology

  • deepseek-official route: Uses a built-in CNY peak/off-peak table. On Beijing weekdays, 09:00–12:00 and 14:00–18:00 are treated as peak hours (2× rate); weekends and public holidays are off-peak.
  • Other routes (openrouter / custom): Uses models.dev listed prices (USD/M), matched by provider|model; the :free suffix is charged 0 directly.
  • Hand-written overrides: User configuration, highest priority.
  • priceModules / registerPriceSource: User code, highest priority.

Displayed Range vs. Actual Billing

The same OpenRouter model can vary in price by 10–30× across different endpoints. The plugin calls OpenRouter’s /api/v1/generation?id=… endpoint using the generation ID to retrieve the actual provider and cost. For the most recent generationLookback turns, it queries the actual value per request. When all lookups succeed, the reading reflects the actual billing and displays “OpenAI · ¥… (actual)”. When the lookup fails (old sessions, missing API key, request purged, timeout), it falls back to the endpoint-range display with an “Estimated” prefix.

Configuration

Configuration is written in the profile’s ~/.dsh/profiles/<profile>/cordis.patch.yml:

- id: turn-cost
  name: dsh-turn-cost
  config:
    currency: CNY
    usdToCny: 7.2
    proxy: socks5://127.0.0.1:1080
    refreshHours: 24
    unknownDisplay: dash
    showRequests: true
    priceNote: 'Prices sourced from openrouter'
    sources:
      modelsDev: true
      openrouter: true
    pricers:
      openrouter: true
    aliases:
      '@preset/ds41f-cheap': 'openrouter|deepseek/deepseek-v4.1-flash'
    overrides: []
    priceModules: []

Key field descriptions:

  • enabled: Defaults to true; when false, nothing is rendered.
  • currency / usdToCny: Display currency and exchange rate.
  • proxy: Proxy used by the host to fetch the price catalog.
  • refreshHours: Catalog cache freshness interval.
  • providers: Defaults to 15; only these models.dev providers are written into the catalog.
  • providerMap: DSH route ID → models.dev provider ID mapping.
  • aliases: Model aliases; value is provider|model or a bare model ID.
  • overrides: Hand-written unit prices, highest priority.
  • priceModules: Path to .mjs price modules.
  • endpointRanges: Master switch; when off, all pricers are bypassed and only model prices are shown.
  • pricers: Disable a specific pricer by ID, e.g. { openrouter: false }.
  • generationLookup: Use generation ID to query actual provider and cost (requires an OpenRouter key).
  • generationLookback: How many recent turns to query.

Custom Pricing: Four Tiers — Pick the Lightest That Fits

  • Just need to change numbers: Use overrides for exact route or substring matching.
  • Bulk price lists: Use priceModules with a host-side .mjs file.
  • Add a new pricer: Inject turnCostPricers in the client plugin, implementing match and quote.

Example:

export function apply(ctx) {
  ctx.inject(['turnCostPricers'], (scope) => scope.turnCostPricers.register({
    id: 'my-relay',
    match: (target) => target.provider === 'my-relay',
    quote({ request, target, price, usage, config, ladder }) {
      return { min: 0.01, max: 0.03, count: 2, note: 'Custom two-tier' }
    },
  }))
}

Use Cases & Notes

  • Ideal for developers who need precise per-turn cost visibility, cross-model pricing, or use OpenRouter / custom routes.
  • The plugin runs with the current dsh process’s permissions; review the source code and license before installing.
  • The host-side half reads the entry config only once at profile startup. After adding settings like proxy, a DeepSeek Harness restart is required for changes to take effect. If you want to avoid a restart, you can modify ~/.dsh/turn-cost/config.json — it is re-read on every rebuild.

Summary

dsh-turn-cost provides per-turn cost display in DeepSeek Harness, with expandable details, OpenRouter endpoint-range queries, and generation actual-billing lookups. Combined with its multi-layer customization mechanism, it is well suited for developers who need fine-grained cost control. See the links below for the plugin catalog page and the GitHub repository.

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

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

Xiaoye