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

# Create an outbound Pix refund (MED)

> Issues a refund against a previously completed CASHIN transfer with a structured pacs.004 reasonCode.



## OpenAPI

````yaml /es/openapi/v3-current/pix-lerian-spi.yaml post /transfers/{id}/refunds
openapi: 3.1.0
info:
  contact:
    name: Lerian Studio
    url: https://lerian.studio
  description: >-
    Public API for outbound Pix transfers, refunds, and scheduled payments. This
    release provides a mock-provider integration for testing; live BACEN
    connectivity is not included.
  license:
    name: Lerian Studio General License
  title: Pix Lerian — Payments
  version: 1.0.0
servers:
  - url: https://api.example.com/spi/v1
    description: >-
      Replace the example host with the URL provided during environment
      onboarding.
security:
  - BearerAuth: []
tags:
  - description: Create, list, and retrieve Pix refunds.
    name: Refunds
  - name: Scheduled Payments
    description: Register, list, retrieve, and cancel scheduled Pix payments.
  - description: Initiate, process, list, and retrieve outbound Pix transfers.
    name: Transfers
paths:
  /transfers/{id}/refunds:
    post:
      tags:
        - Refunds
      summary: Create an outbound Pix refund (MED)
      description: >-
        Issues a refund against a previously completed CASHIN transfer with a
        structured pacs.004 reasonCode.
      operationId: createRefund
      parameters:
        - description: >-
            REQUIRED. Client-supplied replay key, at most 64 bytes. A request
            without it is refused with PIX-0030 @ 400 before the handler runs.
            Replaying the same key with a divergent method, URL or body is
            PIX-0031 @ 412.
          in: header
          name: X-Idempotency
          required: true
          schema:
            maxLength: 64
            minLength: 1
            type: string
        - description: Account UUID
          in: header
          name: X-Account-Id
          required: true
          schema:
            description: Account UUID
            examples:
              - 019606a1-3b4c-7d8e-9f01-234567890abc
            type: string
        - description: Original transfer UUID
          in: path
          name: id
          required: true
          schema:
            description: Original transfer UUID
            examples:
              - 0196070b-1234-7890-abcd-ef0123456789
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRefundBody'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RefundCashoutOutput'
          description: Created
        '400':
          content:
            application/json:
              example:
                code: PIX-0030
                title: Idempotency Key Required
                message: >-
                  The Idempotency-Key header is required for this operation and
                  must be within the accepted length.
              schema:
                $ref: '#/components/schemas/LegacyErrorEnvelope'
            application/problem+json:
              example:
                type: https://errors.lerian.studio/v1/PIX-0403
                title: Bad Request
                status: 400
                detail: Missing or malformed required fields for refund.
                code: PIX-0403
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            Missing, duplicated, or malformed request headers/path/body fields,
            an invalid amount/reason, or another invalid refund input
            (PIX-0001-0003, PIX-0010, PIX-0015, PIX-0017, PIX-0403).
            X-Idempotency absent or longer than 64 bytes (PIX-0030). Legacy
            {code,title,message} envelope, NOT problem+json.
        '404':
          content:
            application/problem+json:
              example:
                type: https://errors.lerian.studio/v1/PIX-0400
                title: Not Found
                status: 404
                detail: Original transfer does not exist.
                code: PIX-0400
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            The original transfer does not exist in the calling account scope
            (PIX-0400).
        '409':
          content:
            application/problem+json:
              example:
                type: https://errors.lerian.studio/v1/PIX-0406
                title: Conflict
                status: 409
                detail: The refund changed during this request. Retry the operation.
                code: PIX-0406
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            A concurrent refund update won the race, or the operation reached
            another conflicting state (PIX-0406, PIX-0704).
        '412':
          content:
            application/json:
              example:
                code: PIX-0031
                title: Idempotency Key Conflict
                message: The Idempotency-Key was already used with a different request.
              schema:
                $ref: '#/components/schemas/LegacyErrorEnvelope'
          description: >-
            X-Idempotency replayed with a divergent request -- a different
            method, URL (including the path parameter) or body (PIX-0031).
            Legacy {code,title,message} envelope, NOT problem+json.
        '415':
          content:
            application/problem+json:
              example:
                type: https://errors.lerian.studio/v1/PIX-0016
                title: Unsupported Media Type
                status: 415
                detail: >-
                  The request body must be sent with Content-Type:
                  application/json.
                code: PIX-0016
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            The non-empty request body is missing an accepted JSON Content-Type
            (PIX-0016).
        '422':
          content:
            application/problem+json:
              example:
                type: https://errors.lerian.studio/v1/PIX-0401
                title: Unprocessable Entity
                status: 422
                detail: Original transfer is not in COMPLETED status.
                code: PIX-0401
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            The original transfer is not completed, the refund exceeds the
            remaining amount, or the ledger account/balance cannot be used
            (PIX-0401, PIX-0402, PIX-0328, PIX-0329).
        '500':
          content:
            application/problem+json:
              example:
                type: https://errors.lerian.studio/v1/PIX-0000
                title: Internal Server Error
                status: 500
                detail: >-
                  The server could not complete the request. Please try again
                  later.
                code: PIX-0000
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unexpected server error (PIX-0000).
        '502':
          content:
            application/problem+json:
              example:
                type: https://errors.lerian.studio/v1/PIX-0404
                title: Bad Gateway
                status: 502
                detail: >-
                  The server could not complete the request. Please try again
                  later.
                code: PIX-0404
              schema:
                $ref: '#/components/schemas/Detail'
          description: A required upstream service failed (PIX-0404, PIX-0405, PIX-0705).
        '503':
          content:
            application/json:
              example:
                code: PIX-0032
                title: Idempotency Unavailable
                message: >-
                  The request was not processed because the idempotency store is
                  unavailable. Please retry.
              schema:
                $ref: '#/components/schemas/LegacyErrorEnvelope'
          description: >-
            Replay cache unavailable on this fail-closed route, so the mutation
            was refused rather than executed without replay protection
            (PIX-0032). Legacy {code,title,message} envelope, NOT problem+json.
        default:
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Error
components:
  schemas:
    CreateRefundBody:
      additionalProperties: false
      properties:
        amount:
          description: Refund amount
          examples:
            - '100.00'
          type: string
        reason:
          description: Human-readable refund reason
          examples:
            - Estorno solicitado pelo pagador
          type: string
        reasonCode:
          description: pacs.004 RtrRsnInf reason code
          examples:
            - MD06
          type: string
      required:
        - amount
        - reasonCode
        - reason
      type: object
    RefundCashoutOutput:
      additionalProperties: false
      properties:
        accountId:
          examples:
            - 019606a0-1a2b-7c3d-8e4f-567890123abc
          type: string
        amount:
          examples:
            - '100.00'
          type: string
        createdAt:
          examples:
            - '2026-05-06T10:45:00Z'
          format: date-time
          type: string
        deletedAt:
          format: date-time
          type: string
        description:
          examples:
            - Estorno solicitado pelo pagador
          type: string
        id:
          examples:
            - 019606b1-3b4c-7d8e-9f01-234567890dee
          type: string
        ledger:
          $ref: '#/components/schemas/LedgerInfo'
        metadata:
          additionalProperties: {}
          type: object
        originalEndToEndId:
          examples:
            - E12345678202605061030abcdef12345
          type: string
        reasonCode:
          examples:
            - MD06
          type: string
        returnEndToEndId:
          examples:
            - D12345678202605061045fedcba54321
          type: string
        status:
          examples:
            - COMPLETED
          type: string
        type:
          examples:
            - OUTBOUND
          type: string
        updatedAt:
          examples:
            - '2026-05-06T10:45:30Z'
          format: date-time
          type: string
      required:
        - id
        - originalEndToEndId
        - status
        - type
        - amount
        - reasonCode
        - createdAt
        - updatedAt
      type: object
    LegacyErrorEnvelope:
      additionalProperties: false
      properties:
        code:
          description: PIX-XXXX error code
          type: string
        message:
          description: Human-readable error message
          type: string
        title:
          description: Short error title
          type: string
      required:
        - code
        - title
        - message
      type: object
    Detail:
      additionalProperties: false
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          examples:
            - ERR-0001
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
        upstream:
          $ref: '#/components/schemas/Upstream'
          description: >-
            RFC 9457 extension member: the error a proxied third-party provider
            reported. Absent unless the emitting service explicitly surfaced
            one.
      type: object
    LedgerInfo:
      additionalProperties: false
      properties:
        destinationOperationId:
          examples:
            - 019606a5-7f80-7182-3c4d-56789012cdf1
          type: string
        revert:
          $ref: '#/components/schemas/LedgerRevertInfo'
        sourceOperationId:
          examples:
            - 019606a5-7f80-7182-3c4d-56789012cdf0
          type: string
        transactionId:
          examples:
            - 019606a5-7f80-7182-3c4d-56789012cdef
          type: string
      type: object
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
    Upstream:
      additionalProperties: false
      properties:
        code:
          description: The upstream provider's own error code, verbatim.
          examples:
            - E4001
          type: string
        message:
          description: >-
            The upstream provider's own error message, verbatim (bounded, never
            its raw response body).
          examples:
            - account not found at provider
          type: string
      type: object
    LedgerRevertInfo:
      additionalProperties: false
      properties:
        destinationOperationId:
          examples:
            - 019606a5-7f80-7182-3c4d-56789012cdf1
          type: string
        sourceOperationId:
          examples:
            - 019606a5-7f80-7182-3c4d-56789012cdf0
          type: string
        transactionId:
          examples:
            - 019606a5-7f80-7182-3c4d-56789012cdef
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http

````