← 返回 Skills 市场
netanel-abergel

Billing Monitor

作者 Netanel Abergel · GitHub ↗ · v1.0.2 · MIT-0
cross-platform ⚠ suspicious
126
总下载
0
收藏
1
当前安装
3
版本数
在 OpenClaw 中安装
/install billing-monitor
功能描述
Monitor for API billing errors and alert the owner and admin immediately. Use when: an API billing error is detected, a peer PA reports a billing error, or d...
使用说明 (SKILL.md)

Billing Monitor Skill

Load Local Context

CONTEXT_FILE="/opt/ocana/openclaw/workspace/skills/billing-monitor/.context"
[ -f "$CONTEXT_FILE" ] && source "$CONTEXT_FILE"
# Then use: $OWNER_PHONE, $ADMIN_PHONE, $BILLING_LOG, $BILLING_FALLBACK_CONFIG, etc.

Minimum Model

Any model. Detection and alerting are rule-based. No reasoning required.


When to Run This Skill

Run when you see ANY of these in an API response:

your API key has run out of credits
insufficient balance
billing_error
payment_required
exceeded your current quota
HTTP 402
"type": "billing_error"

When NOT to Alert the Owner

  • Routine billing check completed with no errors → silent, no message
  • HTTP 200 / all clear → silent, no message
  • ElevenLabs 401 (auth, not billing) → silent unless TTS is actively needed

Only alert the owner if:

  1. HTTP 402 detected (out of credits)
  2. LLM is unreachable and the agent cannot function
  3. A peer PA reports a billing error

Routine health checks run silently. The owner does not need a "billing OK" message.

NOTE (Production): Netanel uses a proxy — billing-health-check cron has been REMOVED as not relevant. Only alert on actual API failure detected during real usage.


Response Steps (Run in Order)

Step 1 — Notify Owner

Send via WhatsApp (or preferred channel):

⚠️ Billing issue — I can't respond normally.
My API key ran out of credits (or was rate-limited).
Please top up or switch my API key in agent settings.

Step 2 — Notify Admin

[PA Name] has a billing error.
Owner: [Owner Name]
Action: top up API credits or reassign key.
Time: [current timestamp]

Step 3 — Switch to Fallback Model

  1. Check if config/billing-fallback.json exists
  2. If yes → read the fallback_model field
  3. Run: openclaw config set model "$FALLBACK_MODEL"
  4. If the command fails → tell owner: "Auto-switch failed — please update model manually in agent settings"
  5. Notify owner: "Switched to [Fallback Model] temporarily while primary key is resolved"

If billing-fallback.json doesn't exist → skip this step and tell admin to configure it.

Step 4 — Log the Incident

LOG_DIR="$HOME/.openclaw/workspace/logs"
mkdir -p "$LOG_DIR"

# Append one line to the log file
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) BILLING_ERROR api_key_exhausted" \
  >> "$LOG_DIR/billing-incidents.log"

Health Check Script

Run this during heartbeat to catch billing issues before they cause failures:

#!/bin/bash
# billing-check.sh
# Checks the LLM provider API key configured in env vars

set -e

LOG_DIR="$HOME/.openclaw/workspace/logs"
mkdir -p "$LOG_DIR"
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)

# Detect provider from env vars (check in order)
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
  PROVIDER="Anthropic"
  HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
    -H "x-api-key: ${ANTHROPIC_API_KEY}" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d "{\"model\":\"claude-haiku-20240307\",\"max_tokens\":1,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" \
    https://api.anthropic.com/v1/messages 2>/dev/null)

elif [ -n "${OPENAI_API_KEY:-}" ]; then
  PROVIDER="OpenAI"
  HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
    -H "Authorization: Bearer ${OPENAI_API_KEY}" \
    -H "content-type: application/json" \
    -d "{\"model\":\"gpt-4o-mini\",\"max_tokens\":1,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" \
    https://api.openai.com/v1/chat/completions 2>/dev/null)

elif [ -n "${GOOGLE_API_KEY:-}" ]; then
  PROVIDER="Google"
  HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
    "https://generativelanguage.googleapis.com/v1beta/models?key=${GOOGLE_API_KEY}" 2>/dev/null)

else
  echo "$TIMESTAMP SKIP no API key env var found" >> "$LOG_DIR/billing-incidents.log"
  exit 0
fi

# Act on the HTTP status code
case "$HTTP_STATUS" in
  200)
    echo "$TIMESTAMP OK $PROVIDER" >> "$LOG_DIR/billing-incidents.log"
    ;;
  402)
    echo "$TIMESTAMP BILLING_ERROR $PROVIDER HTTP_402" >> "$LOG_DIR/billing-incidents.log"
    echo "BILLING ERROR — run the 4-step response protocol above"
    exit 1
    ;;
  401)
    echo "$TIMESTAMP AUTH_ERROR $PROVIDER HTTP_401" >> "$LOG_DIR/billing-incidents.log"
    echo "AUTH ERROR — invalid API key, notify admin"
    exit 1
    ;;
  429)
    echo "$TIMESTAMP RATE_LIMITED $PROVIDER HTTP_429" >> "$LOG_DIR/billing-incidents.log"
    echo "RATE LIMITED — wait 60 seconds and retry. Not a billing issue."
    exit 2
    ;;
  *)
    echo "$TIMESTAMP UNKNOWN $PROVIDER HTTP_$HTTP_STATUS" >> "$LOG_DIR/billing-incidents.log"
    echo "UNKNOWN ERROR HTTP $HTTP_STATUS"
    exit 1
    ;;
esac

HTTP status meanings:

  • 200 → OK
  • 402 → Billing error → run 4-step protocol
  • 401 → Invalid key → notify admin
  • 429 → Rate limit (temporary) → wait and retry, do NOT trigger billing protocol

Fallback Config File

Create config/billing-fallback.json in your workspace:

{
  "primary_provider": "your-primary-provider",
  "primary_model": "your-primary-model",
  "fallback_provider": "your-fallback-provider",
  "fallback_model": "your-fallback-model",
  "admin_phone": "+1XXXXXXXXXX",
  "alert_channel": "whatsapp"
}

Replace placeholders with real values. Examples:

  • Anthropic → OpenAI: "primary_provider": "anthropic", "primary_model": "claude-haiku-20240307", "fallback_provider": "openai", "fallback_model": "gpt-4o-mini"

Recovery (After Credits Restored)

  1. Owner confirms credits are topped up.
  2. Read the primary model name from config:
    PRIMARY=$(python3 -c "
    import json
    with open('config/billing-fallback.json') as f:
        print(json.load(f)['primary_model'])
    ")
    
  3. Switch back to primary:
    openclaw config set model "$PRIMARY"
    
  4. Log the recovery:
    echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) BILLING_RESTORED" \
      >> ~/.openclaw/workspace/logs/billing-incidents.log
    
  5. Notify owner: "✅ Primary model restored. Normal service resumed."

Edge Cases

Scenario Action
429 rate limit Wait 60s, retry. Do NOT trigger billing protocol.
5xx server error Retry 2x with 10s delay. If persists → notify owner.
Both primary AND fallback billing errors Escalate to admin immediately. Agent cannot function.
No API key env var set Log as config issue. Notify admin.
Peer PA reports billing error Log it. Notify admin if you are the network coordinator.

Cost Tips

  • Cheap: Health checks with curl — no LLM cost at all
  • Expensive: Running health checks too frequently wastes money. Every 2 hours is enough.
  • Batch: Combine billing check with other heartbeat checks in one script run
  • Small model OK: This skill needs no reasoning — any model can send a notification message

Running via Cron (Recommended)

Instead of a plugin, run billing-monitor as a scheduled skill via cron:

{
  "id": "billing-health-check",
  "schedule": { "kind": "cron", "expr": "0 * * * *", "tz": "UTC" },
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "message": "Run the billing-monitor skill: check all configured API keys for billing errors. If any provider returns 402, send an alert to the admin phone and update billing-status.json. Reply HEARTBEAT_OK if all clear."
  },
  "delivery": { "mode": "silent" }
}

This runs every hour and alerts automatically — no plugin required.

安全使用建议
Before installing, ask the publisher to: (1) update the skill metadata to list all required environment variables and config paths (provider API keys, owner/admin contacts, billing-fallback.json, any .context file path); (2) explain why the skill needs to source /opt/ocana/.../.context and what data that file contains (avoid sourcing arbitrary system-wide files with secrets); (3) confirm that `openclaw` is available on the target system and document what `openclaw config set model` changes and whether it affects other agents; (4) Restrict who can run the health-check cron and ensure logs/credentials are stored with least privilege; and (5) test in a sandboxed agent (no production credentials, use test keys) to verify behavior. If the publisher cannot justify the undocumented env vars and absolute paths, treat this as higher risk and do not install in production.
能力评估
Purpose & Capability
The skill claims to monitor billing and alert/auto-switch models — that purpose legitimately requires provider API keys (OpenAI/Anthropic/Google), notification targets (owner/admin phones or channels), and a fallback config. However the registry metadata lists no required env vars, no required config paths, and no primary credential. This is inconsistent: the instructions clearly depend on ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY, OWNER_PHONE/ADMIN_PHONE (or a sourced context file) and config/billing-fallback.json.
Instruction Scope
The SKILL.md tells the agent to source /opt/ocana/openclaw/workspace/skills/billing-monitor/.context (which may contain sensitive secrets), to check several environment variables for provider keys, to run curl against provider APIs, to call `openclaw config set model` (modifying agent config), and to write logs under $HOME/.openclaw. Sourcing an absolute /opt path and modifying agent configuration are beyond what a minimal 'notification' skill should do and are not reflected in declared requirements.
Install Mechanism
Instruction-only skill with no install spec and no code files. This reduces supply-chain risk because nothing new is downloaded or written by an installer. The runtime actions still read/write local files and run commands, but there is no separate install mechanism to evaluate.
Credentials
The skill will access multiple sensitive env vars (ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY) and expects notification contact info (OWNER_PHONE, ADMIN_PHONE) and a fallback config file. Those are proportionate to the stated purpose, but the metadata does not declare them — the skill does not advertise it needs these credentials. Also the health-check script reads provider keys from the environment and will perform network calls using them, which should be explicitly declared.
Persistence & Privilege
always:false (normal) and autonomous invocation allowed (default). The skill instructs modifying the agent's model setting via `openclaw config set model` (its own agent config), which can be reasonable for an auto-fallback, but combined with the undocumented sourcing of /opt/.../.context and reading of env vars it increases the blast radius. No evidence the skill tries to persist beyond its own config (no 'always:true' or other privilege escalation), but clarify the scope of the context file and confirm this skill only writes its own logs/config.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install billing-monitor
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /billing-monitor 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.2
- Added context-loading instructions for local deployment, supporting use of environment variables like $OWNER_PHONE and $ADMIN_PHONE. - Clarified that routine billing checks and HTTP 200/OK results should be silent (no alerts sent). - Specified conditions for when NOT to alert the owner to avoid unnecessary notifications. - Noted that the billing-health-check cron is not relevant in production for Netanel due to proxy usage. - Rest of the detection, alerting, fallback handling, and recovery protocol are unchanged.
v1.0.1
reactions rule, close-the-loop, reply-to rules; skill-master analytics hook; skill-analytics added
v1.0.0
Initial public release — automated monitoring and alerting for API billing issues across LLM providers. - Detects billing errors from API responses or during scheduled health checks. - Immediately notifies both owner and admin on billing issues, providing clear next steps. - Attempts automatic switch to a fallback model if configured; alerts if auto-switch fails. - Logs all incidents to a dedicated billing log. - Includes scripts and instructions for periodic health checks and recovery steps after credits are restored. - Works with Anthropic, OpenAI, Google, and other API providers; provider-agnostic design.
元数据
Slug billing-monitor
版本 1.0.2
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 3
常见问题

Billing Monitor 是什么?

Monitor for API billing errors and alert the owner and admin immediately. Use when: an API billing error is detected, a peer PA reports a billing error, or d... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 126 次。

如何安装 Billing Monitor?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install billing-monitor」即可一键安装,无需额外配置。

Billing Monitor 是免费的吗?

是的,Billing Monitor 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Billing Monitor 支持哪些平台?

Billing Monitor 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Billing Monitor?

由 Netanel Abergel(@netanel-abergel)开发并维护,当前版本 v1.0.2。

💬 留言讨论