Compare OpenClaw token usage and API cost across time windows, agents, models, and channels.
Project description
openclaw-cost-diff
Compare OpenClaw token usage and API cost across two time windows, agents, models, or channels.
The goal is a small, decision-friendly CLI: what changed, by how much, and which model, agent, or channel contributed most.
Install
pipx install openclaw-cost-diff
For local development:
python -m venv .venv
. .venv/bin/activate
python -m pip install -e ".[dev]"
Examples
openclaw-cost-diff --last 7d --prev 7d
openclaw-cost-diff --agent main --last 30d --json
openclaw-cost-diff --model openai-codex/gpt-5.4 --last 14d --prev 14d
openclaw-cost-diff --from 2026-04-01 --to 2026-04-15 --prev-from 2026-03-17 --prev-to 2026-04-01
openclaw-cost-diff --channel analysis --last 7d --markdown
openclaw-cost-diff --last 7d --top 10 --fail-on-cost-increase 25
Compare different filter sets by applying --prev-agent, --prev-model, or --prev-channel:
openclaw-cost-diff --agent main --prev-agent worker --last 7d --prev 7d
Read a specific fixture or exported transcript directory:
openclaw-cost-diff --data ./fixtures --last 30d
openclaw-cost-diff --data ~/.openclaw/sessions --data ~/.openclaw/transcripts --last 7d
Data Discovery
By default the CLI scans:
~/.openclaw/agents~/.openclaw/sessions~/.openclaw/transcripts~/.openclaw
Set OPENCLAW_DATA_DIR to override the defaults. Multiple paths can be separated with your platform path separator, or you can pass repeated --data arguments.
The loader accepts .json, .jsonl, .ndjson, .log, .txt, and extensionless files. It supports flat records, arrays, sessions, records, and common nested transcript containers such as events, messages, turns, and requests.
For current OpenClaw agent session data, the loader also handles wrapper records where timestamps and channels live on the outer event while model, usage, and cost live under nested objects such as payload.response.usage or message.usage.cost.total. Numeric timestamps may be seconds, milliseconds, microseconds, or nanoseconds, and out-of-range numeric timestamp candidates are ignored instead of crashing the scan.
When usage.input and usage.output are token counts, they are never treated as cost components unless they appear inside an explicit nested cost object.
Cost Field Assumptions
openclaw-cost-diff intentionally avoids pricing tables. It compares cost data that is already present in local OpenClaw records.
Recognized timestamp fields:
timestampcreated_atstarted_atended_attimedate
Recognized token fields:
- Input:
input_tokens,prompt_tokens,tokens_in,input - Output:
output_tokens,completion_tokens,tokens_out,output
Recognized cost fields:
costcost_usdtotal_costtotal_cost_usdapi_costapi_cost_usd- nested
cost.usd - nested
cost.amount - nested
cost.total - nested
message.usage.cost.total
Recognized dimensions:
- Model:
model,model_id,provider_model - Agent:
agent,agent_id,agentId,session_agent - Channel:
channel,role,stream,conversation_channel
Records with missing cost are included in token totals and counted as missing cost records, but they contribute $0.00 to cost totals.
Output
Default terminal output includes:
- total input tokens
- total output tokens
- total cost
- delta amount and percent
- top contributors by model, agent, and channel
- a small cost sparkline
- regression warnings when cost jumps beyond
--regression-threshold
Machine-readable JSON is available with --json. Markdown is available with --markdown.
Limitations
- This tool is a cost comparison utility, not a full observability system.
- It does not infer costs from model pricing tables.
- Month and year relative durations are approximate:
1mis 30 days and1yis 365 days. - Unknown or unsupported transcript shapes may need export normalization before analysis.
- Naive datetimes are treated as UTC.
Release
Tags matching v* run the release workflow:
- Run tests.
- Build the Python package.
- Publish to PyPI using
PYPI_API_TOKENor PyPI trusted publishing. - Create a GitHub release.
- Bump the Homebrew formula in
pfrederiksen/homebrew-tapusingHOMEBREW_TAP_TOKEN.
Do not commit PyPI tokens. Store release credentials as GitHub Actions secrets or use PyPI trusted publishing.
Development
python -m pip install -e ".[dev]"
pytest
openclaw-cost-diff --data fixtures --from 2026-04-13 --to 2026-04-20 --prev-from 2026-04-06 --prev-to 2026-04-13
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openclaw_cost_diff-0.1.5.tar.gz.
File metadata
- Download URL: openclaw_cost_diff-0.1.5.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f47cbfcfc64b7e99644d134e4c8fd0ee7ab79de4562fd2bc363c06d8f9891a5
|
|
| MD5 |
988c91fdc3eaf00d99e0112fd7f1d5f5
|
|
| BLAKE2b-256 |
5184bc502d0ec56d8d642c24c5d196932d4aa484dee05fd5d859002e62c5e790
|
File details
Details for the file openclaw_cost_diff-0.1.5-py3-none-any.whl.
File metadata
- Download URL: openclaw_cost_diff-0.1.5-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ae9bcc103a677b449125a10d52bd49273adc2e27d6c34f300af74f9f26f5588
|
|
| MD5 |
b458b75a3324330e938be9f5eee6c7b9
|
|
| BLAKE2b-256 |
f5e58c51061a8276fc358cd21f61d4bff765ff0f50e7dc9fb5f2a3d6b80009d8
|