> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sonarx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Filter Fee History

> Get transaction fee data for a range of blocks

<Warning>
  **Range Filter Constraint**: Use either block range (`from_block`/`to_block`) OR datetime range (`from_datetime`/`to_datetime`), but not both simultaneously. These filter pairs are mutually exclusive.
</Warning>


## OpenAPI

````yaml POST /api/v1/customer/{chain}/fee-history/filter
openapi: 3.1.0
info:
  title: SonarX EVM API - Transactions
  description: >-
    Query transaction data, receipts, and fee history for EVM-compatible
    networks.
  version: 1.0.0
servers:
  - url: https://api-gateway.sonarx.com
    description: Production API
security:
  - apiKey: []
tags:
  - name: Transactions
    description: Query transaction data, receipts, and fee history
paths:
  /api/v1/customer/{chain}/fee-history/filter:
    post:
      tags:
        - Transactions
      summary: Filter Fee History
      description: >-
        Get transaction fee data for a range of blocks. Use either block range
        or datetime range, not both.
      operationId: filterFeeHistory
      parameters:
        - $ref: '#/components/parameters/ChainPath'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RangeFilterRequest'
            example:
              from_block: 81901160
              to_block: 81901165
      responses:
        '200':
          description: Fee history data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeeHistoryResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    ChainPath:
      name: chain
      in: path
      description: The blockchain network to query
      required: true
      schema:
        type: string
        enum:
          - polygon
        example: polygon
    Limit:
      name: limit
      in: query
      description: Maximum number of results (1-50)
      required: false
      schema:
        type: integer
        minimum: 1
        maximum: 50
        default: 10
    Offset:
      name: offset
      in: query
      description: Number of results to skip for pagination
      required: false
      schema:
        type: integer
        minimum: 0
        default: 0
  schemas:
    RangeFilterRequest:
      type: object
      description: >-
        Base filter request with range parameters. Validation rules: (1) Must
        provide either block range OR datetime range, not both and not neither.
        (2) When using block range, both from_block AND to_block are required.
        (3) When using datetime range, both from_datetime AND to_datetime are
        required. (4) to_block must be >= from_block. (5) to_datetime must be >=
        from_datetime. (6) Block range cannot exceed 100 blocks.
      properties:
        from_block:
          type: integer
          minimum: 0
          description: Start block number. Required if using block range.
        to_block:
          type: integer
          minimum: 0
          description: >-
            End block number. Required if using block range. Must be >=
            from_block and within 100 blocks.
        from_datetime:
          type: string
          format: date-time
          description: >-
            Start datetime (ISO 8601, timezone required, e.g.,
            2024-01-15T10:30:00Z or 2024-01-15T10:30:00+00:00). Required if
            using datetime range.
        to_datetime:
          type: string
          format: date-time
          description: >-
            End datetime (ISO 8601, timezone required, e.g.,
            2024-01-15T10:30:00Z or 2024-01-15T10:30:00+00:00). Required if
            using datetime range. Must be >= from_datetime.
    FeeHistoryResponse:
      type: object
      properties:
        from_block:
          type: integer
          nullable: true
        to_block:
          type: integer
          nullable: true
        from_datetime:
          type: string
          nullable: true
        to_datetime:
          type: string
          nullable: true
        offset:
          type: integer
        limit:
          type: integer
        result:
          type: array
          items:
            $ref: '#/components/schemas/FeeHistory'
        count:
          type: integer
      example:
        from_block: 81901160
        to_block: 81901165
        from_datetime: null
        to_datetime: null
        offset: 0
        limit: 10
        result:
          - block_number: 81901165
            timestamp: 1768922302
            datetime: '2026-01-20T15:18:22'
            base_fee_per_gas: 600795160350
            gas_used: 39500751
            gas_limit: 65000000
            gas_used_ratio: 0.6077038615384616
          - block_number: 81901164
            timestamp: 1768922300
            datetime: '2026-01-20T15:18:20'
            base_fee_per_gas: 602611448639
            gas_used: 34100066
            gas_limit: 65000000
            gas_used_ratio: 0.5246164
        count: 2
    FeeHistory:
      type: object
      properties:
        block_number:
          type: integer
        timestamp:
          type: integer
        datetime:
          type: string
          format: date-time
        base_fee_per_gas:
          type: integer
        gas_used:
          type: integer
        gas_limit:
          type: integer
        gas_used_ratio:
          type: number
      example:
        block_number: 81901165
        timestamp: 1768922302
        datetime: '2026-01-20T15:18:22'
        base_fee_per_gas: 600795160350
        gas_used: 39500751
        gas_limit: 65000000
        gas_used_ratio: 0.6077038615384616
    ErrorResponse:
      type: object
      properties:
        detail:
          type: string
      required:
        - detail
  responses:
    BadRequest:
      description: Bad Request - Invalid parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingBlockNumber:
              summary: Missing block number
              value:
                detail: block_number is required
            mixedRangeParams:
              summary: Mixed block and datetime parameters
              value:
                detail: >-
                  Cannot mix block and datetime parameters. Use either
                  from_block/to_block or from_datetime/to_datetime, not both
            missingRangeParams:
              summary: No range parameters provided
              value:
                detail: >-
                  Either block range (from_block/to_block) or datetime range
                  (from_datetime/to_datetime) must be provided
            incompleteBlockRange:
              summary: Incomplete block range
              value:
                detail: Both from_block and to_block must be provided together
            blockRangeTooLarge:
              summary: Block range exceeds limit
              value:
                detail: Block range cannot exceed 100 blocks
    Unauthorized:
      description: Unauthorized - Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            detail: Invalid API key
    InternalError:
      description: Internal Server Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            detail: An unexpected error occurred
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: apikey
      description: API key for authentication

````