paybondpaybond
Sign in

Recipe · Cloud spend

Spend controls for Cloudflare Agents tools

spend verify before getTools AI SDK execute, auto-evidence after success, and policy budgets for Cloudflare Agents — TypeScript.

  1. 1Wire
  2. 2Authorize
  3. 3Smoke

You'll build

Cloudflare Agents tools with Harbor budgets at invoke time

Cloudflare Agents run tool handlers on Workers and Durable Objects. Paybond guards tool execution at the same boundary — spend verify before side effects, auto-evidence after success. Paybond ships createPaybondCloudflareAgentsConfig on @paybond/kit/cloudflare-agents and @paybond/cloudflare-agents.

TypeScript only. Python Kit does not ship a Cloudflare Agents adapter. Use agent-agnostic spend controls or MCP agent spend controls for Python hosts.

Adapter reference: /docs/kit/cloudflare-agents.

  • spend verify on Workers

    createPaybondCloudflareAgentsConfig wraps AI SDK tool execute on side-effecting tools.

  • Auto-evidence

    Wrapped execute finalizes spend and submits signed evidence after success.

  • Policy budgets

    Versioned YAML caps per-call and intent spend for Durable Object agents.

  • TypeScript native

    Use @paybond/cloudflare-agents; Python hosts use agent-agnostic or MCP.

Why Paybond (not just Cloudflare Agents checks)?

Cloudflare Agents tool handlers do not enforce a spend limit, a per-operation permission check (capability token), or a signed completion receipt tied to a spend agreement (intent).

Cloudflare Agents alone versus Paybond Harbor spend controls
  • Model / input guardrails

    Cloudflare Agents alone
    Yes — SDK or host checks and approvals
    With Paybond
    Yes — plus Harbor authorize at the tool boundary
  • Spend boundary

    Cloudflare Agents alone
    No per-tool Harbor budget or capability token
    With Paybond
    Per-call and intent budgets enforced before invoke
  • Signed evidence

    Cloudflare Agents alone
    SDK traces / logs only
    With Paybond
    Signed completion digests bound to the intent
  • Intent binding

    Cloudflare Agents alone
    No Harbor intent or settlement receipt
    With Paybond
    Capability token + intentId from authenticated bind
  • Paid tool deny / HITL

    Cloudflare Agents alone
    Host or SDK approvals only
    With Paybond
    spend verify, deny, or HITL hold before side effects

How it works

Paybond wraps getTools AI SDK handlers: Harbor authorize before execute, then auto-evidence after success.

Adapter flow

  1. getTools execute

    Cloudflare Agent invokes a side-effecting tool

  2. Paybond wrap

    Harbor authorize before your handler runs

    • Verify spend and operation
    • Deny or HITL hold
    • Issue / check capability
  3. Tool runs

    Your execute handler performs the paid work

  4. Evidence

    Wrapped execute finalizes spend + auto-evidence

Paybond wraps getTools AI SDK handlers: Harbor authorize before execute, then auto-evidence after success.

3-minute quickstart

Smoke the cloudflare-agents adapter sandbox contract — no Workers runtime required for this check:

Terminal
Terminal commandSwipe to inspect long lines
paybond login
paybond agent demo cloudflare-agents smoke \
  --operation paid-tool \
  --requested-spend-cents 100 \
  --evidence-preset cost_and_completion \
  --format table

Install the optional peers when running the native adapter in your app:

Terminal
Terminal commandSwipe to inspect long lines
npm install @paybond/cloudflare-agents agents ai

When the smoke succeeds you should see:

  • ✓ Spend approved
  • ✓ Tool completed
  • ✓ Evidence verified (cost_and_completion)

What success looks like

Example status after a Paybond-guarded Cloudflare Agents tool call: approved spend, requested amount, and verified cost_and_completion evidence.

What success looks like

Authorized tool call · illustrative

Sandbox path
Operation
paid-tool
Status
Approved
Requested
$1.00
Evidence
Verified
Preset
cost_and_completion

Scaffold

Terminal
Terminal commandSwipe to inspect long lines
paybond init agent-middleware --framework cloudflare-agents --out paybond-cloudflare-agents.ts
paybond policy init --preset travel --out paybond.policy.yaml

Wire middleware

Recommended wiring

paybond.instrument with framework cloudflare-agents wraps AI SDK tool execute and returns toolApproval hooks.

paybond-session.ts

TS
TypeScript code sampleSwipe to inspect long lines
import { tool } from "ai";
import { z } from "zod";
import { Paybond } from "@paybond/kit";

const paybond = await Paybond.open({ apiKey: process.env.PAYBOND_API_KEY! });

const { tools, hooks } = await paybond.instrument({
  policy: "travel",
  framework: "cloudflare-agents",
  tools: {
    "travel.book_hotel": tool({
      description: "Book a hotel room",
      inputSchema: z.object({
        city: z.string(),
        estimatedPriceCents: z.number().int().nonnegative(),
      }),
      execute: async (args) => bookHotel(args),
    }),
    searchWeb: tool({
      description: "Search the web",
      inputSchema: z.object({ query: z.string() }),
      execute: async (args) => searchWeb(args),
    }),
  },
});

// Return `tools` from getTools(); pass `hooks.toolApproval` to streamText/generateText.

Already bound a run? createPaybondCloudflareAgentsConfig(run, tools) from @paybond/cloudflare-agents wraps execute without reloading policy.

Production: await instrumented.bind({ intentId, capabilityToken }) per session — see Agent middleware.

Production checklist

Production checklist for Paybond-guarded Cloudflare Agents tools.

Production checklist

Works with

Works with

  • Cloudflare
  • Vercel
  • OpenAI
  • MCP

Ready to test?

Developer reference: /docs/kit/cloudflare-agents.