ClawsJoy/dsh-plugins--packages-token-cost ↗★ 0
@clawsjoy/dsh-token-cost
可配置价格的 Token 使用量转费用服务 适合需要自定义 Token 计费单价以准确统计 API 消耗成本的自建或企业用户。
安裝
此插件尚未提供可驗證的 bundle,或相容性檢查未通過。請先閱讀倉庫說明。 閱讀完整 README ↗
說明文件
閱讀完整 README ↗@clawsjoy/dsh-token-cost
A ctx.tokenCost service converting recorded token usage into cost, with
configurable pricing.
Why configurable
The patch this replaces hard-coded DeepSeek's shared-key rates (input ¥0.001/1K, output ¥0.002/1K, reasoning ¥0.004/1K) and an integer unit of 1/10000 ¥. Prices change, and a self-hoster may be on different rates, so the table is configuration with those defaults and an explicit unit.
API
ctx.tokenCost.cost({ inputTokens, outputTokens, reasoningTokens, cacheReadTokens })
// -> { units: 70, fullyPriced: false } units = 1/10000 ¥
ctx.tokenCost.yuan(usage) // -> "0.0070"
fullyPriced: false means at least one token bucket had no price — the total is
a floor, not a lie.
Scope (honest)
This is the server half. Rendering cost in the conversation stats line is a separate client plugin (the client-module surface); it is not part of this package yet.
Install
dsh plugin --profile web add @clawsjoy/dsh-token-cost
- insert:
- id: token-cost
name: '@clawsjoy/dsh-token-cost'
config:
input: 0.001
output: 0.002
reasoning: 0.004
cachedInput: 0
Verification
pnpm test
License
MIT