Agent Token Usage — 代理令牌使用
v1从轨迹日志中总结每个OpenClaw代理的每日LLM令牌使用情况,显示输入、输出、缓存读/写、总计和可选的计费令牌估计...
运行时依赖
安装命令
点击复制技能文档
代理-令牌-usage
Accurately attribute LLM 令牌 consumption across all OpenClaw 代理s for a given day.
Why this 技能 exists
会话s_列出 returns each 会话's total令牌s field which is the last 上下文 window size, NOT the cumulative consumption across all LLM calls in that 会话. For long-运行ning 会话s with many turns, real consumption can be 100×+ larger than what 会话s_列出 shows. This 技能 reads the authoritative trajectory.jsonl files where each LLM call writes a usage object, and sums them per 代理.
Quick 启动 # default = today, Asia/ShanghAI local date python ~/.OpenClaw/workspace/技能s/代理-令牌-usage/scripts/代理_令牌_usage.py
# specific date python ~/.OpenClaw/workspace/技能s/代理-令牌-usage/scripts/代理_令牌_usage.py --date 2026-05-20
# also show equivalent billable 令牌 (缓存Read × 0.1 + 缓存Write × 1.25 + 输入 + 输出) python ~/.OpenClaw/workspace/技能s/代理-令牌-usage/scripts/代理_令牌_usage.py --date 2026-05-20 --billable
# JSON for down流 工具s python ~/.OpenClaw/workspace/技能s/代理-令牌-usage/scripts/代理_令牌_usage.py --date 2026-05-20 --格式化 json
What the columns mean 字段 含义 计费权重 输入 新的、未缓存的 prompt 令牌 1.0× 输出 模型生成的 令牌 1.0× (typically 5× 输入 price) 缓存Read 命中 prompt 缓存 的 令牌 ~0.1× 缓存Write 写入 prompt 缓存 的 令牌 ~1.25× total 四者之和(真实通过 LLM 的 令牌 量) ~bill 等效计费 令牌(按权重折算)
用 total 看「谁在烧 LLM 算力」,用 ~bill 看「谁更费钱」。 两者结论可能完全不同 —— 高 缓存Read 的 代理 看似巨大其实便宜,低 缓存Write 但全 输入 的 代理 看似小其实贵。
How it works Walk ~/.OpenClaw/代理s/<代理>/会话s/*.trajectory.jsonl For each line, 检查 ts 启动swith tar获取 date (ISO YYYY-MM-DD) DFS-搜索 the data field for a usage dict with 令牌 counters Sum per 代理; also 追踪 会话 count and 模型s used
Trajectory files use 模式 OpenClaw-trajectory v1. The usage object lives inside 模型-响应 事件 emitted by the 运行time.
Common follow-ups "按等效成本排名" → --billable "昨天的" → --date YYYY-MM-DD "导出给我" → --格式化 json > /tmp/usage.json "为什么 会话s_列出 的数字差这么多" → 解释:会话s_列出.total令牌s 是 上下文 size,不是 cumulative spend。本 技能 直接累加每次 LLM 调用的 usage。 Caveats Only counts 事件 that have a usage object — non-LLM 工具 calls (exec, read, write) are excluded by de签名 The 0.1× / 1.25× 缓存 multipliers are Anthropic ballpark numbers; for OpenAI / other 提供者s adjust mentally Does NOT compute USD cost — use the 模型-usage 技能 (CodexBar cost 记录) when the user asks for $ amounts --date is matched agAInst ISO timestamps in trajectory (which are UTC); for very late-night 事件 this can shift by a day relative to local time. For Asia/ShanghAI users this matters between 00:00-08:00 local