> For the complete documentation index, see [llms.txt](https://docs.metamynd.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metamynd.ai/agent-controls-agentsafe/x402-payment-binding.md). Agents can also search and read this documentation through its [MCP server](https://docs.metamynd.ai/~gitbook/mcp).

# x402 Payment Binding

MAGP never holds funds — it only binds and attests. Settlement itself runs over [**x402**](https://github.com/coinbase/x402); MAGP's job is making sure a payment can never diverge from the authorization that permitted it, and that a claim about what was paid can be checked.

#### Authorize before pay

A payment must be bound to an `authorizationId` returned by a permitting verdict from `POST /policy/mandate/authorize`. A payment whose amount differs from the authorized amount **must** be refused (`AMOUNT_MISMATCH`); a reused authorization **must** be refused.

#### Hold → claim → capture

On a permitting verdict for a value-bearing action, the gate atomically **reserves** ("holds") the amount against the mandate's cap (gate step 16 — see [The Authorize Gate](https://docs.metamynd.ai/agent-protocol/the-authorize-gate-16-ordered-checks)). From there:

1. **Claim.** Before it pays, the service that executes the action claims the hold — `POST /policy/mandate/authorize/:authId/effect/dispatching`, atomic and single-use — and declares the payment rail with body `{ "x402": true }`. The hold is now **x402-bound**.
2. **Pay.** The service settles the payment over x402.
3. **Capture** with what was actually charged — `POST /policy/mandate/authorize/:authId/capture` — or, if the payment provably did not happen, **void**. If the outcome is ambiguous (a timeout, a lost response), mark the effect **unknown** and let reconciliation decide.

A hold nobody claims expires and auto-voids — nothing sits reserved indefinitely. **A claimed hold is different: it is a commitment.** The payment may already have happened, so it does not lapse with the hold TTL, and only the claimer can settle it lower or release it. `HOLD_VOIDED` is the reason code when a reservation expires or is voided.

Full lifecycle, who may call each step, and request/response examples: [Settlement & Settlement Evidence](https://docs.metamynd.ai/agent-protocol/settlement-and-settlement-evidence).

#### How the binding is actually enforced

The x402 `PaymentRequirements` the service returns in its `402` response carries the authorization id in `accepts[0].extra.magpAuthorizationId`, and `maxAmountRequired` is set to the authorized amount in minor units — this is the structural binding of the payment challenge to a specific authorization.

`checkSettlementBinding(requirements, { authorizationId, paidAmountMinor })` then enforces:

| Condition                                       | Result                   |
| ----------------------------------------------- | ------------------------ |
| `accepts[0].extra.magpAuthorizationId` missing  | `MISSING_BINDING`        |
| `magpAuthorizationId !== claim.authorizationId` | `AUTHORIZATION_MISMATCH` |
| `paidAmountMinor > maxAmountRequired`           | **`AMOUNT_MISMATCH`**    |

Field-level mismatch guards also exist when a service claims an authorization: the guard compares the claim grant with the request it was handed and refuses `AUTHORIZATION_AGENT_MISMATCH`, `AUTHORIZATION_AMOUNT_MISMATCH`, `AUTHORIZATION_CURRENCY_MISMATCH`, `AUTHORIZATION_MERCHANT_MISMATCH` (and `AUTHORIZATION_ACTION_MISMATCH`), so a cheap legitimate authorization cannot unlock a different, more expensive payment.

#### Anti-replay at settlement

`settle()` atomically claims/reserves the authorization in a settlement store **before** calling the facilitator — closing a check-then-settle race. A second settle attempt on the same `authorizationId` returns `SETTLEMENT_REUSED`. If the facilitator call throws, the reservation is released so a legitimate retry can proceed (`SETTLEMENT_FAILED`, retryable).

Endpoints (see [API Endpoints](https://docs.metamynd.ai/agent-protocol/api-endpoints) for the full list):

* `POST /magp/settlement/reserve` — atomic reservation before settling; `409` on reuse.
* `POST /magp/settlement/finalize` — mark settled, carrying the tx hash.
* `POST /magp/settlement/release` — release a reservation whose settlement failed.

#### x402-bound holds and the settlement observer

Reporting what was charged is a claim, and a claim that *less* was charged hands budget back — so it is checked. Only **x402-bound** holds (claimed with `x402: true`) are independently observed; a hold claimed without it is never probed.

**Settling below the authorization.** For an x402-bound hold, a claimer reporting a lower amount presents the Hedera transaction id (`settlementTxHash`, `0.0.X@seconds.nanos`) **and** the account it paid (`payTo`). The **Hedera mirror-node observer** then checks, on the public mirror node, that the transaction exists, succeeded, and credited `payTo` with a matching amount (HBAR via the network's own exchange rate, or a configured HTS stablecoin). If it does, the amount recorded is the one the mirror node **observed**, with `settlementEvidence: independently_confirmed`. If it cannot confirm — unreachable, not yet indexed, no credit to `payTo`, a different amount — the lower figure is **refused**, never believed: `SETTLEMENT_NOT_CONFIRMED`, `SETTLEMENT_AMOUNT_MISMATCH` or `SETTLEMENT_NOT_FOUND` (HTTP 400, code in `data.reasonCode`). The claimer can still capture at the full amount, retry once the transaction is visible, or mark the effect unknown.

**Releasing a claimed hold** is the same act as settling it at zero, so it needs the same support: the observer must **affirm** that nothing was settled. An absent record is never proof that nothing happened.

**The facilitator probe never confirms.** The x402 facilitator MetaMynd deploys is stateless — it verifies and settles, but keeps no per-authorization settlement record — so a probe of it can only ever answer "unknown". Only the Hedera mirror node can positively confirm a lowered settlement. In practice, a lowered capture on an x402-bound hold needs a transaction id plus `payTo`, and a claimed x402-bound hold whose outcome is uncertain goes to reconciliation (and, failing that, a human) rather than being released — it fails closed.

**Non-x402 holds** are not probed. A claimer's lowered settlement on them is believed because of who reported it and recorded as `counterparty_attested`. The trusted-counterparty registry narrows *who* can claim; it does not make the claimer honest.

**The payee directory** adds an owner-side check. An owner may register the accounts each merchant is paid into (dashboard → Trusted Counterparties → Merchant payee accounts, or `POST /policy/payees`). For a merchant with an active entry, a lowered settlement must name one of those accounts in `payTo` (`PAYEE_NOT_REGISTERED` otherwise; `PAYEE_NOT_VERIFIED` if the directory cannot be read). The observer proves the named account was paid; the directory proves it is the right account. See [Trusted Counterparties & Payee Directory](https://docs.metamynd.ai/core-concepts/trusted-counterparties-and-payee-directory).

**More than authorized.** A settlement may never exceed the authorized amount. If reconciliation observes an over-settlement, the effect goes to `compensation_required` (`SETTLED_OVER_AUTHORIZED`) for a person to decide.

**What the settled amount rests on (`settlementEvidence`)**

| Value                      | Meaning                                                                                                                         |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `unattested`               | The full authorized amount, counted for a caller that is not the claiming counterparty. Asserts nothing about what was charged. |
| `unclaimed_lowered`        | Settled below the authorization **before** any claim — a release, not a report of a charge.                                     |
| `counterparty_attested`    | The claiming counterparty reported the amount. Believed because of who said it; nothing confirmed it.                           |
| `independently_confirmed`  | The settlement observer confirmed this amount on the remote system (for x402-bound holds: the Hedera mirror node).              |
| `operator_resolved`        | A platform operator, resolving an ambiguous effect, decided the amount.                                                         |
| `reconciled_at_authorized` | The remote system confirmed the effect occurred but reported no amount, so the full authorized amount is counted.               |

The execution receipt issued at capture (receipt version 2) signs `settlementEvidence` into its payload, so a relying party verifying the receipt at `GET /action-passport/receipt/verify/:authorizationId` gets a tamper-evident answer to how sure the platform was that the settlement was real.

**Client parameters**

```js
// @metamynd/agentsafe-mcp-guard or @metamynd/agentsafe-a2a-guard (service side)
await guard.captureAuthorization({
  authorizationId, claimToken,          // claimToken only for an anonymous claim
  amountCharged: 140,
  settlementTxHash: '0.0.4815162@1758790000.123456789',
  payTo: '0.0.2342',                    // the account you paid
});
```

```python
# metamynd-client (Python)
client.capture(authorization_id, 140, settlement_tx_hash="0.0.4815162@1758790000.123456789", pay_to="0.0.2342")
```

#### The facilitator

Settlement of an x402 payment is verified against a real chain by a standalone **facilitator** service — Express + `@hashgraph/sdk`, separate from the gateway. It doesn't hold funds either: `verify()` queries a `TransactionReceiptQuery` against Hedera and reports `valid: status === 'SUCCESS'`; `settle()` calls `verify()` and returns the same proof (Hedera transactions are already final once submitted, so "settling" here means confirming the on-chain transaction, not broadcasting one).

Its routes are mounted under `/facilitator`: `POST /facilitator/verify`, `POST /facilitator/settle`, `GET /facilitator/supported` (lists supported networks based on which operator keys are configured — `hedera-testnet` / `hedera-mainnet` / `base-sepolia` / `solana-devnet`). The facilitator serves x402 payment tools; it is not the settlement observer described above.

#### Signed authorization, underneath it all

The `authorizationId` a payment is bound to is only trustworthy because the request that produced it was signed — see [Request Signing & Message Format](https://docs.metamynd.ai/agent-protocol/request-signing-and-message-format) for the exact Ed25519 scheme.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.metamynd.ai/agent-controls-agentsafe/x402-payment-binding.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
