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

# Charge the maintenance fee of a period

> Charges the maintenance fee of a period: for each enabled maintenance billing package of the ledger, or the one billingPackageId names (a disabled one is skipped, as billing/calculate skips it, and answers no account), and each active target account, posts one internal fee transaction of feeAmount from the account to maintenanceCreditAccount in the package asset, described "Billing - <label> - <period>" with metadata billingType, billingPackageId and period. When the ledger validates accounting routes the transaction takes the package accounting routes, and a package without them refuses the call (422, 0547) before anything is posted. Each package, account and period is charged at most once: the charge is recorded durably before it posts, an account already posted answers replayed with its transaction and posts nothing, and one another call is posting answers in_flight. A fee transaction the ledger refuses answers refused with its code, for insufficient funds for instance (0018) or an account in another asset, and the other accounts proceed; a later call for the period tries the refused accounts again. With deferrable, the share of the fee the account's available balance cannot fund opens a fee debt of the charge (origin billing_charge with the charge id on GET .../fee-debts; debts opened before name billing_package), settled by the account's later credits, instead of refusing: an account holding nothing opens the whole fee as a debt, posted without a fee transaction and so without transactionId; the overdraft is not drawn. period is YYYY-MM, not later than the current month (UTC) (400, 0082). The call walks the packages by id and, within each, the accounts by id, and visits at most limit accounts (1 to 500, default 100; 0080 above it), replayed ones included. When accounts remain it answers hasMore=true and nextCursor; sending that cursor in the next call resumes after the last account visited, and a call without cursor starts from the first account. A cursor that does not decode is refused (400, 0082). billing/calculate is unaffected and posts nothing. ledgerId in the query or the body is refused with 0235.



## OpenAPI

````yaml /en/openapi/v3-current/ledger.yaml post /v2/organizations/{organization_id}/ledgers/{ledger_id}/billing/charge
openapi: 3.1.0
info:
  contact:
    email: contact@lerian.studio
    name: Lerian Studio
    url: https://lerian.studio
  license:
    name: Lerian Studio General License
  title: Midaz Ledger API
  version: 4.0.0
servers:
  - url: https://ledger.sandbox.lerian.net
security: []
tags:
  - name: Account Block Exceptions (v2)
  - name: Account Plan Assignments (v2)
  - name: Account Plans (v2)
  - name: Account Types (v1)
  - name: Account Types (v2)
  - name: Accounts (v1)
  - name: Accounts (v2)
  - name: Asset Rates (v1)
  - name: Assets (v1)
  - name: Assets (v2)
  - name: Balances (v1)
  - name: Balances (v2)
  - name: Billing Calculate (v2)
  - name: Billing Charge (v2)
  - name: Billing Packages (v2)
  - name: Composition (v2)
  - name: Dashboard (v1)
  - name: Dashboard (v2)
  - name: Encryption (v2)
  - name: Fee Charges (v2)
  - name: Fee Debts (v2)
  - name: Fees (v2)
  - name: Holders (v2)
  - name: Instruments (v2)
  - name: Ledgers (v1)
  - name: Ledgers (v2)
  - name: Metadata Indexes (v1)
  - name: Metadata Indexes (v2)
  - name: Operation Routes (v1)
  - name: Operation Routes (v2)
  - name: Operations (v1)
  - name: Operations (v2)
  - name: Organizations (v1)
  - name: Organizations (v2)
  - name: Packages (v2)
  - name: Portfolios (v1)
  - name: Portfolios (v2)
  - name: Protection (v2)
  - name: Segments (v1)
  - name: Segments (v2)
  - name: Transaction Routes (v1)
  - name: Transaction Routes (v2)
  - name: Transactions (v1)
  - name: Transactions (v2)
paths:
  /v2/organizations/{organization_id}/ledgers/{ledger_id}/billing/charge:
    post:
      tags:
        - Billing Charge (v2)
      summary: Charge the maintenance fee of a period
      description: >-
        Charges the maintenance fee of a period: for each enabled maintenance
        billing package of the ledger, or the one billingPackageId names (a
        disabled one is skipped, as billing/calculate skips it, and answers no
        account), and each active target account, posts one internal fee
        transaction of feeAmount from the account to maintenanceCreditAccount in
        the package asset, described "Billing - <label> - <period>" with
        metadata billingType, billingPackageId and period. When the ledger
        validates accounting routes the transaction takes the package accounting
        routes, and a package without them refuses the call (422, 0547) before
        anything is posted. Each package, account and period is charged at most
        once: the charge is recorded durably before it posts, an account already
        posted answers replayed with its transaction and posts nothing, and one
        another call is posting answers in_flight. A fee transaction the ledger
        refuses answers refused with its code, for insufficient funds for
        instance (0018) or an account in another asset, and the other accounts
        proceed; a later call for the period tries the refused accounts again.
        With deferrable, the share of the fee the account's available balance
        cannot fund opens a fee debt of the charge (origin billing_charge with
        the charge id on GET .../fee-debts; debts opened before name
        billing_package), settled by the account's later credits, instead of
        refusing: an account holding nothing opens the whole fee as a debt,
        posted without a fee transaction and so without transactionId; the
        overdraft is not drawn. period is YYYY-MM, not later than the current
        month (UTC) (400, 0082). The call walks the packages by id and, within
        each, the accounts by id, and visits at most limit accounts (1 to 500,
        default 100; 0080 above it), replayed ones included. When accounts
        remain it answers hasMore=true and nextCursor; sending that cursor in
        the next call resumes after the last account visited, and a call without
        cursor starts from the first account. A cursor that does not decode is
        refused (400, 0082). billing/calculate is unaffected and posts nothing.
        ledgerId in the query or the body is refused with 0235.
      operationId: chargeBillingV2
      parameters:
        - description: Organization ID (UUID)
          in: path
          name: organization_id
          required: true
          schema:
            description: Organization ID (UUID)
            type: string
        - description: Ledger ID (UUID)
          in: path
          name: ledger_id
          required: true
          schema:
            description: Ledger ID (UUID)
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FeeChargeBillingInput'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeeBillingChargeResult'
          description: OK
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Unprocessable Entity
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Error
      security:
        - BearerAuth: []
components:
  schemas:
    FeeChargeBillingInput:
      additionalProperties: false
      properties:
        billingPackageId:
          description: >-
            Maintenance package to charge; a disabled one is skipped and answers
            no account. Absent charges every enabled maintenance package of the
            ledger.
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        cursor:
          description: >-
            nextCursor of the previous call: the call resumes after the last
            account that call visited. Absent starts from the first account. The
            walk takes the packages by id and, within each, the accounts by id.
          examples:
            - eyJpZCI6ImNoYXJnZTouLi4ifQ==
          type: string
        limit:
          description: >-
            Most accounts this call visits, 1 to 500; defaults to 100. Every
            visited account counts, replayed ones included.
          examples:
            - 100
          format: int64
          type: integer
        period:
          description: Period to charge, YYYY-MM, not later than the current month (UTC).
          examples:
            - 2026-11
          type: string
      type: object
      required:
        - period
    FeeBillingChargeResult:
      additionalProperties: false
      properties:
        hasMore:
          description: Whether target accounts remain after the last one this call visited.
          examples:
            - false
          type: boolean
        items:
          description: >-
            One item per active target account the call visited, by package and
            account id.
          items:
            $ref: '#/components/schemas/FeeBillingChargeItem'
          type:
            - array
            - 'null'
        nextCursor:
          description: >-
            Cursor to send in the next call to resume after the last account
            visited; present only when hasMore is true.
          examples:
            - eyJpZCI6ImNoYXJnZTouLi4ifQ==
          type: string
        period:
          examples:
            - 2026-11
          type: string
      required:
        - period
        - items
        - hasMore
      type: object
    Error:
      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
    FeeBillingChargeItem:
      additionalProperties: false
      properties:
        accountAlias:
          examples:
            - '@cliente_x'
          type: string
        accountId:
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        amount:
          examples:
            - '50'
          type: string
        assetCode:
          examples:
            - BRL
          type: string
        billingPackageId:
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        code:
          description: Error code of a refused charge.
          examples:
            - '0018'
          type: string
        status:
          description: >-
            posted: this call posted the fee transaction. replayed: an earlier
            call posted it, nothing new is posted. refused: the fee transaction
            was refused with code; a later call tries it again. in_flight:
            another call holds the account.
          enum:
            - posted
            - replayed
            - refused
            - in_flight
          examples:
            - posted
          type: string
        transactionId:
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
      required:
        - billingPackageId
        - accountId
        - accountAlias
        - status
        - amount
        - assetCode
      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
  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.