Track and analyze your OpenClaw session costs. Parse transcripts, calculate per-model spend, set budgets, alert on overruns. Stop burning money blindly.
你的智能体每轮都会消耗令牌。此技能能精确告诉你消耗了多少。
bash
bash
today = date.today().isoformat()
total = 0
sessions = 0
for f in glob.glob(os.path.expanduser(~/.openclaw/agents//sessions/.jsonl)):
if today in os.path.basename(f) or os.path.getmtime(f) > import(time).time() - 86400:
sessions += 1
with open(f) as fh:
for line in fh:
try:
cost = json.loads(line).get(message,{}).get(usage,{}).get(cost,{}).get(total,0)
if cost: total += cost
except: pass
print(f今日会话数: {sessions})
print(f总支出: ${total:.4f})
print(f平均每会话: ${total/max(sessions,1):.4f})
PYEOF
添加到你的心跳中:
markdown
bash
bash
python3 << PYEOF
import json, glob, os, time
from collections import defaultdict
models = defaultdict(float)
for f in glob.glob(os.path.expanduser(~/.openclaw/agents//sessions/.jsonl)):
if os.path.getmtime(f) > time.time() - 86400:
with open(f) as fh:
for line in fh:
try:
msg = json.loads(line).get(message, {})
model = msg.get(model, unknown)
cost = msg.get(usage, {}).get(cost, {}).get(total, 0)
if cost: models[model] += cost
except: pass
for model, cost in sorted(models.items(), key=lambda x: -x[1]):
print(f {model:50s} ${cost:.4f})
PYEOF
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 agent-session-cost-1776285552 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 agent-session-cost-1776285552 技能
skillhub install agent-session-cost-1776285552
文件大小: 1.87 KB | 发布时间: 2026-4-16 17:59