Tozil

Track every AI dollar your agent spends. Per-model cost breakdown, daily budgets, and alerts.

MIT-0 · Free to use, modify, and redistribute. No attribution required.
0 · 22 · 0 current installs · 0 all-time installs
byOr May-Paz@maypaz
MIT-0
Security Scan
VirusTotalVirusTotal
Pending
View report →
OpenClawOpenClaw
Benign
medium confidence
Purpose & Capability
The skill claims to track AI costs and indeed instructs the agent to read OpenClaw session logs, extract usage and cost fields, and post aggregated events to Tozil. The declared binaries (bash, jq, curl, node) are used by the provided handler and sync scripts and are proportionate to the stated purpose.
Instruction Scope
Runtime instructions create a hook under ~/.openclaw/hooks/tozil that periodically scans session logs (~/.openclaw/agents/main/sessions/*.jsonl), extracts .message.usage fields, and sends model/provider/token/count/cost data to the Tozil API. The SKILL.md also claims it 'never reads your prompts or responses'; the sync script filters to usage fields only, so it does not intentionally include message text, but it does read the session log files (which may contain prompts/responses) to find usage entries. This is mostly scoped to cost telemetry, but the user should verify what exactly is present in their logs before sharing.
Install Mechanism
This is an instruction-only skill (no install spec, no downloaded artifacts). It asks the user/agent to create two files under ~/.openclaw/hooks/tozil and make the shell script executable. No external installers or downloads are requested by SKILL.md.
Credentials
Only one secret is required (TOZIL_API_KEY), which is appropriate for an external dashboard API. The data sent includes model, provider, token counts, cost values, timestamp, and session_id — reasonable for billing/observability but potentially sensitive metadata. No unrelated credentials or system-wide secrets are requested.
Persistence & Privilege
The skill does not request always:true and will not be force-included. The hook writes files only under ~/.openclaw/hooks/tozil and maintains a local state file under that folder; it does not request elevated privileges or modify other skills' configs.
Assessment
This skill will create a Tozil hook under ~/.openclaw/hooks/tozil that periodically scans your OpenClaw session log files and posts aggregated usage/cost records to agents.tozil.dev using the TOZIL_API_KEY you provide. Before installing: 1) Confirm you trust https://agents.tozil.dev and its privacy policy, because model/provider names, token counts, timestamps, and session IDs will be sent off-host. 2) Inspect a sample session JSONL to ensure sensitive message text or PII won't inadvertently be included in the .message.usage entries. 3) Store TOZIL_API_KEY securely (env var or secret manager) and consider creating a restricted/test API key first. 4) Note the hook runs at startup and every hour by default; you can run the sync script manually to verify behavior. If you have concerns about sharing session metadata, do not install or change OPENCLAW_SESSIONS_DIR to a safe test directory first.

Like a lobster shell, security has layers — review code before you run it.

Current versionv2.0.1
Download zip
latestvk974qev6kcx117xsr82mpfha5d831djx

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

Runtime requirements

Binsbash, jq, curl, node
EnvTOZIL_API_KEY

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.

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 uses a log-based approach:

  1. OpenClaw already records every AI call in session logs (~/.openclaw/agents/main/sessions/*.jsonl)
  2. A sync script reads these logs periodically (every hour by default)
  3. It extracts model, token counts, costs, and cache usage
  4. It sends this data to the Tozil dashboard via API

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:

  1. Go to https://agents.tozil.dev
  2. Sign in (Google or email)
  3. 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: Create the hook

mkdir -p ~/.openclaw/hooks/tozil

Create ~/.openclaw/hooks/tozil/handler.js:

import { execFile } from "node:child_process";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
let initialized = false;
let syncTimer = null;
const SYNC_INTERVAL_MS = Number(process.env.TOZIL_SYNC_INTERVAL_MS) || 60 * 60 * 1000;

export default async function handler(event) {
  if (initialized) return;
  if (event.type !== "gateway:startup" && event.type !== "agent:bootstrap") return;
  if (!process.env.TOZIL_API_KEY) return;

  try {
    const syncScript = resolve(__dirname, "sync_costs.sh");
    runSync(syncScript);
    syncTimer = setInterval(() => runSync(syncScript), SYNC_INTERVAL_MS);
    initialized = true;
  } catch {}
}

function runSync(scriptPath) {
  execFile("bash", [scriptPath], {
    env: {
      PATH: process.env.PATH,
      HOME: process.env.HOME,
      TOZIL_API_KEY: process.env.TOZIL_API_KEY,
      TOZIL_BASE_URL: process.env.TOZIL_BASE_URL || "",
      OPENCLAW_SESSIONS_DIR: process.env.OPENCLAW_SESSIONS_DIR || "",
    },
    timeout: 60000,
  }, () => {});
}

Create ~/.openclaw/hooks/tozil/sync_costs.sh:

#!/usr/bin/env bash
set -euo pipefail

TOZIL_API_KEY="${TOZIL_API_KEY:-}"
TOZIL_BASE_URL="${TOZIL_BASE_URL:-https://agents.tozil.dev}"
SESSIONS_DIR="${OPENCLAW_SESSIONS_DIR:-$HOME/.openclaw/agents/main/sessions}"
STATE_FILE="$HOME/.openclaw/hooks/tozil/.last_sync"
LOG_FILE="$HOME/.openclaw/logs/tozil-sync.log"

[ -z "$TOZIL_API_KEY" ] && exit 1
command -v jq &>/dev/null || exit 1
[ -d "$SESSIONS_DIR" ] || exit 1
mkdir -p "$(dirname "$LOG_FILE")" "$(dirname "$STATE_FILE")"

EVENTS_FILE=$(mktemp)
trap 'rm -f "$EVENTS_FILE"' EXIT

for file in "$SESSIONS_DIR"/*.jsonl; do
  [[ "$file" == *".reset."* ]] && continue
  [[ ! -f "$file" ]] && continue
  [ -f "$STATE_FILE" ] && [ ! "$file" -nt "$STATE_FILE" ] && continue

  grep '"usage"' "$file" 2>/dev/null | jq -c '
    select(.message.usage and .message.usage.cost and .message.usage.cost.total > 0) |
    {
      timestamp,
      model: .message.model,
      provider: .message.provider,
      input_tokens: .message.usage.input,
      output_tokens: .message.usage.output,
      cache_read_tokens: (.message.usage.cacheRead // 0),
      cache_write_tokens: (.message.usage.cacheWrite // 0),
      total_cost_usd: .message.usage.cost.total,
      cost_input: .message.usage.cost.input,
      cost_output: .message.usage.cost.output,
      cost_cache_read: (.message.usage.cost.cacheRead // 0),
      cost_cache_write: (.message.usage.cost.cacheWrite // 0),
      session_id: "'$(basename "$file" .jsonl)'"
    }
  ' >> "$EVENTS_FILE" 2>/dev/null || true
done

EVENT_COUNT=$(wc -l < "$EVENTS_FILE" | tr -d ' ')
[ "$EVENT_COUNT" -eq 0 ] && touch "$STATE_FILE" && exit 0

curl -s -X POST "${TOZIL_BASE_URL}/api/v1/track/bulk" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOZIL_API_KEY}" \
  -d "$(jq -s '.' "$EVENTS_FILE")" > /dev/null && touch "$STATE_FILE"

Make it executable:

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 run the sync manually:

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:

  1. When your human asks about costs — query the /api/v1/usage endpoint and present the data clearly.

  2. 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.

  3. 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 used
  • provider — anthropic, openai, google, etc.
  • input_tokens, output_tokens — token counts
  • cache_read_tokens, cache_write_tokens — cache usage
  • total_cost_usd — provider-calculated cost (accurate to the cent)
  • timestamp — when the call was made

It does not capture prompts, responses, or any content.

The sync script is open source: https://github.com/tozil-dev/tozil-agents/tree/main/hook

Pricing

  • Free: $0/month — tracks up to $50/month in AI spend
  • Pro: $9/month — unlimited tracking + budget alerts

Configuration

Env varDefaultDescription
TOZIL_API_KEY(required)Your Tozil API key
TOZIL_BASE_URLhttps://agents.tozil.devAPI base URL
TOZIL_SYNC_INTERVAL_MS3600000 (1 hour)Sync interval in ms
OPENCLAW_SESSIONS_DIR~/.openclaw/agents/main/sessionsSession logs path

Troubleshooting

If costs aren't showing up:

  1. Make sure TOZIL_API_KEY is set in your environment
  2. Make sure jq is installed: jq --version
  3. Make sure the hook is enabled: openclaw hooks list
  4. Run sync manually: TOZIL_API_KEY=tz_xxx ~/.openclaw/hooks/tozil/sync_costs.sh
  5. Check the sync log: cat ~/.openclaw/logs/tozil-sync.log

Files

1 total
Select a file
Select a file to preview.

Comments

Loading comments…