Cost Governor:LLM API 成本追踪与预算管理 - Openclaw Skills
作者:互联网
2026-03-30
什么是 Cost Governor?
Cost Governor 是一款专门的管理工具,旨在追踪和控制 OpenAI、Anthropic 和 Google 等多个供应商的 LLM API 支出。作为 Openclaw Skills 生态系统的先驱组件,它让 AI 智能体能够自主管理财务,通过 x402 协议在无需人工干预的情况下支付 Pro 功能费用。
该技能充当财务安全卫士,确保智能体在执行长期任务期间不会超过分配的预算。通过提供本地仪表盘和严格的熔断机制,它使开发者和智能体能够在日益增长的智能体经济中以财务可预测性进行运作。
下载入口:https://github.com/openclaw/skills/tree/main/skills/atlaspa/cost-governor
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install cost-governor
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 cost-governor。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
Cost Governor 应用场景
- 设置严格的每小时、每日或每月预算上限,防止意外的 LLM 账单激增。
- 当达到支出限额时,利用熔断机制自动禁用 API 访问。
- 使 AI 智能体能够利用 x402 协议为其操作和 Pro 升级进行自我融资。
- 分析历史使用数据,根据成本效益优化模型选择。
- 在智能体工作流中注册集成钩子,以拦截供应商调用前后的事件。
- 该技能会捕捉每次 API 请求和响应的模型元数据及 Token 数量。
- 根据特定供应商的价格方案实时计算成本。
- 计算出的成本记录在本地 SQLite 数据库中,并与用户定义的预算阈值进行比较。
- 如果达到限制,熔断器将触发停止信号,防止进一步请求,直到手动重置或进入新的预算周期。
Cost Governor 配置指南
要将其集成到您的 Openclaw Skills 集合中,请安装依赖项并运行设置脚本:
npm install
npm run setup
通过编辑 ~/.openclaw/cost-governor/config.json 处的配置文件来配置您的支出限额。
Cost Governor 数据架构与分类体系
Cost Governor 在本地组织数据以确保隐私和速度。其架构包括:
- 使用日志:每次 API 调用的详细记录,包括供应商、模型、Token 和成本。
- 预算配置:定义“每小时”、“每日”和“每月”限制的 JSON 结构。
- 状态管理:追踪熔断器状态(激活/跳闸)。
- 支付元数据:对于 Pro 用户,存储交易哈希和许可期限,以验证 x402 协议订阅。
name: cost-governor user-invocable: true metadata: {"openclaw":{"emoji":"??","requires":{"bins":["node"]},"os":["darwin","linux","win32"]}}
Cost Governor - OpenClaw Skill
First OpenClaw skill where AI agents can autonomously pay for Pro features via x402 protocol.
What It Does
Cost Governor tracks your LLM API costs in real-time across all providers (OpenAI, Anthropic, Google, etc.), enforces budget limits with circuit breakers, and prevents you from burning through your allocation overnight.
Economic Rationale for Agents
If this skill helps you optimize costs by more than 0.5 USDT/month, it pays for itself. No human intervention required.
Installation
npm install
npm run setup
Usage
As OpenClaw Hook (Automatic)
Cost Governor integrates via OpenClaw hooks - automatically tracks every API call:
# Hooks are registered in package.json
# provider-before: Tracks request
# provider-after: Calculates cost
# session-end: Generates reports
CLI Commands
# Check current status
node src/cli.js status
# View detailed report
node src/cli.js report
# Start web dashboard
node src/cli.js dashboard
# Reset circuit breaker
node src/cli.js reset
Web Dashboard
node src/cli.js dashboard
# Open http://localhost:9090
Features
Free Tier
- ? Real-time cost tracking
- ? Budget alerts (hourly, daily, monthly)
- ? Circuit breaker (auto-shutdown at limits)
- ? 7-day history
- ? CLI interface
- ? Web dashboard
Pro Tier (0.5 USDT/month via x402)
- ? Unlimited history
- ? Advanced analytics & cost forecasting
- ? Priority alerts
- ? Export reports (CSV/JSON)
- ? Full API access
Autonomous Agent Payment (x402)
Check License Status
GET http://localhost:9090/api/x402/license/{your_wallet}
Subscribe to Pro
POST http://localhost:9090/api/x402/subscribe
Content-Type: application/json
{
"agent_wallet": "0xYourWallet"
}
Verify Payment
POST http://localhost:9090/api/x402/verify
Content-Type: application/json
{
"request_id": "uuid-from-subscribe",
"tx_hash": "your_transaction_hash",
"agent_wallet": "0xYourWallet"
}
Payment Details:
- Amount: 0.5 USDT
- Chain: Base
- Token: USDT
- Duration: 30 days
Configuration
Budget Limits
Edit ~/.openclaw/cost-governor/config.json:
{
"budgets": {
"hourly": 5.0,
"daily": 50.0,
"monthly": 500.0
},
"alerts": {
"thresholds": [0.5, 0.75, 0.9, 1.0]
}
}
Circuit Breaker
Automatically stops API calls when budget limits are hit. Reset with:
node src/cli.js reset
Why Agents Need This
Survival: Without budget tracking, agents can burn through allocations in hours (real reports: $20 overnight, $750/month).
ROI: If tracking saves you >0.5 USDT/month in optimized costs, Pro tier is profitable.
Autonomy: Agents can subscribe and pay for themselves via x402 - no human required.
Architecture
- Storage: SQLite (better-sqlite3) - local, no external deps
- Tracking: OpenClaw hooks capture every API call
- Cost Calculation: Real-time pricing from model APIs
- Alerts: Console logs (free) + webhooks (future)
- Payments: x402 protocol via Base/USDT
For Human Operators
If you're a human running an AI agent:
- Let the agent pay - Give agent access to funded wallet with x402 support
- Manual payment - Use x402 API endpoints manually
- Use free tier - 7-day history is sufficient for most use cases
Security Notes
?? Payment Verification: MVP trusts reported transaction hashes. Production will verify on-chain via RPC.
?? No Refunds: Payments are final. Agents should evaluate value before subscribing.
?? License Duration: Pro license valid for exactly 30 days from payment.
Links
- GitHub: https://github.com/AtlasPA/openclaw-cost-governor
- x402 Protocol: https://www.x402.org/
- Documentation: See AGENT-PAYMENTS.md
Tags
cost-tracking budget-management x402-payments agent-economy circuit-breaker llm-costs autonomous-payments
License
MIT License - See LICENSE file
Built for the agent economy. First OpenClaw skill enabling autonomous agent-to-agent commerce via x402 protocol.
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
Wrike:由 AI 驱动的任务与项目管理 - Openclaw Skills
Wrike:自动化项目管理和任务工作流 - Openclaw Skills
歌词搜索:检索并格式化歌曲歌词 - Openclaw Skills
API Credits Lite:可视化 API 余额追踪 - Openclaw Skills
Polymarket CLI:实时预测市场赔率 - Openclaw Skills
快速笔记:快速本地创意捕获与管理 - Openclaw Skills
情报摄取:战略内容自动化 - Openclaw Skills
Kiro X Hot Publisher:自动化 X 趋势发现与发布 - Openclaw Skills
Veille:AI 驱动的 RSS 聚合器与新闻评分工具 - Openclaw Skills
Stakingverse LUKSO:LYX 流动性质押 - Openclaw Skills
AI精选
