Spend guardrails
Add spend guardrails to Coinbase AgentKit
Screwtape.ai decides whether an AI agent is allowed to spend money, and keeps the proof. Call POST /v1/judge before any payment. Pay only on pass. Screwtape advises and records; your Coinbase AgentKit code must honor the verdict.
Install-free snippet
Evidence is an array of strings. Free: 3 calls/day with no key, 10/day with a free key.
export async function spendAllowed(task: string, plannedAction: string, evidence: string[] = []) {
const headers: Record<string, string> = { "content-type": "application/json" };
if (process.env.SCREWTAPE_KEY) headers.authorization = `Bearer ${process.env.SCREWTAPE_KEY}`;
const r = await fetch("https://screwtape.ai/v1/judge", {
method: "POST",
headers,
body: JSON.stringify({ task, agent_output: plannedAction, evidence }),
});
if (!r.ok) return { verdict: "fail", reasons: [`check unavailable: HTTP ${r.status}`] }; // fail closed
return r.json() as Promise<{ verdict: "pass" | "fail" | "retry"; reasons: string[]; receipt?: unknown }>;
}
const v = await spendAllowed(
"Pay invoice INV-42 from Acme",
"Pay $120.00 to Acme",
["PO-42: Acme, $120.00"],
);
if (v.verdict === "pass") await pay();
else if (v.verdict === "retry") await fixAndRetry(v.reasons);
else await askAHuman(v.reasons);
// Optional: POST /v1/duplicate before judge for invoice replay
// Optional: POST /v1/budget to reserve against a shared run cap
// Optional: POST /v1/receipt to sign the reported action
Why check before a Coinbase AgentKit payment?
Agents can pay the wrong amount, the wrong party, or the same invoice twice. Screwtape returns pass, fail, or retry with reasons and a signed receipt so your code can stop before the payment runs.
Do I need to install a package?
No. Call HTTPS endpoints with your HTTP client. Optional free API key via POST /v1/signup. Without a key you still get a small shared free allowance per day.
What if the check is unavailable?
Fail closed: treat a non-200 response as fail and do not pay. The snippets below do that.
How do I catch a duplicate invoice?
POST /v1/duplicate with the invoice fields before or instead of judge. It returns unique, duplicate, possible_duplicate, or replay.
How do I share a budget across agents?
POST /v1/budget with run_id, event_id, amount, cap, and merchant. Honor block. Children inherit the root cap.
How do I keep proof of what the agent did?
POST /v1/receipt with agent_id, event_id, action, and status. Verify for free at GET /v1/receipt/verify or on /verify/. To close a whole run, send children: a list of prior receipt ids; the summary signs a root digest over them.
All spend-guardrail guides · Framework connection examples · Machine-readable API notes · Verify a receipt · Receipt format
