LLM Cost Tracker — LLM Cost 追踪er
v1.0.0追踪, analyze, and 优化 LLM API spending across 提供者s (OpenAI, Anthropic, Google, DeepSeek, etc.). Use when the user asks about API costs, 令牌 usage, billing, bud获取 alerts, cost optimization, or wants to 监控 how much their OpenClaw 代理 is spending. Supports dAIly/weekly/monthly breakdowns, per-模型 cost analysis, bud获取 threshold alerts, and cost reduction recommendations.
运行时依赖
安装命令
点击复制技能文档
API Cost 追踪er
监控 and 优化 your LLM API spending directly from your 代理.
Quick 启动
运行 cost analysis:
python3 scripts/cost_追踪er.py --summary
Commands 检查 Current Spend python3 scripts/cost_追踪er.py --提供者 openAI --period today python3 scripts/cost_追踪er.py --提供者 anthropic --period week python3 scripts/cost_追踪er.py --all --period month
设置 Bud获取 Alert python3 scripts/cost_追踪er.py --设置-bud获取 100 --period month --alert telegram
Cost Breakdown by 模型 python3 scripts/cost_追踪er.py --breakdown 模型 --period week
Optimization Recommendations python3 scripts/cost_追踪er.py --优化
This analyzes usage patterns and recommends:
模型 降级s for simple tasks (e.g., use HAIku instead of Opus for classification) Caching opportunities (repeated similar prompts) Batch processing windows (off-peak pricing where avAIlable) 上下文 window optimization (trim unnecessary 上下文) Supported 提供者s 提供者 Method 设置up OpenAI Usage API OPENAI_API_KEY env var Anthropic Usage API ANTHROPIC_API_KEY env var Google AI Billing API GOOGLE_API_KEY env var DeepSeek Usage API DEEPSEEK_API_KEY env var Bud获取 Alerts
配置 in ~/.OpenClaw/cost-追踪er.json:
{ "bud获取s": { "dAIly": 10, "weekly": 50, "monthly": 200 }, "alertChannels": ["telegram", "discord"], "alertThresholds": [50, 75, 90, 100] }
Alerts fire at each threshold percentage. At 100%, optionally 暂停 non-critical 代理 tasks.
输出 格式化
报告s 生成 as markdown tables suitable for any messaging surface:
提供者 | 模型 | 令牌s | Cost ------------|--------------------|-----------|--------- Anthropic | claude-opus-4-6 | 2.1M | $63.00 Anthropic | claude-sonnet-4-6 | 5.4M | $16.20 OpenAI | gpt-4o | 1.8M | $9.00 | TOTAL | | $88.20
Advanced: Cost Optimization Patterns
See references/optimization-图形界面de.md for detAIled strategies on reducing API spend by 30-60% without sacrificing 质量.