Create an AP2 mandate
- Level
- Intermediate
- Time
- ~15 min
- Prerequisites
- Delegated machine DID, controller human DID
- Stack
- TypeScript
Open an AP2 session
A session binds the agent DID to a provider DID for a specific service with a max-amount ceiling.
import { TenzroClient } from "tenzro-sdk";
const client = new TenzroClient({ endpoint: "https://rpc.tenzro.xyz" });
const session = await client.ap2().createSession(
"did:tenzro:machine:agent-1",
"did:tenzro:machine:provider-1",
"https://api.tenzro.xyz/inference",
"2.50",
"TNZO",
);Validate the checkout/payment mandate pair
For higher-assurance flows, have the principal sign a CheckoutMandate VDC and the agent sign a PaymentMandate VDC, then check the pair against every ceiling — the CheckoutMandate cap, the DelegationScope, the runtime SpendingPolicy, the on-chain escrow, and the Stripe SPT usage limits.
const result = await client.ap2().validateMandatePair(checkoutVdc, paymentVdc, true);
if (!result.valid) throw new Error(result.error);Authorize a payment within the session
Each authorization is scoped under the session ceiling. The node checks the agent's DelegationScope and runtime SpendingPolicy at sign time.
const auth = await client.ap2().authorizePayment(session.session_id, "0.50");
console.log("authorization:", auth.authorization_id);Execute and settle
Execution settles the previously-authorized amount and emits a receipt.
const receipt = await client.ap2().executePayment(session.session_id, auth.authorization_id);
console.log("settled:", receipt);List persisted mandates
Signed checkout/payment mandate pairs persist under the controller DID. Retrieve them to audit what an agent was authorized to buy — each record carries the mandate ids, the controller/agent/merchant DIDs, the max and total amounts, asset, chain, expiry, the delegation-enforced flag, and the stored checkout/payment VDCs.
const { mandates } = await client.ap2().listMandates("did:tenzro:human:controller-1");
for (const m of mandates) {
console.log(m.mandate_id, m.max_amount, m.total_amount, m.asset);
}