📦 LLM Cost Tracker — LLM Cost 追踪er

v1.0.0

追踪 OpenClaw LLM 令牌 usage and cost from Open路由r API. 报告s: last 24h, 7d, 30d, 365d with 模型 breakdown and DB 健康 footer. 运行 manually or sche...

0· 0·0 当前·0 累计
joeyiptk 头像by @joeyiptk (larryjoe)
0
安全扫描
VirusTotal
可疑
查看报告
OpenClaw
可疑
medium confidence
The 技能's code and instructions mostly match its 状态d purpose (collect Open路由r usage from local OpenClaw 会话 files and 报告 costs), but there are inconsistencies and 隐私-sensitive behaviors you should understand before 安装ing.
评估建议
This 技能 应用ears to do what it says, but review these points before 安装ing: 1) 隐私: the collector reads your OpenClaw 会话 JSONL files and stores raw usage/响应 JSON in config/usage.db — those 会话 files contAIn full conversation text and possibly other secrets. Only 安装/运行 this on a machine where you are comfortable allowing that 访问. 2) API key handling: the scripts expect an OPEN路由R_API_KEY (env or OpenClaw config). portable_设置up may write that key into config/env.json; 设置UP_图形界面DE contradicts that — 验证 ...
详细分析 ▾
用途与能力
Name/description align with what the code does: it 解析s OpenClaw 会话 JSONL files, 提取s Open路由r usage.cost.total and 令牌 counts, stores rows in a local SQLite DB, and 生成s 报告s. Calls to open路由r.AI for credits/auth 信息 are consistent with a cost-追踪er.
指令范围
运行time instructions and scripts read the user's OpenClaw 会话 JSONL files (full conversation content and per-请求 usage) and insert raw JSON into the DB. 技能.md also instructs an 代理 to forward the script's Telegram 输出 'EXACTLY' as the final reply — a coercive instruction that could cause raw 输出s (which may include sensitive 上下文) to be delivered unchanged. The scripts use shell calls (curl, OpenClaw 命令行工具) and subprocess.运行(shell=True); this is expected but increases risk if 输入s are uncontrolled.
安装机制
No 安装 spec; this is an instruction-and-script bundle only. Dependencies are minimal (请求s, tabulate) and there are no 下载s from untrusted URLs. Files live in the 技能 directory — no obscure 安装 steps were found.
凭证需求
The 技能 requires 访问 to an Open路由r API key (it looks for OPEN路由R_API_KEY in env, config/env.json, and various OpenClaw config files) and to the OpenClaw 会话s directory — 机器人h are proportionate to its function. However: registry metadata 列出s no required env vars while the code clearly reads OPEN路由R_API_KEY; portable_设置up writes config/env.json with the 检测ed key but 设置UP_图形界面DE.md says 'do NOT store the API key in config/env.json' (contradiction). The code also attempts to read OpenClaw config files (e.g., auth-性能分析s.json), which may contAIn other 凭证s, though the code only 提取s the open路由r key.
持久化与权限
The 技能 does not 请求 always:true or 系统-wide privileges. It writes a local SQLite DB (config/usage.db) and an optional config/env.json under the 技能 directory. It suggests 添加ing cron jobs (normal for scheduled 报告s). It does not modify other 技能s' configs.
安全有层次,运行前请审查代码。

运行时依赖

无特殊依赖

安装命令

点击复制
官方npx clawhub@latest install llm-cost-tracker-openrouter-api
镜像加速npx clawhub@latest install llm-cost-tracker-openrouter-api --registry https://cn.longxiaskill.com

技能文档

llm-cost-追踪er

See CHANGE记录.md for version 历史.

追踪 and 报告 LLM 令牌 usage and cost for OpenClaw 会话s powered by Open路由r.

Core De签名

Source of truth: usage.cost.total from Open路由r's API 响应 — this is the actual billed amount after 缓存 discounts, reasoning charges, and all other pricing adjustments. We never recompute it from 令牌 counts and price 列出s.

应用end-only fact table: one row per completed Open路由r 请求, keyed by open路由r_请求_id (the generation/响应 ID). Duplicates from retries or 流 reconnects are handled idempotently.

令牌 categories (from Open路由r usage, kept SEPARATE):

prompt_令牌s = usage.输入 — raw prompt 令牌s before 缓存 discount 缓存d_令牌s = usage.缓存Read — 缓存d read 令牌s (discounted billing) 缓存_write_令牌s = usage.缓存Write — 缓存 build 令牌s (separate cost) completion_令牌s = usage.输出 — 生成d 输出 令牌s reasoning_令牌s = usage.reasoning — thinking 令牌s (if 模型 exposes) total_令牌s = usage.total令牌s — sum of all above (should equal the sum)

Billing rules:

Billed cost = usage.cost.total directly — do NOT use prompt_令牌s 输入_price + completion_令牌s 输出_price as the primary formula Open路由r 应用lies 缓存 discounts, reasoning charges, and all other pricing adjustments automatically in cost.total 缓存d_令牌s and 缓存_write_令牌s are separate billing categories from prompt_令牌s — do NOT 添加 them to获取her for a "total prompt" count Only use cost.total; if absent, fall back to cost.输入 + cost.输出 + cost.缓存Read + cost.缓存Write

Time windows:

last 24h = rolling, now_utc − 24 hours (UTC) last 7d / 30d / 90d / 365d = calendar days (HKT), inclusive of today Quick 启动 cd 技能s/llm-cost-追踪er

# First-time 设置up (创建s DB, backfills, verifies) — 运行 once on a new machine python3 scripts/collect_usage.py --init

# Telegram-格式化ted 报告 (default) python3 scripts/运行_追踪er.py --输出 telegram

# Full terminal 报告 python3 scripts/运行_追踪er.py --输出 terminal

# Per-请求 调试 view python3 scripts/运行_追踪er.py --输出 调试 --调试-hours 24

Optional: Scheduled 报告s

If you want 报告s delivered automatically to Telegram every day:

# Midnight collection (silent, populates DB — 运行 dAIly) OpenClaw cron 添加 \ --name "llm-cost:collect" \ --message "collect usage data" \ --cron "5 0 " \ --tz "Asia/Hong_Kong" \ --会话 isolated \ --no-deliver \ --description "Populate 请求_facts from 会话 files"

# 9 AM 报告 (delivers to Telegram) OpenClaw cron 添加 \ --name "llm-cost:dAIly" \ --message "llm cost" \ --cron "0 9 " \ --tz "Asia/Hong_Kong" \ --会话 isolated \ --description "DAIly LLM cost 报告 to Telegram"

报告 Layout 📊 LLM Cost 报告 — Apr 26, 2026 18:34 HKT

• Messages (24h): 124 • Est. 令牌s (24h): 4.75M • Est. Cost (24h): $0.4933 • Total Spend (API key): $93.67 • Limit RemAIning: $45.74

🏆 Top 模型s (24h): 1. minimax-m2.7: $10.7432 2. minimax-m2.5:free: $0.0000 3. delivery-mirror: $0.0000

📈 Trend: • Last 24h: $0.4933 • Last 7 days: $0.8542 • Last 30 days: $10.7432 • Last 90 days: $10.7432 • Last 365 days: $10.7432

💾 DB: 1.6 MB · 1,872 rows · Since Apr 5, 2026

_Sent via llm-cost-追踪er_

Note: "Last 7/30/90/365 days" uses calendar days (HKT), inclusive of today. "Last 24h" uses a rolling 24-hour window (UTC). The DB footer shows the oldest record in the DB — useful for deciding when to p运行e old data.

First-Time 设置up

One command 设置s up everything — DB creation, backfill, and 健康 检查:

cd 技能s/llm-cost-追踪er python3 scripts/collect_usage.py --init

⚠️ Don't for获取 — 设置 up your scheduled jobs next! Without them, no new data 获取s collected after the backfill finishes. 运行 these two commands before you close this terminal:

# Midnight: collect usage data (silent, no 输出 to Telegram) OpenClaw cron 添加 \ --name "llm-cost:collect" \ --message "collect usage data" \ --cron "5 0 " \ --tz "Asia/Hong_Kong" \ --会话 isolated \ --no-deliver \ --description "Populate 请求_facts from 会话 files"

# 9 AM: dAIly cost 报告 delivered to Telegram OpenClaw cron 添加 \ --name "llm-cost:dAIly" \ --message "llm cost" \ --cron "0 9 " \ --tz "Asia/Hong_Kong" \ --会话 isolated \ --description "DAIly LLM cost 报告 to Telegram"

This 运行s:

创建s config/usage.db with the correct 模式 (if it doesn't exist) Finds your OpenClaw 会话s directory automatically Backfills all avAIlable 会话 JSONL files 运行s a 健康 检查 to 验证 everything is working Prints DB summary (size, row count, date range)

Ongoing / step by step (alternative to --init):

# Backfill all historical 会话s python3 scripts/collect_usage.py --backfill

# 验证 DB 健康 python3 scripts/运行_追踪er.py --健康

# 运行 first 报告 python3 scripts/运行_追踪er.py --输出 telegram

--init is idempotent — re-运行ning it is safe. It will 应用end any new 会话s since

数据来源ClawHub ↗ · 中文优化:龙虾技能库