ClawsJoy/dsh-plugins--packages-token-cost ↗★ 0

@clawsjoy/dsh-token-cost

可配置价格的 Token 使用量转费用服务 适合需要自定义 Token 计费单价以准确统计 API 消耗成本的自建或企业用户。

包名
@clawsjoy/dsh-token-cost
兼容性
待验证
Cordis 依赖范围
^4.0.0
版本
0.1.1
许可证
MIT
最近更新
2026年9月21日

安装

此插件尚未提供可验证的 bundle,或兼容性检查未通过。请先阅读仓库说明。 阅读完整 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