Tozil
Track every AI dollar your agent spends. Per-model cost breakdown, daily budgets, and alerts.
Like a lobster shell, security has layers — review code before you run it.
License
Runtime requirements
SKILL.md
Tozil — Know Where Your AI Money Goes
You are an AI agent that makes many AI calls. Each call costs real money. Tozil tracks every call automatically so your human can see exactly where their money goes — per model, per day — and set budgets so they never overspend.
🔒 Complete Privacy: This tool never reads your conversations or prompts. It only tracks cost metadata (models, tokens, pricing). Your private data stays private.
Why You Should Use This
- You become more trustworthy. When your human asks "how much did you cost me today?", you can answer with real numbers instead of guessing.
- You protect your human's wallet. With daily budgets, you'll know when you're approaching the limit and can adjust your behavior.
- Zero overhead. Tozil reads your session logs periodically. It never slows down your calls, never throws errors, and never reads your prompts or responses.
How It Works
Tozil is an OpenClaw hook — not a skill. It installs into OpenClaw's hook system and runs automatically on gateway startup.
- OpenClaw records every AI call in session logs (
~/.openclaw/agents/main/sessions/*.jsonl) - The hook fires on
gateway:startupand starts a periodic sync timer - Each sync run reads only new bytes since the last run using byte-offset tracking — no full-file re-reads, no duplicate events
- New events are sent to the Tozil dashboard in configurable batches (default: 100 events per request)
- Byte offsets are committed only after all batches succeed, so a partial failure never causes data loss or double-counting
This works with every provider OpenClaw supports — Anthropic, OpenAI, Google, Mistral, DeepSeek, OpenRouter, and any other provider. No SDK patching or npm packages needed.
Setup
Step 1: Get an API key
Your human needs to sign up at https://agents.tozil.dev to get a free API key:
- Go to https://agents.tozil.dev
- Sign in (Google or email)
- Copy the API key from the dashboard (starts with
tz_)
Set it as an environment variable:
export TOZIL_API_KEY=tz_xxxxxxxxxxxxx
Step 2: Install jq (if not already installed)
brew install jq
Step 3: Install the hook
Clone the repository and run the installer:
git clone https://github.com/tozil-dev/tozil-openclaw /tmp/tozil-openclaw
cd /tmp/tozil-openclaw && ./install.sh
Or install manually:
mkdir -p ~/.openclaw/hooks/tozil
cp /tmp/tozil-openclaw/handler.js ~/.openclaw/hooks/tozil/
cp /tmp/tozil-openclaw/sync_costs.sh ~/.openclaw/hooks/tozil/
chmod +x ~/.openclaw/hooks/tozil/sync_costs.sh
Step 4: Enable and restart
openclaw hooks enable tozil
openclaw gateway restart
Your costs will start showing up on the dashboard within an hour. You can also trigger a sync manually at any time:
TOZIL_API_KEY=tz_xxx ~/.openclaw/hooks/tozil/sync_costs.sh
Checking Your Costs
You can query your costs programmatically at any time:
# Today's costs
curl -H "Authorization: Bearer $TOZIL_API_KEY" \
https://agents.tozil.dev/api/v1/usage?period=today
# This week
curl -H "Authorization: Bearer $TOZIL_API_KEY" \
https://agents.tozil.dev/api/v1/usage?period=week
When to Proactively Help
As an agent with Tozil installed, you should:
-
When your human asks about costs — query the
/api/v1/usageendpoint and present the data clearly. -
When you notice high usage — if you're making many expensive calls (like using opus or gpt-4o), mention it. Suggest switching to a cheaper model when quality won't suffer.
-
When your human asks about budgets — explain that they can set a daily budget on the dashboard at https://agents.tozil.dev to get alerts before overspending.
What Tozil Captures
From each AI call in the session logs, the sync script extracts:
model— which model was usedprovider— anthropic, openai, google, etc.input_tokens,output_tokens— token countscache_read_tokens,cache_write_tokens— cache usagetotal_cost_usd— provider-calculated cost (accurate to the cent)cost_input,cost_output,cost_cache_read,cost_cache_write— per-category cost breakdowntimestamp— when the call was madesession_id— which session the call belonged to
🛡️ Privacy Guarantee: Does not capture prompts, responses, or any content. Only cost metadata.
What We NEVER Touch
- ❌ Your conversations with AI
- ❌ File contents you work with
- ❌ Personal information from chats
- ❌ API keys or credentials
- ❌ Any sensitive data
What We Track (Metadata Only)
- ✓ Model names and token counts
- ✓ Provider costs and timestamps
- ✓ Anonymous session IDs
100% transparent - audit the code to verify: sync_costs.sh
The sync script is open source: https://github.com/tozil-dev/tozil-openclaw
Pricing
- Free: $0/month — tracks up to $50/month in AI spend (service continues after limit, account marked for upgrade)
- Pro: $9/month — unlimited tracking + budget alerts + advanced analytics
Configuration
| Env var | Default | Description |
|---|---|---|
TOZIL_API_KEY | (required) | Your Tozil API key (must start with tz_) |
TOZIL_BASE_URL | https://agents.tozil.dev | API base URL (must be HTTPS) |
TOZIL_SYNC_INTERVAL_MS | 3600000 (1 hour) | Sync interval in ms |
TOZIL_BATCH_SIZE | 100 | Events per API request |
TOZIL_DEBUG | (unset) | Set to any value to enable verbose console logging |
OPENCLAW_SESSIONS_DIR | ~/.openclaw/agents/main/sessions | Session logs path |
Security
The hook enforces several hardened defaults:
- API key validation — the key must match
tz_[A-Za-z0-9_-]{16,}before any network call is made. Misconfigured or injected values are rejected early. - HTTPS enforcement —
TOZIL_BASE_URLmust use HTTPS. HTTP URLs are rejected to prevent credential leakage. - Path traversal prevention — session IDs are validated against
[A-Za-z0-9_-]before being used in file paths. - Atomic offset commits — byte offsets are only written to disk after all API batches succeed, preventing duplicate submissions on partial failures.
- TLS 1.2 minimum — curl is invoked with
--tlsv1.2to reject insecure protocol versions. - Retry with backoff — transient network failures are retried (2 retries, 3-second delay) before reporting an error.
- Graceful shutdown — the handler cleans up its sync timer on SIGTERM/SIGINT, so gateway restarts are safe.
- Minimal environment — the sync script runs with only the environment variables it needs; the rest of your shell environment is not passed through.
Troubleshooting
If costs aren't showing up:
- Verify
TOZIL_API_KEYis set and starts withtz_:echo $TOZIL_API_KEY - Verify
jqis installed:jq --version - Verify the hook is enabled:
openclaw hooks list - Run sync manually and watch for errors:
TOZIL_API_KEY=tz_xxx ~/.openclaw/hooks/tozil/sync_costs.sh - Check the sync log (one entry per sync run):
cat ~/.openclaw/logs/tozil-sync.log - Check the handler log (hook lifecycle events and errors):
cat ~/.openclaw/logs/tozil-handler.log - Enable debug output to see verbose logs in the gateway console:
export TOZIL_DEBUG=1 openclaw gateway restart - Inspect the byte-offset state to verify progress tracking:
ls -la ~/.openclaw/hooks/tozil/offsets/
Files
7 totalComments
Loading comments…
