spend-circuit-breaker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesespend-circuit-breaker
spend-circuit-breaker
OpenClaw has no built-in hard spending cap. This skill monitors session logs to estimate cumulative API cost, alerts at configurable thresholds, and automatically pauses non-essential cron automations when the monthly budget ceiling is hit.
OpenClaw 没有内置的硬性支出上限。本Skill会监控会话日志以估算API累计成本,在达到可配置阈值时发出告警,触及月度预算上限时会自动暂停非必要的cron自动化任务。
Setup (first run)
设置(首次运行)
Before the skill is useful, record your monthly budget in state:
python3 check.py --set-budget 50 # $50/month hard cap
python3 check.py --set-alert 0.5 0.75 # Alert at 50% and 75%在本Skill正常使用前,需要先在状态中记录你的月度预算:
python3 check.py --set-budget 50 # $50/month hard cap
python3 check.py --set-alert 0.5 0.75 # Alert at 50% and 75%Cron Wakeup Behaviour
Cron 唤醒逻辑
Runs every 4 hours (). On each wakeup:
cron: "0 */4 * * *"- Read — load
~/.openclaw/skill-state/spend-circuit-breaker/state.yamlandmonthly_budget_usdspend_this_month_usd - Parse OpenClaw session logs from to estimate new spend since
~/.openclaw/sessions/(model × token counts × price table)last_checked_at - Update and
spend_this_month_usdin statelast_checked_at - Apply threshold logic (see below)
- Reset spend to 0 on the 1st of each month
每4小时运行一次()。每次唤醒时执行以下操作:
cron: "0 */4 * * *"- 读取 —— 加载
~/.openclaw/skill-state/spend-circuit-breaker/state.yaml和monthly_budget_usd配置spend_this_month_usd - 解析 路径下的OpenClaw会话日志,估算自
~/.openclaw/sessions/以来的新增支出(模型 × Token数量 × 价目表)last_checked_at - 更新状态中的 和
spend_this_month_usd字段last_checked_at - 执行阈值判断逻辑(见下文)
- 每月1日自动将支出清零
Threshold logic
阈值逻辑
| Spend % | Action |
|---|---|
| < 50% | Log silently — nothing to surface |
| ≥ 50% | Notify user: "You've used ~50% of your $X budget this month" |
| ≥ 75% | Notify user + suggest which cron skills to pause |
| ≥ 100% | Notify user + automatically pause all |
At 100%, write to state. checks this flag before registering new cron jobs — new installs are allowed, new cron triggers are not.
circuit_open: trueinstall.sh| 支出占比 | 执行操作 |
|---|---|
| < 50% | 静默记录日志 —— 无需对外通知 |
| ≥ 50% | 通知用户:「你本月已使用约50%的$X预算」 |
| ≥ 75% | 通知用户 + 给出可暂停的cron Skill建议 |
| ≥ 100% | 通知用户 + 自动暂停所有 |
当支出占比达到100%时,会向状态文件写入。在注册新的cron任务前会检查该标志位 —— 允许安装新Skill,但不允许新增cron触发规则。
circuit_open: trueinstall.shCircuit reset
熔断重置
To restore automations after a budget reset or manual override:
python3 check.py --reset-circuitThis sets and re-registers all paused cron jobs.
circuit_open: false在预算重置或手动覆盖规则后,可通过以下命令恢复自动化任务:
python3 check.py --reset-circuit该命令会将设为,并重新注册所有已暂停的cron任务。
circuit_openfalseModel price table
模型价目表
The script ships with a price table for common models (claude-3-5-sonnet, gpt-4o, etc.). To add a custom model:
python3 check.py --add-model my-model-name --input-cost 3.00 --output-cost 15.00Prices are per million tokens.
脚本内置了常用模型(claude-3-5-sonnet、gpt-4o等)的价目表。如需添加自定义模型,可执行以下命令:
python3 check.py --add-model my-model-name --input-cost 3.00 --output-cost 15.00价格单位为每百万Token。