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

# Create a swap

> Converts balance between two of your currencies, synchronously and atomically — your balance changes instantly and the money never leaves your account (no OTP). Volatile pairs (BTC/GOLD) share the per-operation and 24h volume limits with payouts and card purchases. Requires an idempotency key: replaying returns the original swap and never re-executes.



## OpenAPI

````yaml /openapi.yaml post /v1/swaps
openapi: 3.1.0
info:
  title: CBPay API
  version: '1.89'
  description: |
    CBPay is a multi-currency payment platform: fiat payouts and collections
    across Latin America, internal transfers, on-chain funding and
    withdrawals, and KYC screening. Every account holds four independent
    virtual balances — USDT (the operating currency), USDC, BTC and GOLD
    (grams of fine gold) — that never mix or convert automatically.
    Payouts and service fees can be paid from any of the four balances:
    set a default with `PUT /v1/settlement` or override per payout with
    `settlement_asset`.

    All amounts are decimal strings in each currency's precision (6 decimals
    for USDT/USDC/GOLD, 8 for BTC). Errors always return
    `{"error": "<code>", "message": "<detail>"}`.
servers:
  - url: https://api.qbank.cl/platform
    description: Live (production, real money)
  - url: https://cryptobank.qbank.cl/platform
    description: Test (sandbox, simulated money — pk_test_ keys)
security:
  - bearerAuth: []
tags:
  - name: Receipts
    description: >-
      Branded PDF receipt per operation, with a public signed-QR authenticity
      check, receipt_url on every response/webhook and automatic email delivery
      on final states.
  - name: Authentication
    description: Register and log in account members. Sessions last 24 hours.
  - name: Account
    description: Profile, members and API keys of the calling account.
  - name: Balances
    description: Balances, movement history and FX rates.
  - name: Payouts
    description: >-
      Fiat dispersals debited from the settlement balance of your choice (USDT
      by default).
  - name: Payins
    description: Fiat top-ups credited to the USDT balance.
  - name: Transfers
  - name: Contacts
  - name: Swaps
    description: >-
      Free internal transfers between CBPay accounts (person or company, any
      combination).
  - name: Crypto
    description: On-chain funding and withdrawals (TRON, Ethereum and Bitcoin).
  - name: Segregated wallets
    description: >-
      On-chain wallets with their own balance (companies unlimited; persons 1
      per network+asset pair) — create, import, send, export the private key and
      auto-forward. The balance lives on-chain, never in the ledger.
  - name: QR Crypto POS
    description: >-
      Amount-bearing crypto QR charges for processors with physical POS
      terminals (company accounts): verified merchants, exclusive address + QR
      per charge, early payment detection, per-merchant reconciliation and
      refunds over the crypto withdrawal rail.
  - name: KYC / KYB
  - name: AML screening
    description: >-
      Identity verification: KYC for persons, KYB for companies, with AML
      screening, rescreening and continuous monitoring.
  - name: Wallet screening
    description: >-
      AML risk assessment of blockchain addresses (sanctions, illicit-fund
      exposure) with a per-scan fee, plus free automatic protection on
      withdrawals and deposits.
  - name: Analytics
  - name: Webhooks
    description: Subscriptions to receive signed event notifications.
  - name: Status
    description: Service availability.
  - name: Banking
    description: >-
      Real bank accounts: receive, hold and send money over international
      banking rails.
  - name: Cards
    description: >-
      Virtual and physical cards that spend Just-In-Time from the account's USDT
      balance, with per-card spending limits.
  - name: Security (OTP)
    description: >-
      One-time verification codes over SMS/WhatsApp/email protecting sensitive
      actions, plus self-service 2FA preferences. Applies to user sessions only
      — API keys are exempt.
  - name: Passkeys
    description: >-
      Passwordless sign-in with the device's biometrics (Face ID, Touch ID,
      Windows Hello, security keys) via WebAuthn, authenticator apps (TOTP) with
      backup codes, and session/device management.
  - name: Social login
    description: >-
      Passwordless sign up and sign in with Google, Apple, Microsoft and
      Facebook via token exchange. The front end obtains the provider
      credential; the API verifies it and issues the CBPay session.
paths:
  /v1/swaps:
    post:
      tags:
        - Swaps
      summary: Create a swap
      description: >-
        Converts balance between two of your currencies, synchronously and
        atomically — your balance changes instantly and the money never leaves
        your account (no OTP). Volatile pairs (BTC/GOLD) share the per-operation
        and 24h volume limits with payouts and card purchases. Requires an
        idempotency key: replaying returns the original swap and never
        re-executes.
      operationId: createSwap
      parameters:
        - $ref: '#/components/parameters/idempotencyKeyHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - from_asset
                - to_asset
                - amount
              properties:
                from_asset:
                  type: string
                  enum:
                    - USDT
                    - USDC
                    - BTC
                    - GOLD
                to_asset:
                  type: string
                  enum:
                    - USDT
                    - USDC
                    - BTC
                    - GOLD
                amount:
                  type: string
                  description: >-
                    Amount in the source currency (6 decimals for
                    USDT/USDC/GOLD, 8 for BTC).
                idempotency_key:
                  type: string
            examples:
              usdt_btc:
                summary: USDT to BTC
                value:
                  from_asset: USDT
                  to_asset: BTC
                  amount: '1000'
                  idempotency_key: swap-2026-07-10-a
              cross:
                summary: Direct BTC to GOLD
                value:
                  from_asset: BTC
                  to_asset: GOLD
                  amount: '0.01'
                  idempotency_key: swap-2026-07-10-b
              stables:
                summary: USDT to USDC
                value:
                  from_asset: USDT
                  to_asset: USDC
                  amount: '500'
                  idempotency_key: swap-2026-07-10-c
      responses:
        '200':
          description: Idempotency replay (original swap, never re-executed).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Swap'
              example:
                swap_id: 8a1b2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d
                account_id: 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d
                from_asset: USDT
                to_asset: BTC
                from_amount: '1000.000000'
                to_amount: '0.01568419'
                rate: '0.00001568'
                status: completed
                idempotency_key: swap-2026-07-10-a
                created_at: '2026-07-10T15:00:00Z'
                idempotency_hit: true
        '201':
          description: Swap executed (synchronous).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Swap'
              example:
                swap_id: 8a1b2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d
                account_id: 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d
                from_asset: USDT
                to_asset: BTC
                from_amount: '1000.000000'
                to_amount: '0.01568419'
                rate: '0.00001568'
                status: completed
                idempotency_key: swap-2026-07-10-a
                created_at: '2026-07-10T15:00:00Z'
        '400':
          description: >-
            invalid_asset / invalid_pair / invalid_amount / amount_too_small /
            swap_asset_disabled / idempotency_key_required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: amount_too_small
                message: amount is too small to convert at the current rate
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientFunds'
        '403':
          description: verification_required / service_disabled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: service_disabled
                message: this service is not enabled for your account
        '422':
          description: >-
            settlement_limit_exceeded / settlement_daily_limit_exceeded
            (volatile caps shared with payouts and cards).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: settlement_daily_limit_exceeded
                message: >-
                  the account exceeded its 24h volume for volatile assets; retry
                  later or use smaller amounts
        '503':
          description: Execution price unavailable or stale (pricing_unavailable).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: pricing_unavailable
                message: execution price is unavailable or stale; retry later
components:
  parameters:
    idempotencyKeyHeader:
      name: Idempotency-Key
      in: header
      required: false
      description: Alternative to the `idempotency_key` body field.
      schema:
        type: string
  schemas:
    Swap:
      type: object
      properties:
        swap_id:
          type: string
          format: uuid
        account_id:
          type: string
          format: uuid
          description: >-
            Owning account. Lets org admins attribute each record in the
            org-wide view.
        from_asset:
          type: string
          enum:
            - USDT
            - USDC
            - BTC
            - GOLD
        to_asset:
          type: string
          enum:
            - USDT
            - USDC
            - BTC
            - GOLD
        from_amount:
          type: string
        to_amount:
          type: string
        rate:
          type: string
          description: Destination units per source unit (marked execution rate).
        status:
          type: string
          example: completed
        idempotency_key:
          type: string
        created_at:
          type: string
          format: date-time
        idempotency_hit:
          type: boolean
          description: Present on replays.
    Error:
      type: object
      properties:
        error:
          type: string
          description: Machine-readable error code (snake_case).
          example: insufficient_funds
        message:
          type: string
          description: Human-readable explanation.
  responses:
    Unauthorized:
      description: Missing or invalid credential (`unauthorized`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: unauthorized
            message: invalid or missing credentials
    InsufficientFunds:
      description: Account balance is not enough for this operation (`insufficient_funds`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: insufficient_funds
            message: account balance is not enough for this operation
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: |
        Session JWT (from register/login) or API key (`pk_...`).
        `X-API-Key: <token>` is accepted as an alternative header.

````