> ## 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.

# Create a transaction

> Creates a transaction that buys from one merchant with one of the buyer's saved cards. Declare what it buys in `purchase`: `ucp_checkout` sends the merchant's UCP checkout, which Sapiom drives; `browser_checkout` states the merchant and total of a checkout page your agent completes in a browser. Name the card in `funding`. Follow the response's `nextAction` with [Get a transaction](/api-reference/transactions/get-a-transaction). A retry with the same `Idempotency-Key` and body returns the same transaction. Requires a [buyer key](/api-reference/overview#authentication).

> [!NOTE]
>
> Pick `purchase.type` by merchant. Call [Check a merchant](https://docs.sapiom.ai/api-reference/merchants/check-a-merchant.md) first: when `status` is `supported`, send `ucp_checkout`. For any other merchant, send `browser_checkout`. Both need a browser session with [Browser Pay](https://docs.sapiom.ai/transactions/browser-pay) attached to enter the card.

| | `ucp_checkout` | `browser_checkout` |
| - | - | - |
| Who states the items and total | The merchant. `purchase.assertedBy` is `merchant`. | Your agent. Sapiom doesn't check them. `purchase.assertedBy` is `agent`. |
| `shipping` | Optional | Refused. Enter the address on the checkout page. |
| `Idempotency-Key` | Required | Optional. Send one. |
| Change the purchase | [Replace the checkout](https://docs.sapiom.ai/api-reference/transactions/replace-the-checkout.md) | Not possible. Cancel and create a new transaction. |


## OpenAPI

````yaml /api-reference/openapi.json post /v1/transactions
openapi: 3.0.0
info:
  title: Sapiom Pay API
  version: '1.0'
  description: >-
    Create buyers, save their cards and authorize transactions. Send your
    platform key or a buyer key in the `x-api-key` header.
servers:
  - url: https://api.sapiom.ai
    description: Production
security:
  - api-key: []
tags:
  - name: Buyers
    description: One buyer per end user. Called tenants in the API.
  - name: Cards
    description: Hosted card setup links and the buyer's saved cards.
  - name: Spending limits
    description: Limits on what each card can spend.
  - name: Merchants
    description: Check whether Sapiom can buy from a merchant.
  - name: Transactions
    description: Create, read and cancel a transaction, and drive its UCP checkout.
  - name: Browser Pay relay
    description: The relay Browser Pay uses to send the card, for either purchase type.
paths:
  /v1/transactions:
    post:
      tags:
        - Transactions
      summary: Create a transaction
      description: >-
        Creates a transaction that buys from one merchant with one of the
        buyer's saved cards. Declare what it buys in `purchase`: `ucp_checkout`
        sends the merchant's UCP checkout, which Sapiom drives;
        `browser_checkout` states the merchant and total of a checkout page your
        agent completes in a browser. Name the card in `funding`. Follow the
        response's `nextAction` with [Get a
        transaction](/api-reference/transactions/get-a-transaction). A retry
        with the same `Idempotency-Key` and body returns the same transaction.
        Requires a [buyer key](/api-reference/overview#authentication).
      operationId: TransactionController_createTransaction
      parameters:
        - name: Idempotency-Key
          required: false
          in: header
          schema:
            type: string
          description: >-
            Your unique ID for this transaction. A retry with the same key
            returns the same transaction instead of buying twice. Required for a
            `ucp_checkout`. The older spelling `x-idempotency-key` still works;
            sending both with different keys returns `400 invalid_request`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTransactionRequest'
            examples:
              ucp_checkout:
                summary: UCP checkout
                value:
                  purchase:
                    type: ucp_checkout
                    merchant:
                      origin: https://shop.example
                    checkout:
                      currency: USD
                      line_items:
                        - item:
                            id: merchant-product-id
                          quantity: 1
                  funding:
                    source: external_card
                    paymentCardId: 00000000-0000-4000-8000-000000000001
              browser_checkout:
                summary: Browser checkout
                value:
                  purchase:
                    type: browser_checkout
                    merchant:
                      origin: https://store.example
                      name: Example Store
                    total:
                      amount: '54.18'
                      currency: USD
                    description: Trail running shoes, size 10, standard shipping
                    claimedLineItems:
                      - title: Trail running shoes, size 10
                        quantity: 1
                        unitAmount: '48.00'
                    pageUrl: https://store.example/checkout
                  funding:
                    source: external_card
                    paymentCardId: 00000000-0000-4000-8000-000000000001
      responses:
        '201':
          description: Transaction created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponseDto'
        '400':
          description: >-
            Invalid request data. Card funding that names no card, for a tenant
            with no saved card that can pay, is refused with `code:
            "no_saved_card"`: send the cardholder a card setup link, then create
            the transaction again. A card that can't pay is refused with `code:
            "card_unavailable"` and a `cardReason` (`missing`, `removed`,
            `failed`, `pending`, `setup_pending`, `wrong_environment`), or with
            `code: "no_card_route"`. A `purchase` that is wrong is refused with
            `code` `unsupported_purchase_type`, `invalid_purchase`,
            `field_not_allowed` or `field_required`, and `field` naming what to
            fix. Different keys in `Idempotency-Key` and `x-idempotency-key` are
            refused with `code: "invalid_request"`.
        '401':
          description: Unauthorized - invalid or missing API key
        '409':
          description: >-
            `idempotency_conflict`: the purchase replays an `Idempotency-Key`
            first used for a different request.
      security:
        - api-key: []
components:
  schemas:
    CreateTransactionRequest:
      type: object
      required:
        - purchase
        - funding
      properties:
        purchase:
          description: What the transaction buys. Each `type` takes only its own fields.
          oneOf:
            - type: object
              title: UCP checkout
              description: >-
                Sapiom opens and drives the merchant's UCP checkout in the same
                call, and the merchant states the items and total. Use it when
                [Check a merchant](/api-reference/merchants/check-a-merchant)
                returns `supported`. If you send `shipping`, leave `buyer` out
                of `checkout`.
              required:
                - type
                - merchant
                - checkout
              additionalProperties: false
              properties:
                type:
                  type: string
                  enum:
                    - ucp_checkout
                  description: >-
                    Sapiom drives the merchant's UCP checkout, and opens it in
                    this call.
                merchant:
                  type: object
                  required:
                    - origin
                  additionalProperties: false
                  properties:
                    origin:
                      type: string
                      maxLength: 200
                      description: The merchant's origin.
                      example: https://shop.example
                checkout:
                  type: object
                  description: >-
                    The merchant's UCP checkout create request, such as
                    `currency` and `line_items`, without payment data. If you
                    send `shipping`, leave `buyer` out.
                  example:
                    currency: USD
                    line_items:
                      - item:
                          id: merchant-product-id
                        quantity: 1
              example:
                type: ucp_checkout
                merchant:
                  origin: https://shop.example
                checkout:
                  currency: USD
                  line_items:
                    - item:
                        id: merchant-product-id
                      quantity: 1
            - type: object
              title: Browser checkout
              description: >-
                Your agent completes the merchant's own checkout page in a
                browser and states what it's buying. Sapiom doesn't contact the
                merchant and checks nothing in the statement against it: your
                rules and the buyer approve the stated `total`, but Sapiom can't
                hold the merchant to it. Use it for a merchant without a
                supported UCP checkout. A browser purchase can't be changed: to
                buy something else, cancel it and create a new transaction.
              required:
                - type
                - merchant
                - total
              additionalProperties: false
              properties:
                type:
                  type: string
                  enum:
                    - browser_checkout
                  description: >-
                    Your agent checks out on the merchant's page and states what
                    it's buying. Don't send `shipping`: your agent enters it on
                    the page.
                merchant:
                  type: object
                  required:
                    - origin
                  additionalProperties: false
                  properties:
                    origin:
                      type: string
                      format: uri
                      maxLength: 200
                      description: >-
                        The checkout page's origin, with no path, query or
                        fragment. The card is relayed only from a page on this
                        origin.
                      example: https://store.example
                    name:
                      type: string
                      minLength: 1
                      maxLength: 256
                      description: >-
                        The merchant's name, shown to the buyer on the approval
                        and security-code pages. Defaults to the origin's
                        hostname.
                      example: Example Store
                total:
                  type: object
                  required:
                    - amount
                    - currency
                  additionalProperties: false
                  description: >-
                    The full amount the checkout page will charge, including
                    shipping and tax. Your rules and the buyer approve this
                    amount. Sapiom can't hold the merchant to it.
                  properties:
                    amount:
                      type: string
                      maxLength: 100
                      pattern: ^\d+(\.\d{1,2})?$
                      description: >-
                        A decimal string with at most two decimals, more than
                        zero.
                      example: '54.18'
                    currency:
                      type: string
                      enum:
                        - USD
                description:
                  type: string
                  minLength: 1
                  maxLength: 4000
                  description: What is being bought, in your agent's words.
                claimedLineItems:
                  type: array
                  maxItems: 64
                  description: >-
                    The items being bought, as your agent read them from the
                    page. The buyer sees each `title` and `quantity` on the
                    approval and security-code pages.
                  items:
                    type: object
                    required:
                      - title
                      - quantity
                    properties:
                      title:
                        type: string
                        minLength: 1
                        maxLength: 4000
                      quantity:
                        type: integer
                        minimum: 1
                      unitAmount:
                        type: string
                        maxLength: 100
                        pattern: ^\d+(\.\d{1,2})?$
                        description: The price of one, in USD.
                pageUrl:
                  type: string
                  format: uri
                  maxLength: 2048
                  description: The checkout page's URL, kept for the record.
              example:
                type: browser_checkout
                merchant:
                  origin: https://store.example
                  name: Example Store
                total:
                  amount: '54.18'
                  currency: USD
                description: Trail running shoes, size 10, standard shipping
                claimedLineItems:
                  - title: Trail running shoes, size 10
                    quantity: 1
                    unitAmount: '48.00'
                pageUrl: https://store.example/checkout
          discriminator:
            propertyName: type
        funding:
          description: >-
            The buyer's card that pays. Omit `paymentCardId` to use the buyer's
            default card.
          allOf:
            - $ref: '#/components/schemas/TransactionFundingDto'
        shipping:
          description: >-
            Only with `ucp_checkout`: the address and contact Sapiom fills into
            the merchant checkout wherever `checkout` leaves them out. Anything
            in `checkout` wins. Refused with `browser_checkout`; enter the
            address on the checkout page.
          allOf:
            - $ref: '#/components/schemas/TransactionShippingDto'
        returnUrl:
          type: string
          maxLength: 2048
          description: >-
            Return destination after hosted approval and card confirmation. Must
            use an origin or app scheme registered by the organization.
        metadata:
          type: object
          description: Additional metadata for the transaction
    TransactionResponseDto:
      type: object
      properties:
        returnUrl:
          type: string
          nullable: true
          description: Integrator-provided return destination for hosted transaction steps
        nextAction:
          type: object
          description: >-
            The next step in one vocabulary (`type` + `actor`: `wait`,
            `buyer_security_code`, `approval`, `payment_ready`, `closed`, …),
            always present for a purchase. For a transaction that buys nothing,
            only an approval or security-code step, absent when nobody needs to
            act. Links are derived at read time.
        purchase:
          type: object
          description: >-
            For a purchase: what is bought, from whom, for how much, and who
            said so (`assertedBy`: `merchant` for the merchant's own checkout
            answer, `agent` for the agent's unchecked statement). Read from
            durable records; absent for a transaction that buys nothing.
          example:
            type: ucp_checkout
            assertedBy: merchant
            merchant:
              origin: https://shop.example
            total:
              amount: '19.99'
              currency: USD
            lineItems:
              - title: Mug
                itemId: item_123
                quantity: 1
                unitAmount: '19.99'
            revision: 1
        order:
          type: object
          nullable: true
          description: >-
            For a purchase: the merchant-confirmed order outcome (`confirmed`,
            `not_confirmed`, `unknown`). With `confirmed`, the merchant's
            confirmation from its completed answer, for the platform to show the
            cardholder: `id`, `label` (the order number the buyer sees),
            `permalinkUrl` (the order on the merchant's site) and `links` (its
            refund, shipping, terms, privacy and contact pages, `{ type, url,
            title? }`), each null or empty when the merchant sent none. Null for
            a browser purchase, which has no order confirmation.
          example:
            outcome: confirmed
            id: gid://shopify/Order/1
            label: '#1008'
            permalinkUrl: https://shop.example/orders/1
            links:
              - type: refund_policy
                url: https://shop.example/policies/refund-policy
                title: Refund policy
        version:
          type: string
          description: >-
            For a purchase: changes whenever anything the caller acts on
            changes. Pass it back as `since` to wait for the next change.
        approvals:
          type: object
          description: >-
            Approval obligations and linked successor attempts; inspect an
            approval for current authority
        id:
          type: string
          description: Transaction ID
          example: 123e4567-e89b-12d3-a456-426614174000
        tenantId:
          type: string
          description: Organization ID
          example: 123e4567-e89b-12d3-a456-426614174000
        serviceName:
          type: string
          description: Service identifier
          example: openai
        actionName:
          type: string
          description: Action being performed
          example: completion
        resourceName:
          type: string
          description: Resource being accessed
          example: gpt-4
        serviceId:
          type: string
          nullable: true
          description: Service entity ID (foreign key reference)
          example: 123e4567-e89b-12d3-a456-426614174000
        status:
          enum:
            - pending
            - preparing
            - waiting_approval
            - authorized
            - completed
            - denied
            - cancelled
            - needs_revision
          type: string
          description: Transaction status
          example: authorized
        requiresPayment:
          type: boolean
          description: Whether the transaction requires payment
          example: true
        qualifiers:
          type: object
          description: Additional qualifiers for the transaction
          example:
            model: gpt-4
            tokens: 1000
        metadata:
          type: object
          description: Additional metadata for the transaction
        createdAt:
          format: date-time
          type: string
          description: Creation timestamp
          example: '2024-01-01T00:00:00.000Z'
        updatedAt:
          format: date-time
          type: string
          description: Last update timestamp
          example: '2024-01-01T00:00:00.000Z'
        authorizedAt:
          format: date-time
          type: string
          description: Authorization timestamp
          example: '2024-01-01T00:00:00.000Z'
        completedAt:
          format: date-time
          type: string
          description: Completion timestamp
          example: '2024-01-01T00:00:00.000Z'
        outcome:
          enum:
            - success
            - error
          type: string
          description: Transaction outcome (set when completed)
          example: success
        currentPaymentTransactionId:
          type: string
          nullable: true
          description: Current payment transaction ID if transaction requires payment
          example: 123e4567-e89b-12d3-a456-426614174000
        payment:
          description: Payment transaction details when transaction requires payment
          allOf:
            - $ref: '#/components/schemas/PaymentTransactionResponseDto'
        trace:
          description: Trace information for workflow grouping
          allOf:
            - $ref: '#/components/schemas/TraceResponseDto'
        agentId:
          type: string
          nullable: true
          description: Agent ID if transaction is associated with an agent
          example: 123e4567-e89b-12d3-a456-426614174000
        agent:
          description: Agent information if transaction is associated with an agent
          allOf:
            - $ref: '#/components/schemas/AgentResponseDto'
      required:
        - id
        - tenantId
        - serviceName
        - actionName
        - resourceName
        - status
        - requiresPayment
        - createdAt
        - updatedAt
    TransactionFundingDto:
      type: object
      properties:
        source:
          type: string
          enum:
            - external_card
          description: Pay with one of the tenant's own payment cards
        paymentCardId:
          type: string
          format: uuid
          description: >-
            The card fixed for this transaction. Omitted: resolve the tenant's
            default once at transaction creation.
      required:
        - source
    TransactionShippingDto:
      type: object
      properties:
        address:
          $ref: '#/components/schemas/TransactionShippingAddressDto'
        contact:
          $ref: '#/components/schemas/TransactionShippingContactDto'
    PaymentTransactionResponseDto:
      type: object
      properties:
        id:
          type: string
          description: Payment transaction ID
          example: 123e4567-e89b-12d3-a456-426614174000
        transactionId:
          type: string
          description: Transaction ID this payment belongs to
          example: 123e4567-e89b-12d3-a456-426614174000
        fiatAmount:
          type: string
          description: The payment amount in USD, as a decimal string.
        status:
          enum:
            - pending
            - preparing
            - authorized
            - settling
            - completed
            - failed
            - cancelled
          type: string
          description: Payment status
          example: authorized
        fundingSource:
          type: string
          description: '`external_card`: the buyer''s saved card pays.'
          enum:
            - external_card
        paymentCardId:
          type: string
          nullable: true
          description: The card paying a card-funded payment
          format: uuid
        credentialRoute:
          type: string
          description: >-
            `real_card_number`: the relay puts the real card into the merchant's
            payment request.
          enum:
            - real_card_number
          nullable: true
        placeholder:
          description: >-
            An authorized card payment's placeholder card, while it can still be
            relayed. Submit it in the merchant's card form; the relay swaps it
            for the real credential once.
          allOf:
            - $ref: '#/components/schemas/CardPlaceholderDto'
        reason:
          type: string
          nullable: true
          description: >-
            Why the payment failed, when it is a public code: `sapiom_error` (a
            fault on Sapiom's side; report the transaction's requestId). Absent
            otherwise; a transaction's checkout `nextAction` says why it ended.
          enum:
            - sapiom_error
          example: sapiom_error
        createdAt:
          format: date-time
          type: string
          description: Creation timestamp
          example: '2024-01-01T00:00:00.000Z'
        updatedAt:
          format: date-time
          type: string
          description: Last update timestamp
          example: '2024-01-01T00:00:00.000Z'
        authorizedAt:
          format: date-time
          type: string
          nullable: true
          description: Authorization timestamp
          example: '2024-01-01T00:00:00.000Z'
      required:
        - id
        - transactionId
        - fiatAmount
        - status
        - createdAt
        - updatedAt
    TraceResponseDto:
      type: object
      properties:
        id:
          type: string
          description: Trace ID
          example: 123e4567-e89b-12d3-a456-426614174000
        externalId:
          type: string
          nullable: true
          description: Optional user-supplied external ID for trace correlation
          example: checkout-session-abc123
      required:
        - id
    AgentResponseDto:
      type: object
      properties:
        id:
          type: string
        tenantId:
          type: string
        label:
          type: string
        name:
          type: string
        description:
          type: string
          nullable: true
        status:
          type: string
        createdAt:
          format: date-time
          type: string
        updatedAt:
          format: date-time
          type: string
      required:
        - id
        - tenantId
        - label
        - name
        - status
        - createdAt
        - updatedAt
    TransactionShippingAddressDto:
      type: object
      properties:
        first_name:
          type: string
          maxLength: 255
          example: Jane
        last_name:
          type: string
          maxLength: 255
          example: Buyer
        street_address:
          type: string
          maxLength: 255
          example: 1 Market St
        extended_address:
          type: string
          maxLength: 255
          description: Apartment, suite, unit
          example: Suite 300
        address_locality:
          type: string
          maxLength: 255
          description: City or locality
          example: San Francisco
        address_region:
          type: string
          maxLength: 255
          description: State, province or region
          example: CA
        postal_code:
          type: string
          maxLength: 32
          example: '94105'
        address_country:
          type: string
          pattern: /^[A-Z]{2}$/
          description: ISO 3166-1 alpha-2 country code
          example: US
      required:
        - street_address
        - address_locality
        - address_country
    TransactionShippingContactDto:
      type: object
      properties:
        email:
          type: string
          format: email
          example: jane@example.com
        phone_number:
          type: string
          maxLength: 32
          description: Some merchants require a phone number for delivery
          example: '+14155550100'
    CardPlaceholderDto:
      type: object
      properties:
        number:
          type: string
          description: Card number shaped like the real card's brand; not a real card
          example: '4000123412341234'
        expMonth:
          type: number
          example: 7
        expYear:
          type: number
          example: 2029
        cvc:
          type: string
          example: '123'
        brand:
          type: string
          example: visa
        expiresAt:
          type: string
          description: After this the placeholder no longer relays
          example: '2026-10-13T13:00:00.000Z'
        injectionRef:
          type: string
          description: The armed injection the relay looks the placeholder up by
        transactionId:
          type: string
          description: The transaction the placeholder is relayed through
      required:
        - number
        - expMonth
        - expYear
        - cvc
        - brand
        - expiresAt
        - injectionRef
        - transactionId
  securitySchemes:
    api-key:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your platform key for buyer management, or a buyer key for everything
        else.

````

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