Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

dsh-usage-ledger

Latest version: v0.1.0

Overview

Last scanned
29 Nov 2026
Published
29 Nov 2026
npm package Publisher: geeklei
2 Versions

Scan summary

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.

  • Releases: 2 versions, all published on 29 Nov 2026.
  • Findings: No rules fired in version 0.1.0.

Versions

2 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.1.0 LATEST 29 Nov 2026 No rules fired
0.0.0-stage 29 Nov 2026 Not shown

No rules fired in 0.1.0

Findings

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.

README

The publisher’s own README, as collected from the registry.

dsh-usage-ledger

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。

用量账 schema 速览

每行一个 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。

使用说明

parse_usage_jsonl — 解析

逐行解析账本,容错对齐 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。

aggregate_usage — 多维汇总

按 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 注入覆盖价目。

reconcile_cost — 两本账对账

网关侧账本 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)。

attribute_report — 异常消费者检测

按 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 注入。

统计口径 / 数据表

  • token 直接取落盘值:本工具不重新估算 token,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 级看逐条,汇总级看模型级。
  • 价目是历史快照:重算结果依赖 dsh-price-catalog 的内置快照价目(截止 2026-11-26),若网关落盘用的是更早/更晚价表,price_recalc_drift 会体现——这是预期信号而非错误,精确对账须注入与账单同期的价目表。

安全边界

  • 只读、不联网、不读文件:输入只能是字符串参数(账本文本、账单数组、价目注入),本工具绝不打开文件路径、不发网络请求、不访问账本目录。AIGate 的 usage.jsonl 落盘在网关进程内,离线分析时由调用方把内容作为文本传入。
  • PII/身份最小化:key_alias/org/team/session 是身份归因维度,默认在 attribute_report 透出明文以便排障;redact_alias=true 切为 sha256 指纹。trace_id 在 parse/aggregate 阶段原样保留(供单行审计回溯),仅在对账差异样本 recompute_diff_sample 中做 sha256 指纹;attribute_report 的异常样本用行号(line)或 key_alias 维度定位,findings 不含明文 trace_id。
  • 解析不等于信任:账本可能来自不可信导出;本工具只按 AIGate schema 解析与统计,不据此做鉴权、不计入结算权威。cost_usd 是落盘值非复核值。
  • 资源上界:账本输入 800 万字符、行数 200 万、单行 10 万字符(超限行记 too_long 跳过);延迟分位排序为 O(n log n),其余统计 O(n);异常检测的深夜计数预建 Map,杜绝 O(aliases×events) 退化。无正则回溯。
  • 依赖版本可追溯:重算口径钉死在 dsh-price-catalog 的精确版本,价目快照与其截止日期绑定;换价目版本=换重算结果,对账结论须连价目版本一起留档。

版本历史

0.1.0(2026-11-27)
  • 首版。解析对齐 AIGate UsageJsonlReader 容错(缺 at 跳过、kind 默认 CHAT、非法枚举 strict 跳过、非数字 cost/latency 归 null)。
  • 多维汇总:key_alias/deployment_model/model_group/vendor/key_org/key_team/session_id/day 切片,延迟分位 p50/p95/p99,全局 totals + 重算差额。
  • 两本账对账:trace 级 / model 汇总级自动选模式,matched/mismatched/双向 only 四类差异定位,容差可注入。
  • 异常消费者检测:集中/高错误/高估算/未计价有成本/深夜/幻影成本/价目漂移七类,阈值与脱敏可注入。
  • 真实 import dsh-price-catalog 公开 API(queryPrice)做重算,按唯一模型 memoize,零重写。

RoadMap

  • v0.2:多文件/分片账本合并(对齐 UsageJsonlWriter 的 size 轮转 usage.1.jsonl…),自动跨文件去重(同 trace_id);账本时间窗聚合(按小时/周滚动);导出 xlsx/csv 友好的宽表行(衔接 dsh-xlsx-lite)。
  • v0.3:流式增量聚合(喂入新一段账本,返回累计增量,不重读全量);多币种与汇率注入;按 session 维度的会话级成本归因;与 attribute_report 阈值做基线学习(历史分位自动定阈)。

其他插件集成说明

  • dsh-price-catalog(D12):本插件单价核算直接 import 其 queryPrice 公开 API,与网关 CostCalculator 同构(精确→去前缀→最长前缀)。依赖序 D12→D11,D12 已先发版。
  • dsh-sse-toolkit(D10):D10 的 estimate_stream_usage 处理的是「一次流的用量估算」,本插件处理的是「落盘后的账本统计」。D10 估出的 estimated token 若被网关写入 usage.jsonl,本插件按 estimated=true 透出但不二次改写。
  • dsh-gw-config-lint(D9):D9 体检网关配置层(budget 字段合法性),本插件核算实际花费与预算/账单对账,沿「配置→计量→计费→对账」生命周期接续。
  • dsh-gw-metrics(D13):D13 偏运营指标(TTFT/成功率/限流拒绝率),本插件偏财务用量账,二者读同一网关日志族但输出不同视角。
  • dsh-token-budget-tools:token 计数口径同源;本插件优先用落盘 usage,仅在展示 estimated 信号时引用其口径背景。

典型场景

  1. 月末对账:把网关 usage.jsonl 与厂商账单喂 reconcile_cost(trace 级),看 net_diff_usd 与 mismatched[]——逐条定位是 token 数差还是单价差,再查 recalc_vs_gateway 判断是否价目版本滞后。
  2. 抓异常消费者:attribute_report 看 concentrated + high_error_rate + phantom_cost,定位「某 key 吃掉大半 token」「某 key 大量 0-token 却计费」等治理线索,必要时 redact_alias 出脱敏版对外。
  3. 成本按租户分摊:aggregate_usage dims=[key_org, key_team],得到 org/team 维度的 token 与成本分布,供内部分账或限额核算。

FAQ

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。

OX Radar and Response Center

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.

Where it’s listed

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).

  • npm dsh-usage-ledger

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Ethersphere Hijacked With Crypto Stealing Malware (1)
npm

Ethersphere Hijacked With Crypto Stealing Malware Via Github & npm

Copy of Template Design OX Blog (2)
Research

NGINX2Root: Five Critical NGINX Flaws Expose Web Servers to Remote Code Execution

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

Frame 2085668439 (1)
Group 1261154229