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

> Calculate billing charges for a given period. Evaluates all active billing packages matching the specified type and returns transaction payloads ready for Midaz. All-or-nothing — if any package fails, no results are returned.



## OpenAPI

````yaml /en/openapi/v3-current/fees-engine.yaml post /v1/billing/calculate
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/billing/calculate:
    post:
      tags:
        - Billing Calculation API
      summary: Calculate Billing
      description: >-
        Calculate billing charges for a given period. Evaluates all active
        billing packages matching the specified type and returns transaction
        payloads ready for Midaz. All-or-nothing — if any package fails, no
        results are returned.
      parameters:
        - $ref: '#/components/parameters/XOrganizationId'
        - $ref: '#/components/parameters/Authorization'
        - $ref: '#/components/parameters/ContentType'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CalculateBillingRequest'
            examples:
              volumeMonthly:
                summary: Monthly volume billing
                value:
                  ledgerId: ldg_01HZ...
                  period: 2026-03
                  type: volume
              maintenanceWeekly:
                summary: Weekly maintenance billing
                value:
                  ledgerId: ldg_01HZ...
                  period: 2026-W13
                  type: maintenance
              bothTypes:
                summary: Calculate all billing types
                value:
                  ledgerId: ldg_01HZ...
                  period: 2026-03
      responses:
        '200':
          description: Billing calculation results with transaction payloads.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CalculateBillingResponse'
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0019:
                  $ref: '#/components/examples/Error0019'
                Error0020:
                  $ref: '#/components/examples/Error0020'
                Error0041:
                  $ref: '#/components/examples/Error0041'
                Error0053:
                  $ref: '#/components/examples/Error0053'
                Error0063:
                  $ref: '#/components/examples/Error0063'
        '404':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0059:
                  $ref: '#/components/examples/Error0059'
                Error0061:
                  $ref: '#/components/examples/Error0061'
        '422':
          description: Unprocessable — calculation failed due to dependency or data issues.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0060:
                  $ref: '#/components/examples/Error0060'
                Error0062:
                  $ref: '#/components/examples/Error0062'
                Error0068:
                  $ref: '#/components/examples/Error0068'
        '500':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0004:
                  $ref: '#/components/examples/Error0004'
      security: []
components:
  parameters:
    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
    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
  schemas:
    CalculateBillingRequest:
      type: object
      properties:
        ledgerId:
          type: string
          description: Unique identifier of the Ledger to calculate billing for.
        period:
          type: string
          description: >-
            Billing period. Supported formats: `YYYY-MM` (monthly), `YYYY-Www`
            (weekly, e.g. `2026-W13`), or `YYYY-MM-DD` (daily).
        type:
          type: string
          enum:
            - volume
            - maintenance
          description: >-
            Filter by billing type. When omitted, both volume and maintenance
            packages are calculated.
      required:
        - ledgerId
        - period
    CalculateBillingResponse:
      type: object
      properties:
        results:
          type: array
          description: One result per active billing package processed.
          items:
            type: object
            properties:
              billingPackageId:
                type: string
                description: ID of the billing package that generated this result.
              billingPackageLabel:
                type: string
                description: Label of the billing package.
              billingType:
                type: string
                enum:
                  - volume
                  - maintenance
                description: Type of the billing package.
              period:
                type: string
                description: Billing period used for this calculation.
              totalAccounts:
                type: integer
                description: Total number of accounts evaluated.
              totalCharged:
                type: integer
                description: Number of accounts that were charged.
              totalSkipped:
                type: integer
                description: Number of accounts skipped (e.g., free-quota exhausted).
              totalNetAmount:
                type: string
                description: Net amount charged after discounts. Decimal string.
              transactionPayload:
                type: object
                description: >-
                  Transaction payload ready to be sent to Midaz via POST
                  /transactions/json. Includes audit metadata (billingPackageId,
                  billingPeriod, pricing details) in the metadata field.
        summary:
          type: object
          description: Consolidated totals across all results.
          properties:
            totalResults:
              type: integer
              description: Number of billing packages processed.
            totalVolume:
              type: integer
              description: Number of volume results.
            totalMaintenance:
              type: integer
              description: Number of maintenance results.
            totalNetAmount:
              type: string
              description: Total net amount across all results. Decimal string.
    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.
  examples:
    Error0019:
      summary: Invalid header parameter
      value:
        code: FEE-0019
        title: Invalid header parameter
        message: >-
          One or more headers parameters are in an incorrect format. Please
          check the following parameters and ensure they meet the required
          format before trying again.
    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.
    Error0041:
      summary: Unmarshalling error
      value:
        code: FEE-0041
        title: Unmarshalling error
        message: 'Invalid value for field ''%s'': expected type ''%s'', but got ''%s''.'
    Error0053:
      summary: Invalid billing type
      value:
        code: FEE-0053
        title: Invalid billing type
        message: The type field must be `volume` or `maintenance`.
    Error0063:
      summary: Invalid period format
      value:
        code: FEE-0063
        title: Invalid period format
        message: >-
          The period field must follow the format YYYY-MM (monthly), YYYY-Www
          (weekly), or YYYY-MM-DD (daily).
    Error0059:
      summary: Target account not found
      value:
        code: FEE-0059
        title: Target account not found
        message: >-
          One or more accounts referenced in accountTarget could not be found in
          Midaz.
    Error0061:
      summary: No active billing packages
      value:
        code: FEE-0061
        title: No active billing packages
        message: No active billing packages were found for the given ledger and period.
    Error0060:
      summary: Billing calculation failed
      value:
        code: FEE-0060
        title: Billing calculation failed
        message: >-
          An internal error occurred while calculating billing for the given
          period.
    Error0062:
      summary: Segment resolution failed
      value:
        code: FEE-0062
        title: Segment resolution failed
        message: >-
          The system could not resolve the segment referenced in waivedAccounts.
          Verify the segment ID and Midaz connectivity.
    Error0068:
      summary: Midaz query failed
      value:
        code: FEE-0068
        title: Midaz query failed
        message: The system could not query Midaz. Verify connectivity and permissions.
    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.

````