# AP2 protocol

> How the Agent Gateway handles Agent Payments Protocol traffic, including verifiable credential transformation.
AP2 (Agent Payments Protocol) is Google’s protocol for AI-driven payments, built as an extension to [A2A](/products/affinidi-trust-fabric/agent-gateway/concepts/protocols/a2a.md). The specification and canonical reference are maintained by Google alongside the A2A protocol. The Agent Gateway implements AP2 with a credential transformation layer that converts AP2 Verifiable Digital Credentials (VDCs) into W3C Verifiable Credentials and Presentations.

Specification: [https://ap2-protocol.org/](https://ap2-protocol.org/)

## What AP2 enables

AP2 enables AI agents to execute payment flows using cryptographically signed mandates. Three mandate types carry the payment workflow:

| Mandate type | Issued by | Purpose |
| IntentMandate | Shopping agent. | Describes purchase intent, preferences, and constraints. |
| CartMandate | Merchant agent. | Contains cart items, prices, and merchant signature. |
| PaymentMandate | Credentials provider. | Authorises payment method and amount. |

Each mandate is cryptographically signed by its issuer. The gateway validates these signatures and transforms the VDCs into standardised W3C credentials that any system in the trust fabric can verify, regardless of whether it understands AP2 natively.

## Credential transformation pipeline

When AP2 messages pass through the gateway, the transformation pipeline runs automatically:

- VDC detection: The gateway identifies AP2 mandate VDCs in the request body. Per the
AP2 specification, mandates are located at params.message.parts[].data, keyed under
"ap2.mandates.IntentMandate", "ap2.mandates.CartMandate", or
"ap2.mandates.PaymentMandate".

- Signature validation: The cryptographic proof is verified against the issuer’s DID document.

- Data extraction: Credential subject data is extracted from validated VDCs.

- W3C VC creation: Extracted data is re-encoded as a W3C Verifiable Credential, signed by the gateway.

- VP generation: The VC is wrapped in a Verifiable Presentation signed by the gateway.

- Metadata injection: The VP is added to the message metadata for downstream consumption.

## Example transformation

The following shows how an IntentMandate VDC from a shopping agent is transformed into a W3C VP injected into message metadata.

IntentMandate VDC input:

```json
{
  "params": {
    "message": {
      "parts": [
        {
          "data": {
            "ap2.mandates.IntentMandate": {
              "@context": "https://ap2-protocol.org/mandates/v1",
              "type": "IntentMandate",
              "id": "intent-12345",
              "issuer": "did:web:shopping-agent.example.com",
              "credentialSubject": {
                "intent": "Purchase laptop",
                "maxPrice": 1500,
                "preferences": ["fast shipping", "warranty"]
              },
              "proof": {
                "type": "Ed25519Signature2020",
                "verificationMethod": "did:web:shopping-agent.example.com#key-1",
                "proofValue": "z3FXQ..."
              }
            }
          }
        }
      ]
    }
  }
}
```

W3C VP output in message metadata:

```json
{
  "@context": ["https://www.w3.org/2018/credentials/v1"],
  "type": "VerifiablePresentation",
  "verifiableCredential": [{
    "type": ["VerifiableCredential", "PurchaseIntentCredential"],
    "issuer": "did:web:gateway.example.com",
    "credentialSubject": {
      "id": "did:web:shopping-agent.example.com",
      "intent": "Purchase laptop",
      "maxPrice": 1500,
      "originalMandate": "intent-12345",
      "validatedAt": "2026-01-15T10:00:05Z"
    },
    "proof": { "..." }
  }],
  "proof": { "..." }
}
```

## Relationship to A2A

Since AP2 extends A2A, all standard surface features apply to AP2 surfaces: identity extraction, custom metadata injection, trust registry verification, extension rules, rate limiting, and x402 payment requirements.

The dashboard identifies AP2 surfaces with a distinct badge and provides mandate statistics, including counts and processing metrics for each mandate type, in the surface detail view.

## Related

- [A2A protocol](/products/affinidi-trust-fabric/agent-gateway/concepts/protocols/a2a.md): The base protocol that AP2 extends.

- [Surfaces](/products/affinidi-trust-fabric/agent-gateway/concepts/surfaces.md): General surface model.

- [Agent identity and DIDs](/products/affinidi-trust-fabric/agent-gateway/concepts/identity.md): How identity is used in the transformation pipeline.
