微算力 · API 导航与自营网关
API 接入 EN
未登录登录
💰

智能消费守门人,防超支零信任

x402-budget-manager · v1.0.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
专业技能 安全 A 级 作者 marketingkioldenburg 公开目录收录
94 下载 0 安装 205 收藏 1 浏览

简介

基于 x402 支付协议的预算管控技能,通过硬顶/软顶/预授权三层机制,为 Agent 调用付费 API 提供生产级防透支保护,确保每笔支出可控可审计。

原始描述

Track and cap x402 spend across providers — per-endpoint hard_cap/soft_cap, pre-authorized override budgets, cumulative spend tracking, monthly ceilings. Makes x402 the client production-safe by preventing overspend and aborting costly calls before they happen.

通过你的 Agent 添加

安装目录:x402-budget-manager/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/x402-budget-manager/
Codex CLI~/.codex/skills/x402-budget-manager/
DeepSeek Harness~/.agents/skills/x402-budget-manager/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

x402-budget-manager 是 x402 支付生态的预算守门组件,解决"Agent 调用付费 API 时无限透支"的安全隐患。该技能在每次调用前读取 budget.json 策略文件,执行三层价格校验:首先比对单次调用报价与硬顶(hard_cap),超限则直接拒绝;若处于软顶(soft_cap)与预授权预算(override_budget)之间,则按配置执行日志记录、升级审批或失败处理;若报价超过预授权预算,同样硬失败。技能支持两种执行模式:per_request(逐请求审计,无状态)和 cumulative_session(跨会话累计,需状态保持),官方推荐前者以确保可审计性。

显著优点

  1. 生产级安全设计:三层阶梯式管控(硬顶/软顶/预授权)将财务风险锁死在配置边界内,杜绝 Agent 自主超支
  2. 零信任审计友好:per_request 模式无需跨调用状态即可验证,配合 spend-log.json 追加日志实现完整链路追踪
  3. 灵活策略配置:支持全局、端点级、服务商级多维度预算设置,月上限、会话上限、单次上限分层管理
  4. 货币安全处理:内置 USDC 原子单位转换(/ 1e6),防止因精度误解导致配置错误
  5. 合规预授权模式:"升级"动作要求操作员预先设定天花板,Agent 绝不自主谈判,符合企业内控规范

潜在缺点与局限性

  • 状态管理负担:cumulative_session 模式需维护会话状态,分布式部署时需额外解决状态同步问题
  • 配置复杂度:多维度策略叠加时,调试成本较高,需理解硬顶/软顶/预授权三者的优先级关系
  • 实时性限制:基于报价的事前拦截无法防范服务商临时涨价或报价欺诈,需配合 x402-endpoint-validator 使用
  • 无自动预算调整:不支持动态预算伸缩,突发流量需人工预授权,可能中断关键业务流程
  • 生态依赖强:专为 x402 协议设计,无法直接适配其他支付协议

适合的目标群体

  • 运营 x402 付费 Agent 的企业/团队:需要为多个 Agent 实例配置统一支出策略
  • 财务合规敏感场景:如律所、审计、医疗等需严格预算审批的垂直行业
  • 高频 API 调用场景:研究 Agent、数据采集团队等存在循环调用风险的场景
  • 多服务商管理:同时使用 LoneStarOracle、kihustle 等多个 x402 服务商的用户

使用风险

  1. 配置错误风险:原子单位与 USDC 单位混淆会导致 100 万倍预算误差,建议配置时强制校验
  2. 日志累积性能:高频场景下 spend-log.json 持续膨胀,需定期归档或切换外部存储
  3. 服务商一致性风险:若服务端的 payment-required 头部与 body 报价不一致,技能会拒绝调用,可能导致正常服务中断
  4. 重试双付风险:盲目重试会在 x402 无幂等保护时造成重复扣款,必须严格遵循 x402-client 的幂等规则
  5. 依赖项可用性:依赖 curl 和 jq,在精简容器环境中需预装,且 jq 版本需支持复杂 JSON 查询

技能正文


name: x402-budget-manager version: 1.0.0 description: "Track and cap x402 spend across providers — per-endpoint hard_cap/soft_cap, pre-authorized override budgets, cumulative spend tracking, monthly ceilings. Makes x402 the client production-safe by preventing overspend and aborting costly calls before they happen." metadata: openclaw: emoji: "💰" requires: bins: ["curl", "jq"] homepage: "https://www.x402.org"

x402 Budget Manager

Prevents an agent from overspending on x402 pay-per-request APIs. Reads a budget.json policy before every call cycle, checks the call against per-endpoint caps, and either allows, escalates, or fails hard.

Companion to x402-client. Where the client handles how to pay, this skill handles whether you may pay.

The Problem

x402 has no built-in spend limit. Each call costs USDC on Base, and a loop or a misread quote can drain a wallet. The client will happily pay every 402 it receives. The budget manager is the gate in front of it.

Two enforcement modes (schema toggle)

The schema supports two modes, selectable per endpoint or globally:

  • per_request (default) — check cumulative spend before every call. Auditable without carrying state between calls. A single expensive inference can trip the fuse mid-session if you are near the limit. Simple, deterministic.
  • cumulative_session — track spend across a session (or across calls to one provider). Cleaner for long workflows, but requires state carryover between calls.

per_request is the recommended default because it is auditable without state.

budget.json Schema (CC0)

{
  "version": 1,
  "default_action": "fail",
  "global": {
    "monthly_ceiling_usdc": 50.00,
    "per_request_mode": "per_request"
  },
  "endpoints": {
    "https://agent.kihustle.tech/services/impressum-check/jobs": {
      "hard_cap_usdc": 0.10,
      "soft_cap_usdc": 0.05,
      "override_budget_usdc": 0.25,
      "action_on_soft_cap": "log"
    },
    "https://research.johnnybucks.tech/.well-known/x402": {
      "hard_cap_usdc": 2.00,
      "override_budget_usdc": 4.00,
      "action_on_soft_cap": "escalate"
    }
  },
  "providers": {
    "lonestaroracle": {
      "monthly_ceiling_usdc": 20.00,
      "session_ceiling_usdc": 5.00
    }
  }
}

Field semantics

  • hard_cap_usdc — if the quoted call price exceeds this, fail hard. Reject the call. No negotiation.
  • soft_cap_usdc — if the quoted price exceeds this but is within override_budget_usdc, apply action_on_soft_cap.
  • override_budget_usdc — a pre-authorized ceiling above the soft cap. The agent has a known ceiling before it starts; it never negotiates mid-call. If override_budget_usdc is absent, the hard cap is the only ceiling.
  • action_on_soft_cap — "log" (proceed and log the overage), "escalate" (require operator pre-approval, see below), or "fail" (treat as hard cap).
  • monthly_ceiling_usdc (global or per-provider) — cumulative monthly ceiling; alert before hitting it.
  • per_request_mode — "per_request" or "cumulative_session".

The three-cap ladder

price <= hard_cap        -> allow
                         (and price <= soft_cap -> allow silently)

soft_cap < price <= override_budget -> action_on_soft_cap (log / escalate / fail)

override_budget < price  -> fail hard

Escalation (pre-authorized, never mid-call)

The escalate path requires the operator to pre-authorize a ceiling in override_budget_usdc — it is not a mid-call approval. The agent starts each cycle knowing its ceiling.

  • If a call would exceed hard_cap_usdc, the agent fails hard before paying. It must never auto-escalate due to the risk of unbounded liability.
  • Time-sensitive flows that need headroom must have override_budget_usdc pre-set by the operator. There is no runtime negotiation.
  • This mirrors the dispute-bond pattern: approval is bounded and known in advance, not granted on demand.

Check-before-pay workflow

# 1. Read the price from the discovery manifest before triggering the 402
curl -s https://service.example/.well-known/x402 | jq '.resources[] | select(.path|test("impressum")) | {path, priceUsdc}'

# 2. Compare against budget.json (pseudo-pseudocode)
#    price = <parsed priceUsdc, converted from atomic units / 1e6>
#    if price > override_budget_usdc or price > hard_cap_usdc: FAIL
#    elif price > soft_cap_usdc: apply action_on_soft_cap
#    else: proceed

# 3. On proceed, pay via the x402-client flow, then record the spend:
#    append {endpoint, priceUsdc, ts, tx_hash} to spend-log.json

Tracking cumulative spend

Maintain a spend-log.json (append-only):

{
  "calls": [
    {
      "endpoint": "https://agent.kihustle.tech/services/impressum-check/jobs",
      "priceUsdc": 0.05,
      "ts": "2026-08-06T09:00:00Z",
      "status": "settled",
      "payment_signature": "0x..."
    }
  ],
  "monthly_total_usdc": 12.34,
  "session_total_usdc": 0.85
}

Before each call:

  1. Read monthly_total_usdc and session_total_usdc.
  2. Add the quoted price. Does it exceed monthly_ceiling_usdc (global or provider)? If yes → fail (or alert-and-stall).
  3. Does the session total exceed session_ceiling_usdc if set? If yes → apply policy.
  4. Only then check the per-call three-cap ladder above.

Pitfalls

  • Atomic units: amounts in x402 responses are micro-units (USDC has 6 decimals), e.g. "50000" = $0.05. Convert (/ 1e6) before comparing to USDC caps.
  • Per-channel drift: if a service serves the price in both the body (v1) and a payment-required header (v2), verify asset/payTo/amount agree. If they disagree on price, reject — that is a real failure, not version noise.
  • Never retry blindly — a retry can double-pay. Only retry within the idempotency rules of x402-client.
  • Escalate ≠ authorize: the agent may request a ceiling bump for a future run, but it must never approve its own spend above the pre-authorized budget.
  • Log every overage even when you proceed on soft cap — the audit trail is what makes per_request mode trustworthy.

References

  • x402-client — how to actually pay once the budget is approved
  • x402-endpoint-validator — probe a service's price before committing
  • Discussion origin: cross-operator spec developed with floydlso (LoneStarOracle, 50+ live x402 feeds) in the Moltbook x402-billing/openclaw-explorers threads, August 2026.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

payautomationapifinance-accountingbackendoperations

同类 Skill