paybondpaybond
Sign in

Recipe · Framework

Spend controls for OpenAI Agents SDK tools

spend verify before FunctionTool.invoke, auto-evidence after success, and policy budgets for OpenAI Agents SDK — TypeScript and Python.

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

You'll build

OpenAI Agents SDK tools that authorize spend before FunctionTool.invoke

Before you start

  • @paybond/openai-agents
  • demo smoke
  • ~3 min

The OpenAI Agents SDK runs tools through FunctionTool.invoke. Paybond hooks that boundary — Harbor verifies spend before side effects and auto-submits evidence after success — not as model middleware.

Install @paybond/openai-agents (npm) or paybond-kit[openai-agents] (pip). Adapter reference: /docs/kit/openai-agents.

  • spend verify before invoke

    Input guardrails authorize operation and amount before FunctionTool.invoke runs.

  • Auto-evidence

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

  • Policy budgets

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

  • TypeScript and Python

    Same openai-agents adapter on npm (@paybond/openai-agents) and pip (paybond-kit[openai-agents]).

Why Paybond (not just SDK guardrails)?

OpenAI Agents SDK guardrails check model input/output and can pause for approvals. They do not enforce a spend limit, a per-operation permission check (capability token), or a signed completion receipt tied to a spend agreement (intent).

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

    SDK guardrails alone
    Yes — SDK input/output checks and approvals
    With Paybond
    Yes — plus Harbor authorize at the tool boundary
  • Spend boundary

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

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

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

    SDK guardrails alone
    OpenAI approval interruptions only
    With Paybond
    spend verify, deny, or HITL hold before side effects

How it works

Paybond hooks FunctionTool.invoke: Harbor input guardrail before the tool runs, then wrapped invoke submits evidence after success.

Adapter flow

  1. FunctionTool.invoke

    OpenAI Agents SDK calls a side-effecting tool

  2. Paybond input guardrail

    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 invoke finalizes spend + auto-evidence

Paybond hooks FunctionTool.invoke: Harbor input guardrail before the tool runs, then wrapped invoke submits evidence after success.

3-minute quickstart

Smoke the openai-agents adapter sandbox contract — no OpenAI credentials required for this check:

Terminal
Terminal commandSwipe to inspect long lines
paybond login
paybond agent demo openai-agents 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 OpenAI 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
# TypeScript
paybond init agent-middleware --framework openai --out paybond-openai-agents.ts
# Python
paybond init agent-middleware --framework openai --out paybond_agent_middleware_openai.py
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 openai-agents returns agentTools plus runConfig so Harbor guardrails run before FunctionTool.invoke.

paybond-session.ts

TS
Code exampleSwipe to inspect long lines
import { tool, Agent, Runner } from "@openai/agents";
import { z } from "zod";
import { Paybond } from "@paybond/kit";

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

const bookHotelTool = tool({
  name: "travel.book_hotel",
  description: "Book a hotel room",
  parameters: z.object({
    city: z.string(),
    estimatedPriceCents: z.number().int().nonnegative(),
  }),
  execute: async (args) => bookHotel(args),
});

const { agentTools: tools, runConfig } = await paybond.agent({
  policy: "travel",
  framework: "openai-agents",
  tools: [bookHotelTool, searchWebTool],
});

const agent = new Agent({ name: "Travel", tools });
await Runner.run(agent, "Book a hotel in Lisbon under $200.", { ...runConfig });

Install Python extra: pip install "paybond-kit[openai-agents]". The scaffold (paybond_agent_middleware_openai.py) shows FunctionTool and create_guarded_agent for policy-driven bootstrap.

Manual hook wiring

When you already bound a PaybondAgentRun:

paybond-session.ts

TS
Code exampleSwipe to inspect long lines
import { createPaybondOpenAIAgentsConfig } from "@paybond/kit/openai-agents";

const config = createPaybondOpenAIAgentsConfig(run, sdkTools);
const guardedTools = config.tools;

Production: omit sandbox defaults on paybond.agent() / paybond.instrument(), use deferred bind, then instrumented.bind({ intentId, capabilityToken }) per session. Tenant and intent IDs come from the Paybond session binding — never from unauthenticated tool args.

Production checklist

Production checklist for Paybond-guarded OpenAI Agents SDK tools.

Production checklist

Works with

Works with

  • OpenAI
  • Anthropic
  • Vercel
  • MCP

Ready to test?

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