Tenzro
Tutorial — Payments

Create an AP2 mandate

AP2 sessions and mandate pairs are the structured way to tell an agent what it can buy and up to how much. Tenzro validates each mandate against the AP2 intent cap, the on-chain DelegationScope, and the runtime SpendingPolicy before any settlement clears.
Level
Intermediate
Time
~15 min
Prerequisites
Delegated machine DID, controller human DID
Stack
TypeScript
01

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.network" });

const session = await client.ap2().createSession(
  "did:tenzro:machine:agent-1",
  "did:tenzro:machine:provider-1",
  "https://api.tenzro.network/inference",
  "2.50",
  "TNZO",
);
02

Validate the intent/cart mandate pair

For higher-assurance flows, sign Intent and Cart VDCs and check the pair against all three ceilings — the AP2 cap, the DelegationScope, and the runtime SpendingPolicy.

const result = await client.ap2().validateMandatePair(intentVdc, cartVdc, true);
if (!result.valid) throw new Error(result.error);
03

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);
04

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);
Related
← All tutorials