> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sapiom.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Sapiom Pay is for platforms whose agent shops for many end users. Each end user is a buyer with their own Sapiom key and saved cards.
> Use the buyer's key for every call made on that buyer's behalf. Never use one buyer's key for another user, and never give the agent the platform key.
> Backends call the REST API at https://api.sapiom.ai/v1. Agents can also call the hosted MCP tools at https://api.sapiom.ai/v1/mcp/pay. Both take the key in an x-api-key header.
> Keys that start with sk_test_ reach the sandbox, a separate test environment with its own buyers and cards, at the same addresses. Use test card numbers only there.
> Never ask a buyer for a card number, expiry date or CVV in chat. Buyers enter card details only on Sapiom's hosted pages.
> Check the merchant before buying. Use purchase.type ucp_checkout only when the merchant check returns supported. Otherwise use browser_checkout.
> Follow the nextAction in each transaction result. Action links are secrets for the intended buyer only.
> Use one idempotency key per transaction. Resume an unanswered create with the same request and key. If a UCP update or cancellation is uncertain, stop and hand off to a person. If a browser cancellation is uncertain, read the transaction and resend the same cancellation, with the same key, only if it is not closed. Never start a new transaction to escape an uncertain outcome.
> For a ucp_checkout purchase, report an order as placed only when order.outcome is confirmed; if it is unknown, stop and hand off to a person. A browser_checkout purchase has no order confirmation (order is null): confirm the order on the merchant's page.

# Sapiom Pay errors and how to handle them

> Error shapes for Sapiom Pay MCP tools, the transaction error codes, and which errors are safe to retry.

Sapiom Pay errors tell you what went wrong and what to do next. Follow the returned instructions rather than assuming any error is safe to retry.

## MCP tool errors

Payment-method and transaction tools return JSON in a text content block. Check `isError`, then parse the body:

```json theme={null}
{
  "error": {
    "code": "idempotency_conflict",
    "message": "…",
    "nextStep": "…"
  }
}
```

`nextStep` is a plain-language instruction for what to do. Transaction errors can also include `details`, with `retryable`, `retryWithSameIdempotencyKey` and a retry delay. Compatibility and spending-limit tools use their own error shapes.

## Transaction error codes

| Code | Meaning |
| - | - |
| `invalid_input` | The request failed validation. Fix it before retrying. |
| `not_found` | No transaction with that ID for this key. |
| `payment_method_not_ready` | The card cannot pay yet. Check its `readiness`. |
| `setup_link_not_found` | You passed `setupLinkId`, but this buyer has no setup link with that ID. Create a new link with `sapiom_add_payment_method`. |
| `setup_link_closed` | You passed `setupLinkId`, but the link expired or was canceled. Create a new link with `sapiom_add_payment_method`. |
| `idempotency_conflict` | The key already identifies a different request. |
| `checkout_conflict` | The request conflicts with the checkout's current state. Read the transaction and follow `nextStep`. |
| `merchant_refused` | The merchant rejected the request. |
| `merchant_unavailable` | The merchant could not be reached. |
| `checkout_rejected` | The checkout could not be accepted. |
| `timeout` | The outcome is unknown. Follow `nextStep`, and see [Recover without buying twice](https://docs.sapiom.ai/transactions/confirm-and-recover.md#recover-without-buying-twice) |
| `provider_unavailable` | A card provider could not be reached. |

Authentication, scope and permission errors are returned when a key is missing, invalid or lacks a permission.

A timeout does not mean nothing happened. For what to retry and when, see [Recover without buying twice](https://docs.sapiom.ai/transactions/confirm-and-recover.md#recover-without-buying-twice).

## Creating a transaction with no saved card

If you create a transaction with `POST /v1/transactions` without naming a card, Sapiom uses the buyer's default card. If the buyer has no active card, the request returns `400` with `"code": "no_saved_card"` and nothing is created. Send the buyer a [setup link](https://docs.sapiom.ai/cards/vault-a-card.md), then create the transaction again.

## Relay refusals

When the relay refuses, nothing was sent to the payment processor. Browser Pay's `refused` event carries one of these reasons:

| Reason | Meaning |
| - | - |
| `unknown_injection` | No placeholder with that reference for this buyer. |
| `injection_expired` | The placeholder expired. The transaction needs a new authorization. |
| `payment_released` | The payment was canceled, revised or denied. |
| `key_rotated` | Sapiom voided the placeholder. The transaction needs a new authorization. |
| `already_relayed` | Another relay already used this placeholder. |
| `relay_in_progress` | A relay of this placeholder is still running. Browser Pay retries with the same key. |
| `relaying_under_other_key` | Another relay of this placeholder, with a different idempotency key, is not complete. |
| `card_removed` | The buyer removed the card. |
| `card_unavailable` | Sapiom cannot use the card. For example, its setup is not complete. |
| `payment_not_authorized` | The payment or its approvals are no longer current. |
| `total_changed` | The merchant's checkout no longer matches what was authorized. |
| `destination_not_allowed` | The request isn't going where Sapiom can relay it: a public `https` URL, by `POST`, or the destination of the `profileId` it names. |
| `card_fields_invalid` | The card fields don't hold this transaction's placeholder, or the request carries other card data. Without a profile, the placeholder's number must appear in the body exactly once and nowhere in the URL or headers. |
| `merchant_mismatch` | The page or request is for a different merchant than the one authorized. |
| `provider_unavailable` | The card provider is not available now. |
| `merchant_unavailable` | Sapiom cannot read the merchant's checkout now. |
| `payments_stopped` | Sapiom has paused card payments. The placeholder no longer works. |
| `sapiom_error` | A problem in Sapiom stopped the relay. If the event has a `requestId`, give it to Sapiom. |

## Browser Pay failures

Browser Pay's `failed` event has one of these reasons. For the next step, refer to [Recover without buying twice](https://docs.sapiom.ai/transactions/confirm-and-recover.md#recover-without-buying-twice).

| Reason | Meaning |
| - | - |
| `intercept_unavailable` | Browser Pay cannot pause requests in a new tab or frame. It closes that tab or frame. |
| `unknown_session` | The request is from a tab or frame that Browser Pay does not monitor. Browser Pay stops the request. |
| `unreadable_body` | Browser Pay cannot read the request body. |
| `detached` | Browser Pay stopped before the request was complete. For example, your code called `detach()`. |
| `page_origin` | Browser Pay cannot read the origin of the top-level page. |
| `unknown` | Browser Pay does not know if the card went to the merchant. It does not send the card again. |
| `timeout` | The relay did not give a result before `timeoutMs`. |
| `network` | The relay call failed, or another error stopped Browser Pay. |
| `response_credential` | The relay sent the card, but the processor's response contains the placeholder number. Browser Pay does not give that response to the page. |
| `headers_unrelayable` | The request has more than 32 headers to forward, or a header name or value is too long. Browser Pay does not send the request to the relay. |

> [!NOTE]
>
> REST error responses and the full error inventory to be documented.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.