技能标识:token-cost-estimator
Estimate API token costs from OpenClaw session transcripts. Analyzes all agent sessions to calculate what you'd pay on per-token pricing vs subscription plans. Use when asked about API costs, token usage, billing estimates, or comparing Max/Pro plans to pay-per-use.
根据 OpenClaw 会话记录数据估算真实的 API 成本。
OpenClaw 将会话记录以 JSONL 文件格式存储在 ~/.openclaw/agents/
运行以下 Python 脚本来分析所有智能体:
python
import json, glob, os
AGENTS_DIR = os.path.expanduser(~/.openclaw/agents)
agentdirs = [d for d in os.listdir(AGENTSDIR) if os.path.isdir(os.path.join(AGENTS_DIR, d))]
grandin, grandout = 0, 0
for agent in sorted(agent_dirs):
sessdir = os.path.join(AGENTSDIR, agent, sessions)
if not os.path.isdir(sess_dir):
continue
totalin, totalout, sessions = 0, 0, 0
for f in glob.glob(os.path.join(sess_dir, *.jsonl)):
sessions += 1
turns = []
for line in open(f):
try:
obj = json.loads(line)
msg = obj.get(message, {})
if not isinstance(msg, dict): continue
role = msg.get(role, )
raw = json.dumps(msg)
turns.append((role, len(raw)))
except: pass
# 考虑上下文重新发送
cumulative = 0
for role, chars in turns:
if role in (user, system, tool):
cumulative += chars
elif role == assistant:
total_in += cumulative // 4
total_out += chars // 4
print(f{agent}: {sessions} 个会话, ~{totalin:,} 输入, ~{totalout:,} 输出 Token)
grandin += totalin
grandout += totalout
print(f\n总输入: ~{grandin:,}, 总输出: ~{grandout:,})
for tier, rates in PRICING.items():
for cache_pct in [0.6, 0.9]:
cached = int(grandin * cachepct)
uncached = grand_in - cached
cost = (uncached/1e6)rates[input] + (cached/1e6)rates[cacheread] + (grandout/1e6)*rates[output]
print(f{tier} ({int(cache_pct*100)}% 缓存): ${cost:,.2f})
上下文重新发送: 每次 API 调用都会发送完整的对话历史作为输入。一个 50 轮次的对话会在每条新消息中重新发送之前的所有轮次。这是第一大成本驱动因素。
缓存命中: OpenClaw 会缓存提示前缀。典型缓存命中率:60-90%。缓存读取成本比全新输入低 87.5%。
记录缺失的内容: 系统提示、工具定义和内部重试并不总是被记录。实际成本通常是记录估算值的 1.5-2 倍。
| 方案 | 月费 | 最佳适用场景 |
|---|---|---|
| API (Opus) | 按量计费 | 重度智能体使用(月均超过 $200) |
| API (Sonnet) |
盈亏平衡点: 如果估算的 API 成本超过订阅价格,则订阅更省钱。注意:Anthropic 已限制第三方工具中的 OAuth Token 使用。
以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:
帮我安装 SkillHub 和 token-cost-estimator-1776291375 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 token-cost-estimator-1776291375 技能
skillhub install token-cost-estimator-1776291375
文件大小: 2.29 KB | 发布时间: 2026-4-16 16:58