dsh-plugin-cost-ledger: Tracking Every Model Call in a Monthly JSONL Cost Ledger

Foreword

When running agents in DeepSeek Harness (dsh), model calls continuously generate token usage. If you only care about “how fast it’s burning right now and whether to stop it,” the community’s dsh-plugin-price-aware is more suitable. However, if you need cross-session, cross-restart reconciliation—“how much was spent this month, how is it distributed by model and by day, can it be exported to Excel”—you need to persist every call with a price list and be able to view reports within dsh.

Below is an introduction to the plugin dsh-plugin-cost-ledger by maintainer 121212165 in the SkillHub “Model Inference” category: it monitors session usage events, calculates costs based on built-in or custom price lists, writes to JSONL files monthly; and performs summarization and export via the /ledger, /ledger-export, and ledger_query tools. The plugin reads and writes local files with the permissions of the current dsh process; please review the source code and the MIT license before installation.

What is this

dsh-plugin-cost-ledger is a dsh plugin: it records every priced model call into a persistent ledger, produces monthly summaries, exports CSVs, and allows the agent to answer “how much money was spent this month.”

Data is broken down by token buckets (uncached input, cache read, cache write, output), supporting off-peak date and multi-currency block statistics; model events not in the price list are discarded rather than guessed, avoiding silent accounting errors. The README notes: Live mount verification in a running dsh has not yet been completed (unit and assembly layer tests have passed).

Core Features

Persistent Ledger

When accounting is set to own (default), the plugin monitors assistant/message usage events in session/event, calculates the cost using the built-in price list (DeepSeek official prices, including peak/off-peak and cache prices), and appends entries one by one to a JSONL file partitioned by month under dataDir, such as ledger-2026-09.jsonl. After the session ends or dsh restarts, the accounts remain on disk.

/ledger

Outputs the current month’s summary: total cost, number of calls, number of sessions, total tokens and cache hit rate, distribution by model (with percentages), distribution by day, and comparison with the previous month. Multi-currency is rendered in separate blocks and not mixed. If there are corrupted lines in the JSONL, the summary will indicate “N corrupted lines.”

/ledger-export [YYYY-MM]

Exports the ledger for a specified month to CSV (BOM + CRLF, for direct opening in Excel), writing to exportDir (default is the same as dataDir). The export does not include session titles (only sessionId is available on the host side).

ledger_query Model Tool

When the agent is asked about expenses, it can query the ledger via this tool.

Division of Labor with price-aware

price-aware focuses on real-time usage and interception; this plugin focuses on “monthly ledger”—persistence, cross-session, exportability, and reconciliation. The pricing logic of both plugins is copied from price-aware (MIT, same author), and they are independent of each other regarding installation.

Installation and Activation

The README provides three steps, tested on @deepseek-ai/dsh@0.1.7-alpha.1 (requires pnpm in PATH; package.json requires Node >=22.18).

  1. Install into the profile (arguments are forwarded to pnpm as-is, and git packages will automatically run prepare to build lib/):
dsh plugin --profile web add github:121212165/dsh-plugin-cost-ledger
  1. Merge the content of the cordis.patch.yml in the repository root directory into $DSH_HOME/profiles/web/cordis.patch.yml. The default file is often []; you should replace the entire file or merge the insert entries into the same array; do not append directly, otherwise there will be two YAML documents, causing a startup error failed to parse overlay ... end of the stream or a document separator is expected.

  2. Restart dsh. Both the configuration layer and the client half need a restart to take effect (a hard refresh of the browser is not enough).

Self-check if it is mounted:

dsh --profile web --dump-config | grep dsh-plugin-cost-ledger

The plugin entry should be visible.

Configuration

Field Default Description
enabled true If disabled, the plugin is not mounted
accounting own own: Account from session events yourself; assume-price-aware: Assume price-aware has already accounted, this plugin only reads the ledger for reports (under current implementation, this mode is equivalent to “report only, do not record new accounts”)
dataDir ~/.dsh/cost-ledger JSONL ledger directory, ~ will be expanded
exportDir dataDir CSV export directory
prices [] Transit/self-defined price lists, shape consistent with price-aware’s prices
holidays [] Dates in Beijing time for off-peak pricing (YYYY-MM-DD)

If a model id can only be matched to a price list row with low confidence, the record will have a matchVia field; the amount is considered an estimate and needs to be verified against the price list before trusting.

Typical Usage

View Current Month’s Summary

Execute the slash command in dsh:

/ledger

Export CSV for a Specific Month

When the parameter is omitted, the behavior depends on the help within dsh; the README example specifies the month:

/ledger-export 2026-09

The file is written to exportDir and can be opened with Excel.

JSONL Single Line Example

Each line is one pricing record, the amount unit is micro (1e-6 currency units):

{"v":1,"sessionId":"…","at":"2026-09-15T02:30:00.000Z","turn":3,"step":1,
 "modelId":"deepseek-v4-pro","provider":"deepseek","pricedAs":"deepseek-v4-pro",
 "buckets":{"uncachedInput":1000,"cacheRead":90000,"output":500,"cacheWrite":0},
 "reasoningTokens":400,"currency":"CNY","costMicros":225000000}

Use Cases and Caveats

Suitable for: Developers who need to keep call costs in dsh for the long term, reconcile accounts monthly, export CSVs, or let the agent answer questions about spending.

Notes:

  • The plugin runs with the dsh process and reads/writes dataDir/exportDir; please check the source code and permissions before installation and configuration.
  • Models without a price list will not be accounted (visible in debug logs), and the total will not be inflated due to missing prices.
  • The ledger currently has no compaction/archival commands; files need to be backed up or cleaned up manually.
  • When mounted simultaneously with price-aware, if you do not want duplicate accounting, you can set accounting: assume-price-aware, but until price-aware writes the ledger to the same dataDir, new accounts will still depend on this plugin’s own mode or historical files.
  • SkillHub directory page: dsh-plugin-cost-ledger is a community plugin index, with no official affiliation to DeepSeek / Quantilla; the DSH ecosystem philosophy is “Everything is a plugin.”

Conclusion

dsh-plugin-cost-ledger turns priced model calls into monthly JSONL, uses /ledger for a dashboard, /ledger-export for CSV export, and ledger_query for agent self-inquiry, and chooses to discard rather than guess when prices are missing. If you are already doing agent development in dsh and want auditable monthly costs, you can follow the README’s three steps to install and merge cordis.patch.yml.

  • Directory Page: https://www.skillhub.cn/plugins/121212165/dsh-plugin-cost-ledger
  • Source Code & Docs: https://github.com/121212165/dsh-plugin-cost-ledger
羽毛球分组比赛记分
小程序二维码

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

Xiaoye