返回顶部
s

session-cost会话成本追踪

Track and analyze your OpenClaw session costs. Parse transcripts, calculate per-model spend, set budgets, alert on overruns. Stop burning money blindly.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
372
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

session-cost

会话成本 — 了解你的支出

你的智能体每轮都会消耗令牌。此技能能精确告诉你消耗了多少。

快速成本检查

bash

今日会话


ls -la ~/.openclaw/agents/main/sessions/ | tail -5

解析最新会话的成本

LATEST=$(ls -t ~/.openclaw/agents/main/sessions/*.jsonl 2>/dev/null | head -1) [ -n $LATEST ] && python3 -c import json total = 0 with open($LATEST) as f: for line in f: entry = json.loads(line) cost = entry.get(message,{}).get(usage,{}).get(cost,{}).get(total,0) if cost: total += cost print(f会话成本: \${total:.4f}) || echo 未找到会话

每日支出汇总

bash

今日所有会话


python3 << PYEOF
import json, glob, os
from datetime import date

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

成本检查(每4小时)


运行会话成本检查。如果每日支出超过15美元,提醒人类。

bash

单行预算检查


python3 -c
import json,glob,os,time
t=0
for f in glob.glob(os.path.expanduser(~/.openclaw/agents//sessions/.jsonl)):
if os.path.getmtime(f)>time.time()-86400:
for l in open(f):
try: t+=json.loads(l).get(message,{}).get(usage,{}).get(cost,{}).get(total,0)
except: pass
print(f今日 \${t:.2f})
if t>15: print(⚠️ 超出预算)

按模型分解

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

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 agent-session-cost-1776285552 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 agent-session-cost-1776285552 技能

通过命令行安装

skillhub install agent-session-cost-1776285552

下载

⬇ 下载 session-cost v1.0.0(免费)

文件大小: 1.87 KB | 发布时间: 2026-4-16 17:59

v1.0.0 最新 2026-4-16 17:59
Session-cost 1.0.0 initial release.

- Track and analyze OpenClaw session costs in detail.
- Scripts provided to summarize spend, give per-model breakdowns, and set/alert on budgets.
- Quick cost check, daily summary, and budget alert examples included for easy integration.
- Helps prevent unexpected token usage and spending overruns.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部