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

# Cut a return file now

> Generates the return of one CNAB agreement now, with every journal movement not yet reported, in the order they happened.

<Info>**Providers:** Lerian (PCR).</Info>

<Warning>**Under development.** This endpoint can change before it is released.</Warning>

**How it works**

- The agreement may be `ACTIVE` or `INACTIVE`.
- A new return takes the agreement's next return NSA, with no gaps. The `CNAB_RETURN_AVAILABLE` notice is queued in the same transaction.
- A return file holds at most 49,999 movements in a single batch: the record sequence (G038) has 5 digits, and each movement takes a T and a U segment.
- With more movements, this request generates only the first file, with `moreReturnsInCut` true. The scheduled cut generates the next files in its next cycles, within about a minute. Each has its own consecutive NSA and notice. `GET /v1/cnab/returns` lists them as they are generated.
- With nothing to report, the answer is `204`: no file, no NSA consumed, no notice.
- An on-demand cut within a minute of the agreement's latest on-demand return is refused with `PBP-0914`. A cut answered `204` generates no return and does not count, and scheduled cuts do not count either. Each on-demand return takes an NSA of the agreement's range, which never comes back.
- A retry under the same `Idempotency-Key` replays the first answer (`201` with the same return, or `204`), even if movements arrived since. To cut again, use a new key.
- Scheduled cuts at the agreement's cut times keep running.
- An agreement of another organization gets `404`, the same as one that does not exist.



## OpenAPI

````yaml /en/openapi/v3-current/payments-pcr.yaml post /v1/cnab/returns
openapi: 3.1.0
info:
  title: Payments PCR preview
  version: 2026-11-23-preview
  description: >-
    Preview of Payments with boleto collections through Lerian (PCR), CNAB 240,
    electronic payers (DDA), bill payments, and shared administration. This
    reference includes current behavior and planned changes. Read each
    operation's provider information: some operations support BTG only today.
    The preview is under development and can change before release. Confirm
    availability with Lerian before integration.


    The webhooks section describes notices Payments sends to your callback URL.
    Verify the signature and timestamp before processing a notice. Use the
    eventId and X-Webhook-Id described by each notice to detect repeated
    delivery. Do not assume delivery order.
servers:
  - url: https://api.example.com
    description: >-
      Replace the example host with the URL provided during environment
      onboarding.
security: []
tags:
  - description: >-
      Tenant-level setup: connecting the banking provider and configuring where
      status notifications are delivered.
    name: Admin
  - description: Issuing, querying and cancelling boletos, and retrieving the rendered PDF.
    name: Boletos
  - name: CNAB Agreements
    description: >-
      CNAB agreements: the link between a Lerian-provider collections agreement
      and the CNAB 240 Lerian files of one account, with its remittance and
      return sequence numbers (NSA) and its return cut times. Every operation of
      this section answers 422 PBP-0900 to a tenant without CNAB 240 enabled.
  - name: CNAB Remittances
    description: >-
      CNAB remittances: the CNAB 240 Lerian remittance files of an organization,
      each received whole, validated and stored encrypted, its title lines
      executed afterwards. A file already received is answered with its stored
      receipt; a new one answers 422 PBP-0900 to a tenant without CNAB 240
      enabled.
  - name: CNAB Returns
    description: >-
      CNAB 240 Lerian return files, one per agreement and cut, built from the
      journal of what happened to the titles that entered by remittance, and
      their download. Every operation of this section answers 422 PBP-0900 to a
      tenant without CNAB 240 enabled.
  - description: >-
      Boleto collections agreements and their reconciliation with the
      beneficiary base of the PCR: the consumption of each beneficiary inventory
      the PCR publishes and the divergences it raises, which carry only
      agreement and situation attributes, never a document or a name. Every
      operation of this section answers 422 PBP-0830 to a tenant without
      collections enabled.
    name: Collections Agreements
  - description: >-
      Boleto collections audit trail: every operation and configuration action,
      append-only, with its author, instant, reason, evidence and the module's
      fields before and after it. Every operation of this section answers 422
      PBP-0830 to a tenant without collections enabled.
    name: Collections Audit
  - description: >-
      Boleto collections beneficiaries: the enablement of the tenant's accounts
      for collections, in batches of up to 5,000 accounts, and the progress and
      per-item outcome of the enablement and bulk adoption batches. Every
      operation of this section answers 422 PBP-0830 to a tenant without
      collections enabled.
    name: Collections Beneficiaries
  - name: Collections Credit Entries
    description: >-
      Boleto collections credit entries: what the credit of each write-off moves
      in the ledger, one entry per write-off and phase, the RELEASE to the
      available balance of the title's account and the CHARGEBACK of a write-off
      cancelled after its release, with where each entry stands with the ledger
      and, when it is not posted, why, as a closed code and never the ledger's
      own text. Every operation of this section answers 422 PBP-0830 to a tenant
      without collections enabled.
  - description: >-
      Boleto collections operation queues: each case that waits for an operator
      and already has its state in collections, with its reason, since when it
      waits and the operations that act on it, read over the states collections
      keeps rather than from a list of its own. Each queue counts the items
      whose age reached its age limit, a per-tenant operational parameter. Every
      operation of this section answers 422 PBP-0830 to a tenant without
      collections enabled.
    name: Collections Operation Queues
  - description: >-
      Boleto collections commands to the PCR: each registration, change and
      write-off sent to the PCR of the institution, with the idempotency key it
      keeps across attempts, its attempts, its next attempt and the last answer
      that did not accept it, never the body sent. Every operation of this
      section answers 422 PBP-0830 to a tenant without collections enabled.
    name: Collections PCR Commands
  - description: >-
      Boleto collections notice subscription of the tenant's connection to the
      PCR: its synchronization with the PCR, the rotation of the secret the PCR
      signs the notices with, the deliveries of notices the PCR recorded for it,
      and the redelivery of a notice whose delivery failed. Every operation of
      this section answers 422 PBP-0830 to a tenant without collections enabled.
    name: Collections PCR Connection
  - description: >-
      Boleto collections notices received from the PCR: each event the PCR of
      the institution delivered to collections, stored once per connection and
      event, with where its processing stands and what it was matched with,
      never the body received. Every operation of this section answers 422
      PBP-0830 to a tenant without collections enabled.
    name: Collections PCR Notices
  - description: >-
      Boleto collections pooled accounts: the links of accounts that issue under
      the agreement of a pooled account, whose holder stays the beneficiary
      while the account's holder is the final one. A link registers nothing at
      Núclea. Every operation of this section answers 422 PBP-0830 to a tenant
      without collections enabled.
    name: Collections Pooled Accounts
  - description: >-
      Boleto collections setup: the tenant's business settings, with the default
      agreement template, the automatic enablement and the retention periods,
      and the tenant's connection to the PCR of its institution. Every operation
      of this section answers 422 PBP-0830 to a tenant without collections
      enabled.
    name: Collections Settings
  - description: >-
      Boleto collections titles: each boleto collections issues at the PCR of
      the institution, with its four state axes (registration, situation at the
      base, credit and block), never the data of a payer or of a beneficiary.
      The barcode and the digitable line are answered only while the title is
      REGISTERED. Every operation of this section answers 422 PBP-0830 to a
      tenant without collections enabled.
    name: Collections Titles
  - name: Collections Write-offs
    description: >-
      Boleto collections write-offs: each write-off of a collections title the
      PCR of the institution notified, with its route, its settlement, the state
      of its credit, its hold and its cancellation deadline, never the data of a
      payer. Every operation of this section answers 422 PBP-0830 to a tenant
      without collections enabled.
  - description: >-
      Aggregated counts, amounts and breakdowns over a period, for boletos and
      for payments.
    name: Dashboards
  - name: Electronic payers
    description: >-
      Electronic payer (DDA): adhesion of the institution's customer to
      electronic presentment of boletos, its accounts and aggregates, and the
      outcome of each request. Under development: can change before it is
      released.
  - description: >-
      The notices Payments posts to the tenant's callback URL, one per type
      enabled in enabledEvents, each signed with the configuration's secret.
      Each item describes the body, the delivery headers, when the notice is
      sent and which providers send it. The webhook is the channel of the first
      delivery: delivery will later move to Lerian's Streaming Hub, which will
      then be the only channel, with a change of subscription and a migration
      plan communicated to the client.
    name: Notices
  - description: >-
      Paying bankslips, utility bills and DARF tax slips, and querying those
      payments.
    name: Payments
  - name: Presented boletos
    description: >-
      Boletos of other institutions presented to the electronic payer: list,
      detail, acceptance and authorized third parties. Under development: can
      change before it is released.
paths:
  /v1/cnab/returns:
    post:
      tags:
        - CNAB Returns
      summary: Cut a return file now
      description: >-
        Generates the return of one CNAB agreement now, with every journal
        movement not yet reported, in the order they happened.


        <Info>**Providers:** Lerian (PCR).</Info>


        <Warning>**Under development.** This endpoint can change before it is
        released.</Warning>


        **How it works**


        - The agreement may be `ACTIVE` or `INACTIVE`.

        - A new return takes the agreement's next return NSA, with no gaps. The
        `CNAB_RETURN_AVAILABLE` notice is queued in the same transaction.

        - A return file holds at most 49,999 movements in a single batch: the
        record sequence (G038) has 5 digits, and each movement takes a T and a U
        segment.

        - With more movements, this request generates only the first file, with
        `moreReturnsInCut` true. The scheduled cut generates the next files in
        its next cycles, within about a minute. Each has its own consecutive NSA
        and notice. `GET /v1/cnab/returns` lists them as they are generated.

        - With nothing to report, the answer is `204`: no file, no NSA consumed,
        no notice.

        - An on-demand cut within a minute of the agreement's latest on-demand
        return is refused with `PBP-0914`. A cut answered `204` generates no
        return and does not count, and scheduled cuts do not count either. Each
        on-demand return takes an NSA of the agreement's range, which never
        comes back.

        - A retry under the same `Idempotency-Key` replays the first answer
        (`201` with the same return, or `204`), even if movements arrived since.
        To cut again, use a new key.

        - Scheduled cuts at the agreement's cut times keep running.

        - An agreement of another organization gets `404`, the same as one that
        does not exist.
      operationId: cutCnabReturn
      parameters:
        - description: >-
            Midaz organization the CNAB agreement belongs to. Required: a
            request without it, or with a value that is not a canonical UUID, is
            refused with 400 PBP-0025. An agreement of another organization is
            answered 404, exactly as one that does not exist.
          in: header
          name: X-Organization-Id
          schema:
            description: >-
              Midaz organization the CNAB agreement belongs to. Required: a
              request without it, or with a value that is not a canonical UUID,
              is refused with 400 PBP-0025. An agreement of another organization
              is answered 404, exactly as one that does not exist.
            type: string
        - description: >-
            Client-supplied idempotency key, a UUID. Required: a request without
            it, with a value that is not a UUID, or with the nil UUID is refused
            with 400 PBP-0012. The same key under another organization is
            refused with 422 PBP-0013.
          in: header
          name: Idempotency-Key
          required: true
          schema:
            description: >-
              Client-supplied idempotency key, a UUID. Required: a request
              without it, with a value that is not a UUID, or with the nil UUID
              is refused with 400 PBP-0012. The same key under another
              organization is refused with 422 PBP-0013.
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CutCnabReturnRequest'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CnabReturn'
          description: >-
            Created. The return generated by this cut. With movements for more
            than one file, the first one, with `moreReturnsInCut` true.
        '204':
          description: >-
            No Content. Nothing to report. No file was generated and no NSA was
            consumed.
        '400':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0001:
                  summary: 'PBP-0001: Request does not match the schema'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0001
                    title: Bad Request
                    status: 400
                    detail: validation failed
                    code: PBP-0001
                PBP-0025:
                  summary: 'PBP-0025: Organization header missing'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0025
                    title: Bad Request
                    status: 400
                    detail: >-
                      X-Organization-Id header is required and must be a
                      canonical UUID
                    code: PBP-0025
                PBP-0012:
                  summary: 'PBP-0012: Idempotency-Key missing'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0012
                    title: Bad Request
                    status: 400
                    detail: Idempotency-Key header is required and must be a UUID
                    code: PBP-0012
          description: >-
            Bad Request.


            - `PBP-0001`: the body does not match the schema.

            - `PBP-0025`: `X-Organization-Id` is missing or is not a canonical
            UUID.

            - `PBP-0012`: `Idempotency-Key` is missing or is not a UUID.


            See the [error
            list](/en/reference/interfaces/payments-btg/payments-error-list) for
            every code.
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0003:
                  summary: 'PBP-0003: Invalid credential'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0003
                    title: Unauthorized
                    status: 401
                    detail: authentication required
                    code: PBP-0003
          description: >-
            Unauthorized.


            - `PBP-0003`: the credential is missing or invalid, or does not
            identify a tenant. Get a valid bearer token.
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0004:
                  summary: 'PBP-0004: No permission'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0004
                    title: Forbidden
                    status: 403
                    detail: permission denied
                    code: PBP-0004
          description: >-
            Forbidden.


            - `PBP-0004`: the credential does not have permission for this
            operation.
        '404':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0901:
                  summary: 'PBP-0901: CNAB agreement not found'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0901
                    title: CNAB Agreement Not Found
                    status: 404
                    detail: CNAB Agreement Not Found
                    code: PBP-0901
          description: >-
            Not Found.


            - `PBP-0901`: no CNAB agreement with this id in the organization. An
            agreement of another organization gets the same answer.
        '409':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0913:
                  summary: 'PBP-0913: Cut already running'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0913
                    title: CNAB Return Cut In Progress
                    status: 409
                    detail: CNAB Return Cut In Progress
                    code: PBP-0913
                PBP-0007:
                  summary: 'PBP-0007: Same key still running'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0007
                    title: Conflict
                    status: 409
                    detail: >-
                      a request with this Idempotency-Key is still being
                      processed
                    code: PBP-0007
          description: >-
            Conflict.


            - `PBP-0913`: another cut or a remittance receipt of the same
            agreement is running. Nothing was written. Retry later.

            - `PBP-0007`: an earlier request under the same `Idempotency-Key` is
            still running. Retry under the same key after a short wait. This
            answer lasts at most five minutes after the earlier request arrived.
            After that, the key returns the stored answer, `500` `PBP-0002` when
            it cannot be replayed, or runs the request when no answer was kept.
            Do not switch keys: the earlier request can still take effect.


            See the [error
            list](/en/reference/interfaces/payments-btg/payments-error-list) for
            every code.
        '413':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0010:
                  summary: 'PBP-0010: Body too large'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0010
                    title: Request Entity Too Large
                    status: 413
                    detail: request body too large
                    code: PBP-0010
          description: |-
            Payload Too Large.

            - `PBP-0010`: the body is larger than the size limit.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0900:
                  summary: 'PBP-0900: CNAB 240 not enabled'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0900
                    title: CNAB Not Enabled
                    status: 422
                    detail: CNAB 240 is not enabled for this tenant
                    code: PBP-0900
                    layout: CNAB_240
                PBP-0013:
                  summary: 'PBP-0013: Key used for another request'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0013
                    title: Idempotency Key Conflict
                    status: 422
                    detail: this Idempotency-Key was used for a different request
                    code: PBP-0013
          description: >-
            Unprocessable Entity.


            - `PBP-0900`: CNAB 240 is not enabled for the tenant. On-demand cuts
            are refused while it is off. The `layout` member names the layout
            (`CNAB_240`).

            - `PBP-0013`: the same `Idempotency-Key` was sent with another body
            or under another organization. Send under a new key.


            See the [error
            list](/en/reference/interfaces/payments-btg/payments-error-list) for
            every code.
        '429':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0914:
                  summary: 'PBP-0914: Cut asked too soon'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0914
                    title: CNAB Return Cut Too Soon
                    status: 429
                    detail: CNAB Return Cut Too Soon
                    code: PBP-0914
          description: >-
            Too Many Requests.


            - `PBP-0914`: the agreement's latest on-demand return was generated
            less than a minute ago. Nothing was written and no NSA was consumed.
            Retry after the seconds in `Retry-After`.
          headers:
            Retry-After:
              description: Seconds until the agreement accepts another on-demand cut.
              schema:
                minimum: 1
                type: integer
        '500':
          description: >-
            Internal Server Error.


            - `PBP-0002`: an unexpected failure, or the stored answer of this
            key cannot be replayed. Contact support. Do not resend under a new
            key.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0002:
                  summary: 'PBP-0002: Unexpected failure'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0002
                    title: Internal Server Error
                    status: 500
                    detail: internal error
                    code: PBP-0002
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
              examples:
                PBP-0008:
                  summary: 'PBP-0008: Dependency unavailable'
                  value:
                    type: https://errors.lerian.studio/v1/PBP-0008
                    title: Service Unavailable
                    status: 503
                    detail: internal error
                    code: PBP-0008
          description: >-
            Service Unavailable. Nothing was written. Send the same request
            again under the same `Idempotency-Key`. The `detail` is a fixed
            text.


            - `PBP-0008`: a dependency did not answer: authentication, the
            tenant's database, its CNAB switch, the registration or the CNAB
            file keys. Also returned when the agreement changed while the cut
            was being prepared.
      security:
        - BearerAuth: []
components:
  schemas:
    CutCnabReturnRequest:
      additionalProperties: false
      properties:
        agreementId:
          description: The CNAB agreement to cut.
          examples:
            - 019a7c1e-4b2d-7f30-9c11-2a5e8d0f4b61
          format: uuid
          type: string
      required:
        - agreementId
      type: object
    CnabReturn:
      additionalProperties: false
      properties:
        agreementId:
          description: The CNAB agreement the return belongs to.
          examples:
            - 019a7c1e-4b2d-7f30-9c11-2a5e8d0f4b61
          format: uuid
          type: string
        contentSha256:
          description: >-
            SHA-256 of the file as generated, lowercase hex; a rebuilt file is
            checked against it.
          pattern: ^[0-9a-f]{64}$
          type: string
        filePurged:
          description: >-
            true when the stored file was purged after the retention period; the
            download then rebuilds it from the journal.
          type: boolean
        generatedAt:
          description: When the return was generated, RFC 3339 in UTC.
          format: date-time
          type: string
        id:
          description: Identifier of the return.
          format: uuid
          type: string
        moreReturnsInCut:
          description: >-
            Only in the 201 of cutCnabReturn: true when movements were left
            after this file (more than 49,999 to report); the scheduled cut
            generates the following files in its next cycles, one per
            transaction, each with its own consecutive NSA and notice; list them
            with listCnabReturns. Absent in the other operations.
          type: boolean
        movementCount:
          description: >-
            Movements in the file (one T/U pair each); 1 to 49,999, one batch
            per file (G038).
          format: int64
          maximum: 49999
          minimum: 1
          type: integer
        nsa:
          description: >-
            Return NSA of the agreement (G018 of the return header);
            consecutive, no gaps.
          examples:
            - 42
          format: int64
          maximum: 999999
          minimum: 1
          type: integer
        requestedBy:
          description: >-
            Subject of the JWT that asked for an ON_DEMAND cut; null for
            SCHEDULED.
          maxLength: 255
          type:
            - string
            - 'null'
        sizeBytes:
          description: Size of the file as generated.
          format: int64
          type: integer
        trigger:
          description: >-
            SCHEDULED: cut at one of the agreement's cut times. ON_DEMAND: cut
            by POST /v1/cnab/returns.
          enum:
            - SCHEDULED
            - ON_DEMAND
          type: string
      required:
        - id
        - agreementId
        - nsa
        - trigger
        - movementCount
        - generatedAt
        - contentSha256
        - sizeBytes
        - filePurged
        - requestedBy
      type: object
    Detail:
      additionalProperties: true
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          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
    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: 'Never returned: the service drops the rejected value.'
      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
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http

````

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