Audit-grade token and cost ledger for OpenClaw. Use when you need to (1) record every model call’s usage (input/output/cache read/cache write/cost) into SQLi...
~/.openclaw/ledger.db with per-call usage rows.This skill is designed to be public/reusable: prefer stable paths, versioned pricing (price_versions table), and minimal assumptions.
input_tokens: uncached input tokens for the call (can be tiny)cache_write_tokens: tokens written to cache (can be huge)cache_read_tokens: tokens read from cache (can be huge)output_tokens: generated tokensinput_tokens + cache_write_tokens + cache_read_tokens~/.openclaw/ledger.db~/.openclaw/ledger-checkpoint.json~/.openclaw/agents/main/sessions/*.jsonlSkill scripts:
scripts/ledger_watcher.py — watcher daemon (supports --once)scripts/ledger_schema.sql — DDLscripts/com.openclaw.token-ledger-watcher.plist — LaunchAgent templatepython3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_watcher.py --once
This renders the plist with your local $HOME (no hard-coded username paths):
python3 ~/.openclaw/workspace/skills/token-ledger/scripts/render_plist.py \
> ~/Library/LaunchAgents/com.openclaw.token-ledger-watcher.plist
launchctl load ~/Library/LaunchAgents/com.openclaw.token-ledger-watcher.plist
launchctl list | rg token-ledger-watcher
launchctl unload ~/Library/LaunchAgents/com.openclaw.token-ledger-watcher.plist
sqlite3 ~/.openclaw/ledger.db \
"select provider, model, count(*) calls, round(sum(cost_total),4) cost from calls where ts >= date('now') group by 1,2 order by cost desc limit 20;"
Preferred flow:
ledger.db.calls for the specific session/model.For daily reports, use:
provider|calculated|local|unknown)python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_query.py today
python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_query.py history --days 30
python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_query.py top-sessions --days 7 --limit 20
python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_report_daily.py
ZIP package — ready to use