paybondpaybond
Sign in

Recipe · Framework

Spend controls for Vercel AI SDK tools

spend verify via toolApproval before execute, auto-evidence after success, and policy budgets for Vercel AI SDK — TypeScript.

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

You'll build

Vercel AI SDK tool calls wrapped with Harbor spend controls

The Vercel AI SDK runs tools through generateText / streamText with optional toolApproval. Paybond supplies that approval hook and wraps execute on side-effecting tools — spend verify before side effects, auto-evidence after success. Keep your provider client for inference; Paybond guards paid tool calls only.

TypeScript only. paybond-kit Python rejects framework: "vercel-ai" (native adapter is @paybond/kit/vercel-ai). Use agent-agnostic spend controls for Python hosts.

Adapter reference: /docs/kit/vercel-ai.

  • toolApproval with wrapped execute

    Harbor authorize runs before side-effecting tools; generateText/streamText stay on your provider.

  • Auto-evidence

    Wrapped execute finalizes spend and submits signed evidence after tool success.

  • Policy budgets

    Versioned YAML caps per-call and intent spend — default-deny for paid tools.

  • TypeScript only

    Native @paybond/kit/vercel-ai adapter; Python hosts use agent-agnostic or another dual-language adapter.

Why Paybond (not just AI SDK guardrails)?

Vercel AI SDK tool approvals do not enforce a spend limit, a per-operation permission check (capability token), or a signed completion receipt tied to a spend agreement (intent).

Vercel AI SDK alone versus Paybond Harbor spend controls
  • Model / input guardrails

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

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

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

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

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

How it works

Paybond supplies toolApproval and wraps execute: Harbor authorize before the tool runs, then auto-evidence after success.

Adapter flow

  1. generateText / streamText

    Vercel AI SDK invokes a side-effecting tool

  2. Paybond toolApproval

    Harbor authorize before execute

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

    Your tool handler performs the paid work

  4. Evidence

    Wrapped execute finalizes spend + auto-evidence

Paybond supplies toolApproval and wraps execute: Harbor authorize before the tool runs, then auto-evidence after success.

3-minute quickstart

Smoke the vercel-ai adapter sandbox contract — no Vercel credentials required for this check:

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

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 Vercel AI SDK 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 vercel-ai --out paybond-vercel-ai.ts
paybond policy init --preset travel --out paybond.policy.yaml

Validate before deploy:

Terminal
Terminal commandSwipe to inspect long lines
paybond policy validate-tools --file paybond.policy.yaml --local-only

Wire middleware

Recommended wiring

paybond.agent with framework vercel-ai returns agentTools plus toolApproval for generateText/streamText.

paybond-session.ts

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

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

const { agentTools: tools, toolApproval } = await paybond.agent({
  policy: "travel",
  framework: "vercel-ai",
  tools: {
    bookHotel: 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),
    }),
  },
});

const result = await generateText({
  model: openai("gpt-4.1"),
  tools,
  toolApproval,
  prompt: "Find hotels in Lisbon and book one under budget.",
});

Already bound a run? paybond.wrapTools(run, tools, { framework: "vercel-ai" }) returns { tools, toolApproval } without reloading policy.

For a full App Router example with request-scoped bind, see Next.js agent checkout.

Production: omit sandbox defaults, use deferred bind, then instrumented.bind({ intentId, capabilityToken }) per session.

Production checklist

Production checklist for Paybond-guarded Vercel AI SDK tools.

Production checklist

Works with

Works with

  • Vercel
  • OpenAI
  • Anthropic
  • MCP

Ready to test?

Developer reference: /docs/kit/vercel-ai.