AP2: Agent Payments Protocol

Google's Agent Payments Protocol for cryptographic mandate-based authorization in AI commerce.

Overview

AP2 (Agent Payments Protocol) is Google’s standard for authorizing agent-initiated payments. It uses cryptographic mandates to prove that a user has explicitly authorized a specific spending action.

AP2 sits in the Authorization Layer of our three-layer protocol architecture, answering the question: β€œDid the user approve this spend?”

Key Concepts

Mandates

Mandates are cryptographically signed authorization tokens. There are three types:

TypePurposeUse Case
Intent MandatePre-authorization for product search”Find me a laptop under $1500”
Cart MandateAuthorization for specific items”I approve these 3 items totaling $1,200”
Payment MandateFinal authorization for payment”Process payment of $1,200 to merchant X”

Mandate Flow

  1. User creates intent β€” Sets budget, category, preferences
  2. Agent searches β€” Finds matching products within mandate constraints
  3. Cart approval β€” User reviews and approves selected items
  4. Payment execution β€” Cryptographically signed payment authorization

Implementation

Create an Intent Mandate

const mandate = await soft.ap2.intents.create({
  user_id: 'user_123',
  max_amount: 1500,
  currency: 'USD',
  category: 'electronics',
  constraints: {
    merchants: ['merchant_a', 'merchant_b'],
    expires_in: 3600,  // 1 hour
  },
});

Verify Mandate Signature

All mandates include ECDSA signatures that must be verified:

const isValid = await soft.ap2.mandates.verify({
  mandate_id: mandate.id,
  signature: mandate.signature,
  public_key: mandate.issuer_public_key,
});

if (!isValid) {
  throw new Error('Invalid mandate signature');
}

Create a Cart Mandate

const cart = await soft.ap2.carts.create({
  intent_mandate_id: mandate.id,
  items: [
    { product_id: 'prod_456', quantity: 1, price: 1199.99 },
  ],
  total: 1199.99,
});

Process Payment

const payment = await soft.ap2.payments.create({
  cart_mandate_id: cart.id,
  payment_method: 'google_pay',
  idempotency_key: 'unique_key_123',
});

Security

AP2 implements multiple security layers:

  • ECDSA Signature Verification β€” Every mandate is cryptographically signed
  • Nonce Validation β€” Prevents replay attacks (5-minute TTL via KV)
  • Amount Constraints β€” Mandates enforce maximum spend limits
  • Merchant Restrictions β€” Mandates can limit which merchants receive payment
  • Expiration β€” All mandates have configurable TTLs

API Endpoints

MethodPathDescription
POST/ap2/intentsCreate intent mandate
GET/ap2/intents/:idGet intent mandate
PUT/ap2/intents/:idUpdate intent mandate
POST/ap2/cartsCreate cart mandate
POST/ap2/paymentsProcess payment mandate
GET/ap2/mandatesList all mandates
GET/ap2/mandates/:idGet mandate details
DELETE/ap2/mandates/:idRevoke mandate

Google Pay Integration

AP2 integrates with Google Pay for seamless checkout:

const paymentData = await soft.ap2.googlePay.createPaymentData({
  mandate_id: cart.id,
  merchant_id: 'BCR2DN5TTDH57OS2',
  merchant_name: 'soft.house',
});

Google Pay is currently in TEST mode. Contact us for production activation.