Skip to content
cccskills
FreePublished on GitHub

usage-costs

Report AI token usage and estimated costs. Use when: owner asks about costs today/yesterday/this week, per session, or per model. Shows main session, cron jobs, and subagents. Answers: 'how much did today cost?', 'how much was this session?', 'what was last week's spend?'

The English summary is being prepared. Showing the original description.

Works withOpenAI
See how to install

Files included (1)

  • SKILL.md5.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Usage Costs Skill

Reports token usage and estimated costs from OpenClaw sessions.


Load Local Context

CONTEXT_FILE="/path/to/workspace/skills/usage-costs/.context"
[ -f "$CONTEXT_FILE" ] && source "$CONTEXT_FILE"
# Provides: $OWNER_PHONE, $PRICING_INPUT, $PRICING_OUTPUT, $PRICING_CACHE_READ

Data Sources

  1. Live sessions → openclaw status --deep (current token counts per session)
  2. Cron run history → /path/to/openclaw/cron/runs/*.jsonl (usage field per run)
  3. Token history → /path/to/workspace/data/token-history.jsonl (daily aggregates)

Pricing (claude-sonnet-4-6, as of 2026-04)

TypePrice
Input$3.00 / 1M tokens
Output$15.00 / 1M tokens
Cache read$0.30 / 1M tokens
Cache write$3.75 / 1M tokens

Step 1 — Live Session Report

# Get current session token counts
openclaw status --deep 2>/dev/null | grep -E "agent:main|direct|cached" | head -20

Parse output: each row has session_key | kind | age | model | tokens.


Step 2 — Cron History Report

#!/usr/bin/env python3
import json, glob, os
from datetime import datetime, timezone, timedelta

def get_cron_usage(days_back=1):
    cutoff = datetime.now(timezone.utc) - timedelta(days=days_back)
    cutoff_ts = cutoff.timestamp() * 1000

    total_input = 0
    total_output = 0
    runs = []

    for f in glob.glob('/path/to/openclaw/cron/runs/*.jsonl'):
        job_name = os.path.basename(f).replace('.jsonl', '')
        with open(f) as fh:
            for line in fh:
                try:
                    d = json.loads(line)
                    if d.get('ts', 0) >= cutoff_ts and 'usage' in d:
                        inp = d['usage'].get('input_tokens', 0)
                        out = d['usage'].get('output_tokens', 0)
                        total_input += inp
                        total_output += out
                        runs.append({
                            'job': d.get('name', job_name),
                            'input': inp,
                            'output': out,
                            'ts': d['ts']
                        })
                except:
                    pass

    return total_input, total_output, runs

inp, out, runs = get_cron_usage(days_back=1)
cost = (inp / 1_000_000 * 3) + (out / 1_000_000 * 15)
print(f"Cron tokens (last 24h): {inp:,} in / {out:,} out")
print(f"Estimated cost: ${cost:.2f}")
print(f"Runs: {len(runs)}")

Report Formats

"How much did today cost?"

📊 Cost Report — 2026-04-04

Main session: ~276K tokens (100% cached)
Cron runs: 25 runs | X in / Y out tokens
Subagents: N sessions | X tokens

Estimated total: ~$Z
(Cron: $A | Subagents: $B | Main session: estimated $C)

Note: Main session cost is estimated — cache reduces actual cost by ~90%.

"How much this week?"

  • Read from /path/to/workspace/data/token-history.jsonl
  • Sum daily entries for the last 7 days
  • Show per-day breakdown + total

"How much was this session?"

  • Run openclaw status --deep
  • Find agent:main:main row → tokens field
  • Calculate: input_cost + output_cost (apply cache discount if cached%)

Save Daily Report

Append to /path/to/workspace/data/token-history.jsonl:

{"date": "2026-04-04", "input": 133, "output": 17376, "cache_read": 900000, "cost_usd": 0.54, "cron_runs": 25, "subagent_runs": 4}

Cost Extraction Script (from session jsonl files)

This is the authoritative method for extracting real costs — works for Anthropic/Claude models:

python3 -c "
import json, glob, os
from datetime import datetime, timezone

sessions_dir = '/path/to/openclaw/agents/main/sessions'
files = glob.glob(f'{sessions_dir}/*.jsonl')
today = datetime.now(timezone.utc).date()
total_cost = 0
total_cache_write = 0
total_cache_read = 0
sessions_today = 0

for fpath in files:
    mtime = datetime.fromtimestamp(os.path.getmtime(fpath), tz=timezone.utc).date()
    if mtime != today:
        continue
    sessions_today += 1
    with open(fpath) as f:
        for line in f:
            try:
                l = json.loads(line)
                if l.get('type') == 'message' and l.get('message',{}).get('role') == 'assistant':
                    u = l['message'].get('usage',{})
                    total_cost += u.get('cost',{}).get('total',0)
                    total_cache_write += u.get('cacheWrite',0)
                    total_cache_read += u.get('cacheRead',0)
            except: pass

print(f'Today: {sessions_today} sessions — \${total_cost:.2f}')
print(f'Cache writes: {total_cache_write:,} tokens')
print(f'Cache reads: {total_cache_read:,} tokens')
"

⚠️ Provider compatibility:

  • ✅ Works for: Anthropic Claude (sonnet, haiku, opus)
  • ❌ Does NOT work for: Google Gemini, OpenAI GPT — cost field is empty
  • For Google/OpenAI agents: use provider billing dashboard directly

Trigger Phrases

"how much did today cost?" "how much was this session?" "how much this week?" "show me costs"

  • "usage report"
  • "token usage"

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

ai-pa

Free

AI Personal Assistant network skill. Use when: contacting another PA, coordinating with peer agents, scheduling meetings between owners, broadcasting messages, looking up contacts from the local PA directory, or performing any cross-PA task. Reads contact data from data/pa-directory.json in the workspace. Does NOT contain hardcoded contact data — each PA maintains their own directory file.

The English summary is being prepared. Showing the original description.

netanel-abergel/pa-skills6Updated May 10, 2026

ai-pa

Free

AI Personal Assistant network skill for multi-agent PA coordination. Use when: contacting another PA, coordinating with peer agents, scheduling meetings between owners, broadcasting messages to PA groups, or looking up contacts from the local PA directory. Reads contact data from data/pa-directory.json in the workspace.

The English summary is being prepared. Showing the original description.

netanel-abergel/pa-skills6Updated May 10, 2026

ai-pa

Free

Route and execute inter-PA coordination tasks in the OpenClaw multi-agent PA network. Triggers when: contacting another PA, passing a message between owners, broadcasting to a PA group, handling group lead/silence rules, or adding a new PA to the directory. NOT for: contact lookups (use contact-list skill), calendar invites (use meetings skill), or billing issues (use billing-monitor skill).

The English summary is being prepared. Showing the original description.

netanel-abergel/pa-skills6Updated May 10, 2026

OpenClaw API gateway proxy for authenticated SaaS calls (100+ services in references/SERVICES.md). Use ONLY when making an HTTP request to a third-party service that requires the gateway's stored credentials. NOT for direct API calls with bearer tokens already in scope, NOT for monday.com (use monday-for-agents), NOT for WhatsApp (use heleni-whatsapp). Triggers: "call the X API", "fetch from <service>", "send to Slack via gateway", "use the gateway for".

The English summary is being prepared. Showing the original description.

netanel-abergel/pa-skills6Updated May 10, 2026

Automatically creates new skills from complex problem-solving sessions. Triggers at the end of multi-step tasks that required novel approaches, debugging sessions, or workflow creation. Use when: a task took 3+ tool calls, involved a non-obvious solution, or established a pattern likely to recur. Also triggers on: "create a skill from this", "save this as a skill", "this should be a skill".

The English summary is being prepared. Showing the original description.

netanel-abergel/pa-skills6Updated May 10, 2026

Monitor for API billing errors and alert the owner and admin immediately. Use when: an API billing error is detected, a peer PA reports a billing error, or during routine health checks. Handles detection, notification, and fallback model switching. Model-agnostic: works with any LLM provider (Anthropic, OpenAI, Google, etc.).

The English summary is being prepared. Showing the original description.

netanel-abergel/pa-skills6Updated May 10, 2026

See all skills by netanel-abergel

Report a problem with this skill