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

# Calculate Fees for a Package

> Use this endpoint to calculate and retrieve the fees associated with a specific package for a given transaction.



## OpenAPI

````yaml /en/openapi/v3-current/fees-engine.yaml post /v1/fees
openapi: 3.1.0
info:
  title: Fees Engine
  description: ''
  version: 3.2.0
servers:
  - url: https://fees.sandbox.lerian.net
security: []
tags:
  - name: Fees Engine
paths:
  /v1/fees:
    post:
      tags:
        - Calculation API
      summary: Calculate Fees for a Package
      description: >-
        Use this endpoint to calculate and retrieve the fees associated with a
        specific package for a given transaction.
      parameters:
        - $ref: '#/components/parameters/Authorization'
        - $ref: '#/components/parameters/ContentType'
        - $ref: '#/components/parameters/XOrganizationId'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCalculationRequest'
            example:
              segmentId: 019c96a0-0b4e-7079-8be0-ab6bdccf975f
              ledgerId: 019c96a0-0ac0-7de9-9f53-9cf842a2ee5a
              transaction:
                route: 019c96a0-10a0-72d2-9fb0-2b7de8093182
                description: Fee test
                pending: false
                send:
                  asset: BRL
                  value: '4000.00'
                  source:
                    from:
                      - accountAlias: customer-brl-1
                        share:
                          percentage: '15'
                      - accountAlias: customer-brl-2
                        share:
                          percentage: '35'
                      - accountAlias: customer-brl-3
                        share:
                          percentage: '40'
                      - accountAlias: customer-brl-4
                        share:
                          percentage: '10'
                  distribute:
                    to:
                      - accountAlias: business-brl-1
                        share:
                          percentage: '25'
                      - accountAlias: business-brl-2
                        share:
                          percentage: '25'
                      - accountAlias: business-brl-3
                        share:
                          percentage: '25'
                      - accountAlias: business-brl-4
                        share:
                          percentage: '25'
      responses:
        '200':
          description: >-
            Indicates that the resource was successfully created and the
            operation was completed as expected.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CalculateResponse'
              examples:
                fullCalculation:
                  summary: Full calculation with fees
                  value:
                    segmentId: 019c96a0-0b4e-7079-8be0-ab6bdccf975f
                    ledgerId: 019c96a0-0ac0-7de9-9f53-9cf842a2ee5a
                    transaction:
                      route: 019c96a0-10a0-72d2-9fb0-2b7de8093182
                      pending: false
                      description: Fee Example
                      metadata:
                        packageAppliedID: 01962565-8d57-737b-abfa-84c3a15eeb15
                      send:
                        asset: BRL
                        value: '4175.00'
                        source:
                          from:
                            - accountAlias: customer-brl-1
                              amount:
                                asset: BRL
                                value: '1000.00'
                              route: pixdebit
                              metadata: null
                            - accountAlias: customer-brl-2
                              amount:
                                asset: BRL
                                value: '1000.00'
                              route: pixdebit
                              metadata: null
                            - accountAlias: customer-brl-3
                              amount:
                                asset: BRL
                                value: '1000.00'
                              route: pixdebit
                              metadata: null
                            - accountAlias: customer-brl-4
                              amount:
                                asset: BRL
                                value: '1175.00'
                              route: pixdebit
                              metadata: null
                        distribute:
                          to:
                            - accountAlias: business-brl-1
                              amount:
                                asset: BRL
                                value: '4175.00'
                              route: pixcredit
                              metadata: null
          headers: {}
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0001:
                  $ref: '#/components/examples/Error0001'
                Error0002:
                  $ref: '#/components/examples/Error0002'
                Error0003:
                  $ref: '#/components/examples/Error0003'
                Error0012:
                  $ref: '#/components/examples/Error0012'
                Error0020:
                  $ref: '#/components/examples/Error0020'
                Error0022:
                  $ref: '#/components/examples/Error0022'
                Error0037:
                  $ref: '#/components/examples/Error0037'
                Error0041:
                  $ref: '#/components/examples/Error0041'
          headers: {}
        '500':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0004:
                  $ref: '#/components/examples/Error0004'
          headers: {}
        '503':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0021:
                  $ref: '#/components/examples/Error0021'
          headers: {}
      security: []
components:
  parameters:
    Authorization:
      name: Authorization
      in: header
      description: >-
        The authorization token in the 'Bearer <token>' format.  


        **Important:** This header is required if your environment has Access
        Manager enabled. For more information, refer to the [Access
        Manager](/en/access-manager) documentation.
      required: false
      schema:
        type: string
    ContentType:
      name: Content-Type
      in: header
      description: The type of media of the resource. Must be `application/json`.
      required: true
      schema:
        type: string
        example: application/json
    XOrganizationId:
      name: X-Organization-Id
      in: header
      description: The unique identifier of the Organization associated with the request.
      required: true
      schema:
        type: string
        example: 019c96a0-0a98-7287-9a31-786e0809c769
  schemas:
    CreateCalculationRequest:
      type: object
      properties:
        segmentId:
          type: string
          description: >-
            Unique identifier of the Segment this Fee Package is linked to in
            the Midaz Ledger.
        ledgerId:
          type: string
          description: >-
            Unique identifier of the Ledger this Fee Package is linked to in the
            Midaz Ledger.
        transaction:
          $ref: '#/components/schemas/Transactions'
      required:
        - ledgerId
        - transaction
    CalculateResponse:
      type: object
      description: >-
        Result of the fee calculation. Contains the Ledger and Segment
        identifiers together with the transaction payload enriched with the
        calculated fees.
      properties:
        segmentId:
          type: string
          description: >-
            Unique identifier of the Segment this Fee Package is linked to in
            the Midaz Ledger.
        ledgerId:
          type: string
          description: >-
            Unique identifier of the Ledger this Fee Package is linked to in the
            Midaz Ledger.
        transaction:
          $ref: '#/components/schemas/Transactions'
      required:
        - ledgerId
        - transaction
    Error:
      type: object
      properties:
        code:
          type: string
          description: A unique, stable identifier for the error.
        title:
          type: string
          description: A brief summary of the issue.
        message:
          type: string
          description: Detailed guidance for resolving the error.
      required:
        - code
        - title
        - message
      description: The response message error.
    Transactions:
      type: object
      description: Information about the transaction to which the fee applies.
      properties:
        chartOfAccountsGroupName:
          type: string
          description: >-
            The chart of accounts group name which categorizes this transaction
            under a specific group.
        route:
          type: string
          description: >-
            The main accounting route of the transaction, representing the
            nature and general purpose of the transactional event. Used to
            categorize and group related operations in the general ledger. Same
            information as the `transactionRoute` field in the package.
        transactionRoute:
          type: string
          description: >-
            Alternative field for `route`. The main accounting route of the
            transaction. Either `route` or `transactionRoute` can be used.
        pending:
          type: boolean
          description: Indicates if the transaction is pending.
        description:
          type: string
          description: A description for the transaction.
        metadata:
          type: object
          description: >-
            An object containing key-value pairs to add as metadata, where the
            field `name` is the key and the field `value` is the value. For
            example, to add a Cost Center, use `costCenter: BR_11101997`.
          additionalProperties:
            type: string
        send:
          type: object
          description: Information about the transaction that will be sent.
          properties:
            asset:
              type: string
              description: The code that identifies the asset that will be sent.
            value:
              type: string
              description: >-
                The amount that will be sent. **Important:** Use a dot (`.`) as
                the decimal separator — commas are not accepted.
            source:
              type: object
              properties:
                from:
                  type: array
                  items:
                    $ref: '#/components/schemas/Operations'
                remaining:
                  type: string
                  description: >-
                    The remaining amount or percentage that will be distributed
                    among the source accounts. **Important:** Use a dot (`.`) as
                    the decimal separator — commas are not accepted.
              description: >-
                The list of accounts that will be used as source (DEBIT
                operations).
              required:
                - from
            distribute:
              type: object
              properties:
                to:
                  type: array
                  items:
                    $ref: '#/components/schemas/Operations'
                remaining:
                  type: string
                  description: >-
                    The remaining amount or percentage that will be distributed
                    among the destination accounts. **Important:** Use a dot
                    (`.`) as the decimal separator — commas are not accepted.
              description: A list of the accounts to which the amount will be transferred.
              required:
                - to
          required:
            - asset
            - value
            - source
            - distribute
      required:
        - route
        - send
    Operations:
      type: object
      properties:
        accountAlias:
          type: string
          description: The alias of the account used in the operation.
        amount:
          type: object
          properties:
            asset:
              type: string
              description: The name of the asset used in the operation.
            value:
              type: string
              description: >-
                The amount that will be sent. **Important:** Use a dot (`.`) as
                the decimal separator — commas are not accepted.
          required:
            - asset
            - value
          description: Information about the amount that will be used in the operation.
        share:
          type: object
          properties:
            percentage:
              type: string
              description: The percentage that will be shared.
            percentageOfPercentage:
              type: string
              description: The percentage of the percentage that will be shared.
            route:
              type: string
              description: >-
                The main accounting route that defines the nature of the
                transaction. Helps group related operations in the ledger.
            metadata:
              type: object
              description: >-
                An object containing key-value pairs to add as metadata, where
                the field `name` is the key and the field `value` is the value.
                For example, to add a Cost Center, use `costCenter:
                BR_11101997`.
              additionalProperties:
                type: string
          description: >-
            If different accounts are part of the operation, this object will
            contain the information about the percentage used for each account.
          required: null
        remaining:
          type: string
          description: >-
            The remaining amount or percentage that will be sent to an account.
            **Important:** Use a dot (`.`) as the decimal separator — commas are
            not accepted.
        rate:
          type: object
          description: >-
            Rate information for the operation (used for currency conversions or
            rate-based operations).
        description:
          type: string
          description: A description for the operation.
        route:
          type: string
          description: >-
            The main accounting route that defines the nature of the
            transaction. Helps group related operations in the ledger.
        metadata:
          type: object
          description: >-
            An object containing key-value pairs to add as metadata, where the
            field `name` is the key and the field `value` is the value. For
            example, to add a Cost Center, use `costCenter: BR_11101997`.
          additionalProperties:
            type: string
      required:
        - accountAlias
  examples:
    Error0001:
      summary: Unexpected fields in the request
      value:
        code: FEE-0001
        title: Unexpected fields in the request
        message: >-
          The request body contains more fields than expected. Please send only
          the allowed fields as per the documentation. The unexpected fields are
          listed in the fields object.
    Error0002:
      summary: Missing fields in request
      value:
        code: FEE-0002
        title: Missing fields in request
        message: >-
          Your request is missing one or more required fields. Please refer to
          the documentation to ensure all necessary fields are included in your
          request.
    Error0003:
      summary: Bad request
      value:
        code: FEE-0003
        title: Bad request
        message: >-
          The server could not understand the request due to malformed syntax.
          Please check the listed fields and try again.
    Error0012:
      summary: Entity not found
      value:
        code: FEE-0012
        title: Entity not found
        message: >-
          No entity was found for the given ID. Please make sure to use the
          correct ID for the entity you are trying to manage.
    Error0020:
      summary: Missing header
      value:
        code: FEE-0020
        title: Missing header
        message: >-
          Headers parameters is required. Please check the following header
          parameters %v and ensure they are passing the values correctly.
    Error0022:
      summary: Failed to calculate fee
      value:
        code: FEE-0022
        title: Failed to calculate fee
        message: Error to make the calculation of a fee about a transaction.
    Error0037:
      summary: Error to distribute values
      value:
        code: FEE-0037
        title: Error to distribute values
        message: >-
          Error to try distribute the values of send object. Please check the
          data passed.
    Error0041:
      summary: Unmarshalling error
      value:
        code: FEE-0041
        title: Unmarshalling error
        message: 'Invalid value for field ''%s'': expected type ''%s'', but got ''%s''.'
    Error0004:
      summary: Internal Server Error
      value:
        code: FEE-0004
        title: Internal Server Error
        message: >-
          The server encountered an unexpected error. Please try again later or
          contact support.
    Error0021:
      summary: Invalid transaction type
      value:
        code: FEE-0021
        title: Invalid transaction type
        message: >-
          Only one transaction type ('amount', 'share', or 'remaining') must be
          specified in the '%v' field for each entry. Please review your input
          and try again.

````