integration
PayStage for the AI SDK
The AI SDK makes it easy to hand a model a wallet and a set of tools. That combination has an obvious failure: a model that can pay can pay the wrong party, in the wrong asset, too often.
Both tools answer that question inside the same loop that would sign the payment, and they are read-only by construction — nothing here signs, holds a key, or moves money. The tool that decides must not be the tool that spends.
Install
npm install @paystage/ai-sdk ai zodUse
import { generateText, gateway } from "ai";
import { paystageTools } from "@paystage/ai-sdk";
const policy = {
version: 1,
max_amount: { value: "0.05", asset: "USDC", decimals: 6 },
allowed_networks: ["eip155:8453"],
unknown_payee: "deny",
};
const { text } = await generateText({
model: gateway("openai/gpt-5-mini"),
tools: { ...paystageTools({ policy }), ...yourPaymentTools },
prompt: "Buy the weather data, but not above 2 cents.",
});The tools
| tool | returns |
|---|---|
paystage_evaluate_payment | decision (pay / review / do_not_pay), reasons[], summary |
paystage_should_pay | allowed, decision, reasons[] — for when reasoning is noise |
What a refusal looks like
A refusal is data, not an exception: do_not_pay with the rule that fired, so the model can explain itself and try a different route. Evaluation is a local computation — not a network call, not a paid request — so asking before every payment costs nothing.