spendguard-strict-budget-runner
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpendGuard Strict Budget Runner
SpendGuard 严格预算执行器
Overview
概述
Use this skill to operationalize strict-budget execution.
使用该Skill实现严格预算的落地执行。
Quick Start
快速开始
- Load .
references/strict-budget-quickstart.md - Start sidecar in strict remote-pricing mode.
- Create agent and set hard budget with CLI or .
scripts/bootstrap_strict_budget.py - Route model calls through SpendGuard and include required headers.
- Confirm budget decrement and handle failures using .
references/error-playbook.md
- 加载文件。
references/strict-budget-quickstart.md - 以严格远程定价模式启动sidecar。
- 通过CLI或创建Agent并设置硬预算。
scripts/bootstrap_strict_budget.py - 将模型调用请求路由至SpendGuard,并包含必要的请求头。
- 确认预算扣减情况,并通过处理失败场景。
references/error-playbook.md
Workflow
工作流程
1) Start SpendGuard in strict mode
1) 以严格模式启动SpendGuard
Use sidecar mode with remote signed pricing verification enabled. Do not bypass signature checks for normal usage.
See full env setup in .
references/strict-budget-quickstart.md使用sidecar模式并启用远程签名定价验证。正常使用时不要绕过签名校验。
详见中的完整环境配置。
references/strict-budget-quickstart.md2) Create budgeted agent identity
2) 创建带预算的Agent身份
Prefer CLI:
bash
spendguard agent create --name "my-agent"
spendguard budget set --agent <agent_id> --limit 5000 --topup 5000
spendguard budget get --agent <agent_id>Use script when deterministic JSON output is needed:
bash
python scripts/bootstrap_strict_budget.py --name my-agent --limit 5000 --topup 5000优先使用CLI:
bash
spendguard agent create --name "my-agent"
spendguard budget set --agent <agent_id> --limit 5000 --topup 5000
spendguard budget get --agent <agent_id>当需要确定性JSON输出时,使用脚本:
bash
python scripts/bootstrap_strict_budget.py --name my-agent --limit 5000 --topup 50003) Route model calls through SpendGuard
3) 将模型调用路由至SpendGuard
Send requests to sidecar routes, not directly to provider APIs.
.../v1/...Required:
- Header
x-cynsta-agent-id: <agent_id> - Optional for explicit run tracking
x-cynsta-run-id: <run_id>
Load for OpenAI SDK and direct HTTP patterns.
references/routing-patterns.md将请求发送至sidecar的路由,而非直接调用服务商API。
.../v1/...必填项:
- 请求头
x-cynsta-agent-id: <agent_id> - 可选请求头,用于显式跟踪运行实例
x-cynsta-run-id: <run_id>
如需了解OpenAI SDK和直接HTTP调用的模式,请加载。
references/routing-patterns.md4) Enforce strict budget behavior
4) 执行严格预算管控
Expect:
- when budget is insufficient for reserve
402 - when same agent budget is locked by another in-flight run
409 - for malformed payload or missing required headers
400
Apply fixes from .
references/error-playbook.md预期出现以下情况:
- 当预算不足以预留时,返回状态码
402 - 当同一Agent的预算被其他运行中的实例锁定时,返回状态码
409 - 当请求格式错误或缺少必填请求头时,返回状态码
400
请根据中的方案进行修复。
references/error-playbook.md5) Validate before finishing
5) 完成前的验证
Run these checks after setup:
- Health endpoint returns .
{"status":"ok"} - returns expected
budget get.remaining_cents - One real or mocked model call succeeds through sidecar.
- Remaining budget decreases after settled usage.
设置完成后执行以下检查:
- 健康检查端点返回
{"status":"ok"} - 命令返回预期的
budget get值remaining_cents - 至少一次真实或模拟的模型调用通过sidecar执行成功
- 结算使用量后,剩余预算相应减少
Guardrails
防护规则
- Use one agent per isolated budget domain; do not share agent IDs across unrelated workloads.
- Keep budgets in cents and treat as the strict cap.
hard_limit_cents - Keep in normal operation.
CAP_PRICING_VERIFY_SIGNATURE=true - In hosted mode, pass API key via or
--api-key.CAP_API_KEY
- 每个独立预算域使用一个Agent;不要在不相关的工作负载间共享Agent ID
- 预算以美分为单位,并将视为严格上限
hard_limit_cents - 正常运行时保持
CAP_PRICING_VERIFY_SIGNATURE=true - 在托管模式下,通过参数或
--api-key环境变量传递API密钥CAP_API_KEY