chenmiao8563/dsh-token-ledger ↗★ 1
@chenmiao8563/dsh-token-ledger
提供透明可审计的Token账单统计与导出 适合需要精确统计、分析和导出各会话Token成本的用户。
安装
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:chenmiao8563/dsh-token-ledger说明文档
阅读完整 README ↗Configuration
Override the composition entry by its id:
- id: token-ledger
config:
ledgerPath: 'D:/dsh/ledger.json' # default: /token-ledger/ledger.json
backfill: false # default: true — fold stored history on startup
backfillLogs: false # default: true — read the session logs on disk too
rates: false # default: true — false makes no network request at all
# rates also takes an object:
# rates:
# source: modelsdev # default: the per-vendor dataset; 'openrouter' for gateway quotes
# refreshIntervalMs: 1800000 # default: 30 minutes
# perVendor: 3 # default: 3 newest models per vendor
# vendors: 15 # default: cap on how many vendors to publish; 0 for all
# modelsUrl: 'https://…' # default: per source — https://models.dev/api.json
# fxUrl: 'https://…/latest/USD' # default: open.er-api.com
# Monthly plans, for the bill's plan grouping. Each is amortized over the days
# a bill covers, so a partial month is billed partially.
subscriptions:
- vendor: deepseek # which vendor's usage this plan covers
plan: 'DeepSeek 包月' # the name shown on the bill
amount: 199 # the fee per month
currency: CNY # the currency the fee is quoted in
startedAt: '2026-09-01' # optional: not billed before this day
endedAt: null # optional: not billed after this day
note: null # optional: free text, shown with the plan
# How the page shortens the session list. The export is never shortened, so these
# only change what is on screen.
# bill:
# foldSmallSessions: true # default: true — false lists every session on the page too
# smallSessionCost: 1 # default: 1, in the bill's currency
# smallSessionCalls: 10 # default: 10
rates: false disables the pricing feature's networking entirely and leaves
hand-entered values as the only source. That is the setting a strictly offline host
wants; the rates page still works.
Where the history comes from
A fresh install shows the ledger you already have rather than one that starts today. Two sources are folded at startup, and each session is owned — permanently — by whichever of them folded it first.
- The session logs on disk,
/sessions/ //session.jsonl.zstd. This is the durable record, it is complete, and it needs nothing from the host: they are the same filesrebuildandauditread. Every session nobody has folded yet comes from here, which is what makes a first install show its history instead of an empty page. sessionPersistence, the host service. It covers what a log cannot — a session whose file has not been written yet — and it is the incremental path for the sessions the live event stream folded.
They hand over different arrays: a log is the harness's compact row form, whose indices mean
something else than the logical event list's. A cursor is therefore only ever advanced by the
source that set it, and the other one refuses rather than re-counting a session. backfillLogs: false keeps the startup fold off the disk; backfill: false turns both off and starts empty.
The disk fold reads one session per turn of the event loop, so a first run cannot stall the
host, and it skips every log that has not been written since the previous pass from a single
stat. A host that has run before pays nothing for history it already folded — only the first
run, or the one after a session was resumed outside this host, opens a file.