> ## 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 service fees to an account

> Charges service fees of the account plan of the account. Each occurrence of a code in serviceCodes is one unit. Units inside the free quota of their fee come out as quota and cost nothing; units past it come out as charged at the fee's flat amount. Codes the account's plan does not declare, and every code of an account without a plan, come out as not_covered and consume nothing. All charged units post in a single fee transaction in the account's asset, debiting the account and crediting each fee's creditAccount, on the fees' transaction route when the ledger validates accounting routes; neither account plans nor fee packages apply to it. When no unit is charged the charge is recorded without a transaction. The X-Idempotency header is required (400, 0552); a retry with the same key and body returns the recorded charge with X-Idempotency-Replayed and charges nothing again. A code no fee of the ledger declares is refused (422, 0549), as is a code only transaction fees declare (422, 0550) and codes whose fees have different transaction routes (422, 0551). When the fee transaction is refused, for insufficient funds for instance, the charge is refused with the same error and nothing is consumed. ledgerId in the query or the body is refused with 0235.



## OpenAPI

````yaml /pt/openapi/v3-current/ledger.yaml post /v2/organizations/{organization_id}/ledgers/{ledger_id}/accounts/{account_id}/fee-charges
openapi: 3.1.0
info:
  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 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}/accounts/{account_id}/fee-charges:
    post:
      tags:
        - Fee Charges (v2)
      summary: Charge service fees to an account
      description: >-
        Charges service fees of the account plan of the account. Each occurrence
        of a code in serviceCodes is one unit. Units inside the free quota of
        their fee come out as quota and cost nothing; units past it come out as
        charged at the fee's flat amount. Codes the account's plan does not
        declare, and every code of an account without a plan, come out as
        not_covered and consume nothing. All charged units post in a single fee
        transaction in the account's asset, debiting the account and crediting
        each fee's creditAccount, on the fees' transaction route when the ledger
        validates accounting routes; neither account plans nor fee packages
        apply to it. When no unit is charged the charge is recorded without a
        transaction. The X-Idempotency header is required (400, 0552); a retry
        with the same key and body returns the recorded charge with
        X-Idempotency-Replayed and charges nothing again. A code no fee of the
        ledger declares is refused (422, 0549), as is a code only transaction
        fees declare (422, 0550) and codes whose fees have different transaction
        routes (422, 0551). When the fee transaction is refused, for
        insufficient funds for instance, the charge is refused with the same
        error and nothing is consumed. ledgerId in the query or the body is
        refused with 0235.
      operationId: chargeServiceFeesV2
      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
        - description: Account ID (UUID)
          in: path
          name: account_id
          required: true
          schema:
            description: Account ID (UUID)
            type: string
        - description: >-
            Required. Idempotency key of the charge, unique per account: a retry
            with the same key and body returns the recorded charge with
            X-Idempotency-Replayed, a different body under the same key answers
            409 (0084).
          in: header
          name: X-Idempotency
          schema:
            description: >-
              Required. Idempotency key of the charge, unique per account: a
              retry with the same key and body returns the recorded charge with
              X-Idempotency-Replayed, a different body under the same key
              answers 409 (0084).
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FeeChargeServiceFeesInput'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeeCharge'
          description: Created
          headers:
            X-Idempotency-Replayed:
              schema:
                type: string
        '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:
    FeeChargeServiceFeesInput:
      additionalProperties: false
      properties:
        description:
          description: >-
            Description of the charge, also used as the description of the fee
            transaction.
          examples:
            - Tarifas de serviço de outubro
          maxLength: 256
          type: string
        metadata:
          additionalProperties: {}
          description: Flat metadata of the charge, also written to the fee transaction.
          type: object
        serviceCodes:
          description: >-
            Service codes to charge, 1 to 100. Each occurrence is one unit;
            codes are normalized to trimmed upper case.
          examples:
            - - PAPER_STATEMENT
              - CARD_REISSUE
          items:
            type: string
          maxItems: 100
          minItems: 1
          type:
            - array
            - 'null'
      required:
        - serviceCodes
      type: object
    FeeCharge:
      additionalProperties: false
      properties:
        accountId:
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        accountPlanId:
          description: >-
            Account plan active for the account when the charge was taken; null
            when the account had none.
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        accountPlanVersion:
          description: >-
            Version of the account plan in effect when the charge was taken; 0
            when the account had no plan.
          examples:
            - 1
          format: int64
          type: integer
        assetCode:
          description: Asset of the account the charge was taken in.
          examples:
            - BRL
          type: string
        createdAt:
          examples:
            - '2026-10-22T12:00:00Z'
          format: date-time
          type: string
        description:
          examples:
            - Tarifas de serviço de outubro
          type: string
        feeTransactionIds:
          description: >-
            Fee transactions that charged the charged items; empty when nothing
            was charged.
          items:
            type: string
          type:
            - array
            - 'null'
        id:
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        items:
          description: One item per service code of the request, in request order.
          items:
            $ref: '#/components/schemas/FeeChargeItem'
          type:
            - array
            - 'null'
        ledgerId:
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        metadata:
          additionalProperties: {}
          type: object
        organizationId:
          examples:
            - 00000000-0000-0000-0000-000000000000
          type: string
        period:
          description: >-
            Monthly quota period (YYYY-MM) the units were counted in, in the
            plan timezone.
          examples:
            - 2026-10
          type: string
        totalAmount:
          description: Sum of the amounts of the charged items.
          examples:
            - '15'
          type: string
      required:
        - id
        - organizationId
        - ledgerId
        - accountId
        - accountPlanId
        - accountPlanVersion
        - items
        - totalAmount
        - assetCode
        - feeTransactionIds
        - period
        - createdAt
      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
    FeeChargeItem:
      additionalProperties: false
      properties:
        amount:
          description: Fee charged for the unit; 0 unless outcome is charged.
          examples:
            - '3'
          type: string
        feeKey:
          description: >-
            Key of the account plan fee the code matched; empty when outcome is
            not_covered.
          examples:
            - extratoImpresso
          type: string
        freeQuota:
          description: >-
            Free units per period of the matched fee; 0 when outcome is
            not_covered.
          examples:
            - 2
          format: int64
          type: integer
        outcome:
          enum:
            - quota
            - charged
            - not_covered
          examples:
            - charged
          type: string
        serviceCode:
          description: Service code of the unit, normalized to trimmed upper case.
          examples:
            - PAPER_STATEMENT
          type: string
        unit:
          description: >-
            Ordinal of the consumed unit in the period; 0 when outcome is
            not_covered.
          examples:
            - 3
          format: int64
          type: integer
      required:
        - serviceCode
        - feeKey
        - outcome
        - unit
        - freeQuota
        - amount
      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.