> 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/get-started/settle-a-claimed-hold.md). Agents can also search and read this documentation through its [MCP server](https://docs.metamynd.ai/~gitbook/mcp).

# Settle a Claimed Hold

This guide is for the **service** that executes an authorized action — an MCP server, an HTTP gateway, an A2A skill. When your service claims a hold (`requireAuthorization`), it takes on the job of saying what happened: capture it, release it, or mark it unknown. Concepts: [Holds, Claims & Exactly-Once Execution](https://docs.metamynd.ai/core-concepts/holds-claims-and-exactly-once-execution) and [Settlement & Settlement Evidence](https://docs.metamynd.ai/agent-protocol/settlement-and-settlement-evidence).

{% embed url="<https://youtu.be/mIubY21BhnY>" %}

#### Why the service settles, not the agent

A permit for a value-bearing action reserves its amount against the mandate's cap as a **hold**. The service that is about to execute it **claims** the hold — atomically and exactly once. From that moment the hold is a commitment:

* it stays against the cap until it's settled — it no longer lapses after the 15-minute hold window;
* only the claimer can settle it **below** the authorized amount, or release it.

Without that rule, an agent could let your service execute a $250 purchase and then capture `$0` (or void) its own hold to get the budget back. The agent can still capture at the full authorized amount — that can only spend more — but it can't lower or release a hold your service claimed.

Failing to settle can only over-count spend, never under-count it. Settle every claim anyway: an unsettled claimed hold keeps the owner's budget tied up until someone reconciles it.

#### Your four calls

All four are methods on the mcp-guard (`@metamynd/agentsafe-mcp-guard` ≥ 0.12.2 for `payTo`). They are best-effort and never throw: each returns `{ ok, reasonCode, … }`.

| Situation                                                   | Call                                                                                              | Budget                                  |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | --------------------------------------- |
| The action ran, at the authorized amount                    | `captureAuthorization({ authorizationId, amountCharged })`                                        | spent                                   |
| The action ran and cost **less**                            | `captureAuthorization({ authorizationId, amountCharged, payTo, settlementTxHash?, bookingRef? })` | the lower amount is spent               |
| The upstream **provably did not** execute (a clean refusal) | `releaseAuthorization({ authorizationId, reason })`                                               | returned                                |
| You don't know — a timeout, a 5xx, a dropped connection     | `markAuthorizationUnknown({ authorizationId, reason })`                                           | stays committed; goes to reconciliation |

Plus one read: `lookupOutcome({ authorizationId })` — what became of this authorization, and is a retry safe?

**Release only what provably did not happen.** A throw, a timeout or an ambiguous error does not prove the upstream did nothing. Mark those unknown; releasing would hand back the budget of something that may have happened.

#### Pattern 1 — let the guard settle for you

```js
const bookFlight = guard.guardIncomingTool('flight-purchase', rawBookFlight, {
  bindPayload: true, requirePayloadBinding: true,
  settle: true,   // handler returns → capture at the authorized amount; handler throws → mark unknown (never release)
});
```

Use this when the action always costs exactly what was authorized. The HTTP gateway does the same with its `settle` option (on by default) and lets you list upstream statuses that guarantee non-execution in `releaseOnStatus` (empty by default, on purpose). The A2A guard offers `guardA2ATask(skillId, handler, { settle: true })`.

#### Pattern 2 — settle yourself (recommended for anything that can cost less)

Give your service its own signing identity (`serviceDid` + `serviceKey`). The guard then signs the claim and every settlement call as your service, the issuer records your DID as the claimer, and no claim token is involved at all:

```js
const guard = createMcpGuard({
  serviceDid: process.env.SERVICE_DID, serviceKey: process.env.SERVICE_KEY,
  issuerApi: 'https://metamynd.ai/api/v1', policyPublicKey: process.env.MAGP_POLICY_PUBLIC_KEY,
  requireAuthorization: true,
});

const bookFlight = guard.guardIncomingTool('flight-purchase', async (signed, booking) => {
  const authorizationId = signed.authorizationId;       // the hold this call just claimed
  let result;
  try {
    result = await airline.book(booking, { idempotencyKey: authorizationId }); // let the upstream de-duplicate
  } catch (err) {
    if (err.definitelyNotExecuted) {                   // e.g. the upstream rejected the request outright
      await guard.releaseAuthorization({ authorizationId, reason: 'UPSTREAM_REJECTED' });
    } else {
      await guard.markAuthorizationUnknown({ authorizationId, reason: 'UPSTREAM_TIMEOUT' });
    }
    throw err;
  }

  const settled = await guard.captureAuthorization({
    authorizationId,
    amountCharged: result.totalCharged,                // may be below the authorized amount
    bookingRef: result.pnr,
    payTo: result.paidAccount,                         // the account you paid — required when settling lower
    settlementTxHash: result.txId,                     // optional: a Hedera transaction id, if payment went on-chain
  });
  if (!settled.ok) console.warn('capture refused', settled.reasonCode); // e.g. PAYEE_NOT_REGISTERED
  return result;
}, { bindPayload: true, requirePayloadBinding: true });
```

The authorization id is the effect's natural idempotency key **for your upstream**: pass it on, and the action runs once even if your service is ever asked to run the same call twice. (Never use it as the claim's own idempotency key — the agent knows it. The guard generates a secret one per claim.)

**Anonymous services.** A service with no signing key can still claim, but proves it is the claimer with a **claim token**: `verifyRequest()` returns it as `decision.claimToken` on a claimed permit, and you pass `claimToken` to `captureAuthorization`, `releaseAuthorization` and `markAuthorizationUnknown`. The token is non-enumerable so a logged or echoed verdict doesn't leak it — keep it server-side; the agent must never see it. Anonymous claims are refused wherever the owner's counterparty registry is enforced (always for mainnet agents), so prefer a signing identity.

#### Settling below the authorized amount

When you report a lower amount, three things decide whether it's accepted:

1. **You must be the claimer.** A lower amount from anyone else is refused.
2. **The payee directory.** If the owner has listed the accounts a merchant is paid into, a lowered settlement for that merchant must name one of them in `payTo` (a Hedera account id `0.0.X` or an EVM address) or it's refused with `PAYEE_NOT_REGISTERED`. If the directory can't be read, the lowered settlement is refused (`PAYEE_NOT_VERIFIED`) rather than let through. Merchants the owner hasn't listed, and settlements at the full amount, are unaffected. `payTo` is not part of the signed capture message; the issuer reads it only after the call has proven it came from the claimer.
3. **Independent confirmation, for x402-bound holds.** A hold whose claim declared x402 as its payment rail (the claim body carries `"x402": true`) can't simply be lowered on the claimer's word. The lower figure must be confirmed by an independent observer of the payment: today that is the public Hedera mirror node, which needs `settlementTxHash` to be a Hedera transaction id and `payTo` to be the account it credited. If the observer can't confirm it — unreachable, undecided, no record, or a different amount — the lower figure is refused (`SETTLEMENT_NOT_CONFIRMED`, `SETTLEMENT_NOT_FOUND`, `SETTLEMENT_AMOUNT_MISMATCH`) and you can still settle in full. Releasing a claimed x402-bound hold likewise needs the observer to affirm that nothing was settled; silence isn't that. The guards declare it when you ask them to: `guardIncomingTool(action, handler, { x402: true })` or `verifyRequest(signed, { x402: true })` in agentsafe-mcp-guard 0.14.0+, `guardA2ATask(skill, handler, { x402: true })` in agentsafe-a2a-guard 0.8.0+, or `x402: true` on a route in agentsafe-http-gateway 0.12.0+. Set it only for tools that are paid by x402, then report the payment's transaction id as `settlementTxHash` and the account as `payTo` when you settle below the authorization.

A settled amount can never exceed the authorized one.

#### What your settlement rests on: `settlementEvidence`

The issuer keeps the authorized amount and the settled amount side by side, and records what the settled figure rests on. `captureAuthorization` returns it as `result.settlementEvidence`, and `lookupOutcome` reports it later:

| `settlementEvidence`       | Meaning                                                                                                                                                                      |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `unattested`               | The full authorized amount, counted for a caller that is not the claiming service. It asserts nothing about what was charged.                                                |
| `unclaimed_lowered`        | Settled below the authorization **before** any claim. Nothing can have executed, so it's a release, not a report of a charge.                                                |
| `counterparty_attested`    | The claiming service reported the amount. Believed because of who said it; nothing confirmed it. A lowered settlement on a hold that is not x402-bound is recorded this way. |
| `independently_confirmed`  | An observer of the remote system reported this amount.                                                                                                                       |
| `operator_resolved`        | A platform operator, resolving an ambiguous effect, decided the amount.                                                                                                      |
| `reconciled_at_authorized` | The remote system confirmed the effect happened but reported no amount, so the full authorized amount is counted.                                                            |

#### When a release is refused

A refused `releaseAuthorization` comes back `{ ok: false, reasonCode }`. The underlying `void` never answers a refusal with a 5xx; it answers:

* **409** `HOLD_UNDER_RECONCILIATION` — the owner forced the hold into reconciliation (below). You no longer hold any power over it.
* **409** `CLAIMED` — a claim landed while your void was in flight.
* **409** `EFFECT_NOT_VOIDABLE` — you already marked the effect `dispatched` or `unknown`, so it may have happened. It is reconciled, not voided.
* **403** `COUNTERPARTY_MISMATCH` — the hold is claimed and the call isn't signed by (or doesn't carry the claim token of) the claimer.
* **400** `SETTLEMENT_NOT_CONFIRMED` — the hold is x402-bound and the settlement observer didn't affirm that nothing was settled. **With a facilitator configured this is every release of a claimed x402-bound hold**, by design: absence of a record is never proof. Capture it, or mark it unknown and let reconciliation decide.

`NOT_HELD` (already settled or released) stays a 200: repeating a void that already happened isn't an error.

#### Unknown, reconciliation and the owner's override

`markAuthorizationUnknown` freezes the hold out of capture and void and hands it to reconciliation, which settles it at whatever the remote system (or an operator) reports — not blindly at the authorization. A settlement larger than the authorization is never absorbed: it goes to compensation (`SETTLED_OVER_AUTHORIZED`) for a person to decide.

Only the claimer, the owner of the hold's mandate, or a platform admin may mark a hold unknown or ask for reconciliation. The authorization id alone isn't enough (`COUNTERPARTY_MISMATCH`, `RECONCILE_NOT_PERMITTED`).

An owner who stops trusting the service holding a claim — typically one they've just revoked — can **force the hold into reconciliation** (dashboard: Trusted Counterparties → the revoked service's row → **Force into reconciliation**; API: `POST /policy/mandate/authorize/{id}/effect/force-reconcile`). The budget stays committed, the claimer loses every power over the hold (even a full-amount capture is refused with `HOLD_UNDER_RECONCILIATION`), and it settles only on what the settlement observer establishes or an operator decides. Nothing is released or reassigned: a hold that may have executed must not run twice.

#### Look up the outcome before any retry

```js
const o = await guard.lookupOutcome({ authorizationId });
// o.outcome: not_started | expired | in_flight | settled | not_executed | unknown | reversing | reversed | reversal_failed
if (o.ok && o.retrySafe) { /* a fresh authorization cannot duplicate this one */ }
```

`GET /policy/mandate/authorize/{id}/effect` is public and keyed by the authorization id. It never returns a claim token or the claimer's identity.

| `outcome`                                                          | `nothingExecuted` | `retrySafe`                                                           |
| ------------------------------------------------------------------ | ----------------- | --------------------------------------------------------------------- |
| `not_started` — authorized, unclaimed, inside its window           | yes               | **no** — still claimable; void it first, then it reads `not_executed` |
| `expired` — unclaimed, past its window                             | yes               | yes                                                                   |
| `not_executed` — voided before a claim, cancelled, or failed clean | yes               | yes                                                                   |
| `in_flight` — claimed                                              | no                | no                                                                    |
| `settled`                                                          | no                | no                                                                    |
| `unknown` — ambiguous or under reconciliation                      | no                | no                                                                    |
| `reversing` / `reversed` / `reversal_failed`                       | no                | no                                                                    |

Retry only on `retrySafe`. Never retry `unknown` or `in_flight` blindly.

**Capture and void are not idempotent the way a claim is.** Retrying a capture that already landed answers `409 NOT_HELD` (the bare code as `message`); retrying a void answers `{ voided: false, reasonCode: "NOT_HELD" }`. Both look like failures but usually mean the first call succeeded and only its response was lost. After a timeout, a dropped connection or a 5xx, read the outcome before concluding anything failed.

#### Refunds

`POST /policy/mandate/authorize/{id}/refund` with `{ "amount"?, "reason"?, "claimToken"? }` records a reversal of an already-captured hold. It is **record-only**: MetaMynd never moves money — returning the funds is your (or your facilitator's) job, just as the original charge was. What it does do is reduce what the mandate's cumulative cap counts, so a refunded purchase genuinely frees budget.

* Omit `amount` for a full refund of whatever remains captured.
* Only the hold's **claimer** may refund it (or the hold's owner or an admin). A signed claimer signs under its own action `refund`, over `amount` (the empty string for a full refund) and `reason`; an anonymous claimer sends its `claimToken`. Anyone else gets `403 COUNTERPARTY_MISMATCH`. A `void` signature is never accepted for a refund.
* The guards do this for you: `guard.refundAuthorization({ authorizationId, amount?, reason?, claimToken? })` in `@metamynd/agentsafe-mcp-guard` 0.15.0 and `@metamynd/agentsafe-a2a-guard` 0.9.0.

#### Python

The Python client (`metamynd-client`) is agent-side: it can't claim a hold, so it can't lower or release one a service claimed. From Python you can:

* read the outcome: `client.outcome(auth_id)` returns `outcome`, `nothing_executed`, `retry_safe`, `authorized_amount`, `settled_amount` and `settlement_evidence`;
* capture at the full amount, or void a hold nobody has claimed: `client.capture(auth_id, amount)`, `client.void(auth_id, reason=...)`. `capture` also accepts `pay_to=` (0.5.2) for the account paid.

A Python service that executes value-bearing actions should sit behind the HTTP gateway ([agentsafe-http-gateway](https://docs.metamynd.ai/sdks/agentsafe-http-gateway)), which claims and settles for it.

#### Refusals you'll meet

| Code                                                                               | From                                  | Meaning                                                                                             |
| ---------------------------------------------------------------------------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `AUTHORIZATION_ALREADY_CLAIMED`                                                    | claim                                 | Someone already claimed this authorization. Look up the outcome; don't execute                      |
| `PAYEE_NOT_REGISTERED` · `PAYEE_NOT_VERIFIED`                                      | lowered capture                       | `payTo` isn't one of the owner's listed accounts for this merchant / the directory couldn't be read |
| `SETTLEMENT_NOT_CONFIRMED` · `SETTLEMENT_NOT_FOUND` · `SETTLEMENT_AMOUNT_MISMATCH` | lowered capture on an x402-bound hold | The observer didn't confirm the lower figure; settle in full or mark unknown                        |
| `HOLD_UNDER_RECONCILIATION`                                                        | capture, void                         | The owner forced the hold into reconciliation (409)                                                 |
| `EFFECT_NOT_VOIDABLE`                                                              | void                                  | The effect is `dispatched` or `unknown`; reconcile it instead (409)                                 |
| `COUNTERPARTY_MISMATCH`                                                            | any settlement call                   | Signed by someone other than the claimer                                                            |
| `PASSPORT_EXPIRED` · `PASSPORT_ALREADY_CONSUMED` · `PASSPORT_REVOKED`              | capture                               | The Action Passport bound to this authorization can't be used for this capture                      |

The `PASSPORT_*` codes are in the published [reason-code registry](https://docs.metamynd.ai/agent-protocol/reason-code-registry) (`GET /magp/schema`). The other claim and settlement codes above are returned by the settlement endpoints themselves and aren't in that registry yet; they are defined in MAGP spec §8.7.


---

# 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/get-started/settle-a-claimed-hold.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.
