Scan your whole stack
Are you using dsh-usage-ledger?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v0.1.0
dsh-usage-ledger was last scanned on 29 Nov 2026 at version 0.1.0. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 0.1.0 LATEST | 29 Nov 2026 | No rules fired |
| 0.0.0-stage | 29 Nov 2026 | Not shown |
Findings for v0.1.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 0.1.0; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
AI 网关用量账(usage.jsonl)离线分析工具:解析账本、按 key/模型/租户/天多维汇总、网关侧 vs 厂商账单侧两本账对账、异常消费者归因。落盘 schema 与 AIGate / pro-litellm4java 的 UsageEvent.toJsonNode() 逐字段对齐;单价核算直接 import 同系列 dsh-price-catalog(最长前缀口径一致,不重写)。零额外第三方运行时依赖,纯同步,只读分析。
本插件是六期依赖序「D12→D11」的下游件:已按依赖序发版顺序,直接 import 已发版的 dsh-price-catalog@0.1.0 公开 API 做重算,非注入降级。
npm install dsh-usage-ledger
需要 Node.js 18 及以上。依赖 dsh-price-catalog(自动随 npm 安装)。四个工具:parse_usage_jsonl / aggregate_usage / reconcile_cost / attribute_report。
每行一个 UsageEvent 的 snake_case JSON,20 个字段:
| 字段 | 类型 | 含义 | 缺省容错(对齐 UsageJsonlReader) |
|---|---|---|---|
| trace_id | string | 链路追踪 id | 缺→null |
| at | ISO-8601 | 事件时刻 | 缺或非法→整行跳过 |
| kind | CHAT|EMBEDDING | 调用类型 | 缺→CHAT;非法→strict 跳过 |
| stream | boolean | 是否流式 | 缺→false |
| model_group | string | 模型组(路由层) | 缺→null |
| deployment_model | string | 实际部署模型名 | 缺→null |
| vendor | string | 厂商标识 | 缺→null |
| key_alias | string | 虚拟 key 别名 | 缺→null |
| key_org | string | 租户组织(v1.9) | 缺→null |
| key_team | string | 租户团队 | 缺→null |
| session_id | string | 会话 id(v1.10) | 缺→null |
| prompt_tokens | int | 输入 token | 缺→null |
| completion_tokens | int | 输出 token | 缺→null |
| total_tokens | int | 总 token | 缺→null |
| cost_usd | double | 网关侧已算成本 | 非数字→null |
| priced | boolean | 是否命中价目 | 缺→false |
| estimated | boolean | token 是否为估算 | 缺→false |
| latency_ms | long | 延迟 | 非数字→null |
| error_type | 枚举/null | 错误类型(null=成功) | 非法→strict 跳过 |
| success(派生) | boolean | = error_type is null | 解析时归出 |
error_type 合法值:AUTHENTICATION / RATE_LIMIT / INVALID_REQUEST / CONTENT_FILTER / SERVER_ERROR / TIMEOUT / CONNECTION / CANCELLED / BUDGET_EXCEEDED / UNKNOWN。
逐行解析账本,容错对齐 AIGate UsageJsonlReader:空行忽略;非法 JSON 或非对象行跳过(unparsable/not_object);缺 at 或 at 不可解析跳过(missing_at/bad_at);kind 缺省 CHAT,默认 strict 下非法 kind/error_type 整行跳过(与 Reader valueOf 抛错→skip 同构),opts.strict_enum=false 时降级为警告。归一出 at_ms/day/hour/success 派生字段。返回 events/meta/skipped/warnings。trace_id 等明细在此阶段原样保留,脱敏放到 attribute_report。
按 opts.dims(默认 key_alias+deployment_model+day,可选 model_group/vendor/key_org/key_team/session_id)切片汇总,每片给事件数、三类 token、cost_usd(落盘)、recompute_cost_usd(按 D12 重算)、cost_null、success、error_events、errors_by_type、estimated、priced、stream、延迟分位(min/max/avg/p50/p95/p99)。另有全局 totals 与 recompute_delta_usd(重算−落盘,反映价目快照差异)。opts.no_recompute=true 跳过重算,opts.prices 注入覆盖价目。
网关侧账本 vs vendor_bill(厂商账单侧数组)。自动选模式:账单含 trace_id 走 trace 级逐条对账,否则走 model 汇总级。每对给 gateway_cost/vendor_cost/cost_diff/token_diff。返回 summary{matched,mismatched,gateway_only,vendor_only,net_diff_usd} 与四个明细数组。附 recalc_vs_gateway(落盘 cost_usd vs 按 D12 重算总差),定位「网关算的钱」与「按当期价目应算的钱」之间的偏差。opts.tolerance_usd/tolerance_rel 控制容差(默认 1e-6)。
按 key_alias 归因,检测:concentrated(单 key token 占比≥阈值)、high_error_rate、high_estimated(疑似缺 stream_options.include_usage)、unpriced_cost(有落盘成本却 priced=false,自相矛盾)、off_hours(深夜活跃)、phantom_cost(0 token 却有成本)、price_recalc_drift(落盘 vs D12 重算偏差 top alias)。返回 findings[]/counts/consumer_overview[]/grand。opts.redact_alias=true 时 key_alias 出 sha256 指纹不回显明文,trace_id 明细一律指纹。阈值经 opts.thresholds 注入。
prompt/completion/total_tokens 一律用账本里的值(网关侧已落盘,权威来自 provider usage 或上游 SSE 估算)。estimated=true 仅作为信号透出,不改动 token 数。recompute_cost = Σ(prompt_tokens/1M × input_price + completion_tokens/1M × output_price),单价经 dsh-price-catalog queryPrice 最长前缀命中,与网关 CostCalculator.cost 同构。unknown 模型或 null token 计 0。net_diff = 网关总成本 − 厂商账单总成本,正=网关多记(疑计费 bug/重复入账),负=厂商多收(疑网关漏记或价目版本滞后)。trace 级看逐条,汇总级看模型级。price_recalc_drift 会体现——这是预期信号而非错误,精确对账须注入与账单同期的价目表。redact_alias=true 切为 sha256 指纹。trace_id 在 parse/aggregate 阶段原样保留(供单行审计回溯),仅在对账差异样本 recompute_diff_sample 中做 sha256 指纹;attribute_report 的异常样本用行号(line)或 key_alias 维度定位,findings 不含明文 trace_id。queryPrice 公开 API,与网关 CostCalculator 同构(精确→去前缀→最长前缀)。依赖序 D12→D11,D12 已先发版。estimate_stream_usage 处理的是「一次流的用量估算」,本插件处理的是「落盘后的账本统计」。D10 估出的 estimated token 若被网关写入 usage.jsonl,本插件按 estimated=true 透出但不二次改写。reconcile_cost(trace 级),看 net_diff_usd 与 mismatched[]——逐条定位是 token 数差还是单价差,再查 recalc_vs_gateway 判断是否价目版本滞后。attribute_report 看 concentrated + high_error_rate + phantom_cost,定位「某 key 吃掉大半 token」「某 key 大量 0-token 却计费」等治理线索,必要时 redact_alias 出脱敏版对外。aggregate_usage dims=[key_org, key_team],得到 org/team 维度的 token 与成本分布,供内部分账或限额核算。Q:cost_usd 用落盘值还是重算值?
A:两者都给。cost_usd 是账本里的落盘值(网关当时算的),recompute_cost_usd 是按 dsh-price-catalog 当期价目重算的。对账以落盘值对账单,重算差用于发现价目漂移或 estimated 流偏差,不互相覆盖。
Q:为什么非法 kind 整行跳过而不是报错?
A:对齐 AIGate UsageJsonlReader——它 kind 走 Kind.valueOf、error_type 走 ErrorType.valueOf,非法值抛异常被 catch 后「跳过该行(warn 不 fatal)」。本插件复刻这个健壮性,坏行不致命,全量进 skipped[] 可审计。opts.strict_enum=false 可改成降级保留。
Q:trace_id 会不会明文泄露?
A:分场景。parse/aggregate 的 events 里 trace_id 原样明文(那是单行定位/审计回溯用的,由你自己控制是否外发);reconcile_cost 的差异样本 recompute_diff_sample 把 trace_id 做成 sha256 指纹;attribute_report 的异常样本根本不带 trace_id——phantom_cost 用行号(line)定位、price_recalc_drift 用 key_alias 维度定位。key_alias 本身是否明文由 redact_alias 控制。
Q:能直接读磁盘上的 usage.jsonl 吗? A:不能,也不应该。本插件纯离线、只接受字符串入参,不碰文件路径——避免把网关进程的轮转目录、文件权限等环境耦合带进来。调用方自行把账本内容读出后传入。
Q:reconcile 的两个模式怎么选? A:看你的厂商账单粒度。账单逐条带 trace_id 就 trace 级精确对账;账单只有按模型/按日汇总就用 model 汇总级。插件按账单是否含 trace_id 自动判定,无需手动指定。
Q:重算和落盘差很大正常吗?
A:常见且通常正常——多半是价目快照版本不同(网关当时用的价 ≠ dsh-price-catalog 内置快照),或大量 estimated 流。把它当信号:要么注入与账单同期的价目表重算,要么核对这些 key 是不是真没开 include_usage。
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.