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

# Structured Query



## OpenAPI

````yaml openapi.json POST /gateway/v1/onchain/query
openapi: 3.1.0
info:
  title: Hermod
  version: 0.0.1
servers:
  - url: https://api.asksurf.ai
security: []
paths:
  /gateway/v1/onchain/query:
    post:
      tags:
        - Onchain
      summary: Blockchain Structured Query
      description: >-
        Executes a structured JSON query on blockchain data. No raw SQL needed —
        specify source, fields, filters, sort, and pagination.


        All tables live in the **agent** database. Use `GET /v1/onchain/schema`
        to discover available tables and their columns.


        **Key rules:**

        - **Source format:** `agent.<table_name>` (e.g.
        `agent.ethereum_transactions`, `agent.ethereum_dex_trades`)

        - Max 10,000 rows (default 20), 30s timeout

        - **Always filter on block_date** — it is the partition key. Without it,
        queries scan billions of rows and will timeout


        **Data refresh:** ~24 hours.


        ## Example


        ```json

        {
          "source": "agent.ethereum_dex_trades",
          "fields": ["block_time", "project", "token_pair", "amount_usd", "taker"],
          "filters": [
            {"field": "block_date", "op": "gte", "value": "2025-03-01"},
            {"field": "project", "op": "eq", "value": "uniswap"},
            {"field": "amount_usd", "op": "gte", "value": 100000}
          ],
          "sort": [{"field": "amount_usd", "order": "desc"}],
          "limit": 20
        }

        ```
      operationId: onchain-structured-query
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StructuredQuery'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataResponseOnchainRow'
          description: OK
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataAPIError'
          description: Error
      security:
        - AccessToken: []
components:
  schemas:
    StructuredQuery:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          examples:
            - https://example.com/schemas/StructuredQuery.json
          format: uri
          readOnly: true
          type: string
        fields:
          description: >-
            Columns to return. Omit to return all columns. Example for
            agent.ethereum_transactions: [`transaction_hash`, `from_address`,
            `value`]
          examples:
            - - transaction_hash
              - from_address
              - value
          items:
            type: string
          type:
            - array
            - 'null'
        filters:
          description: WHERE conditions (ANDed together)
          items:
            $ref: '#/components/schemas/StructuredFilter'
          type:
            - array
            - 'null'
        limit:
          description: Max rows to return. Default 20, max 10000
          examples:
            - 20
          format: int64
          type: integer
        offset:
          description: Rows to skip for pagination. Default 0
          examples:
            - 0
          format: int64
          type: integer
        sort:
          description: ORDER BY clauses
          items:
            $ref: '#/components/schemas/StructuredSort'
          type:
            - array
            - 'null'
        source:
          description: Fully-qualified table name like `agent.my_table`
          examples:
            - agent.my_table
          type: string
      required:
        - source
      type: object
    DataResponseOnchainRow:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          examples:
            - https://example.com/schemas/DataResponseOnchainRow.json
          format: uri
          readOnly: true
          type: string
        data:
          items:
            additionalProperties: {}
            type: object
          type:
            - array
            - 'null'
        meta:
          $ref: '#/components/schemas/OffsetMeta'
      required:
        - data
        - meta
      type: object
    DataAPIError:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          examples:
            - https://example.com/schemas/DataAPIError.json
          format: uri
          readOnly: true
          type: string
        error:
          $ref: '#/components/schemas/DataAPIErrorDetail'
      required:
        - error
      type: object
    StructuredFilter:
      additionalProperties: false
      properties:
        field:
          description: Column name to filter on like `block_number` or `from_address`
          examples:
            - block_number
          type: string
        op:
          description: >-
            Comparison operator: eq, neq, gt, gte, lt, lte, like, in, not_in.
            For `in`/`not_in`, value must be a JSON array
          examples:
            - eq
          type: string
        value:
          description: >-
            Comparison value. Use a JSON array for `in`/`not_in` operators like
            `[21000000, 21000001]`
      required:
        - field
        - op
        - value
      type: object
    StructuredSort:
      additionalProperties: false
      properties:
        field:
          description: Column name to sort by like `gas`, `block_number`, or `amount_usd`
          examples:
            - gas
          type: string
        order:
          description: 'Sort direction: asc (default) or desc'
          examples:
            - desc
          type: string
      required:
        - field
      type: object
    OffsetMeta:
      additionalProperties: false
      properties:
        cached:
          description: Whether this response was served from cache
          type: boolean
        credits_used:
          description: Credits deducted for this request
          format: int64
          type: integer
        limit:
          description: Maximum number of items returned in this response
          format: int64
          type: integer
        offset:
          description: Number of items skipped (pagination offset)
          format: int64
          type: integer
        total:
          description: >-
            Total number of matching items (before pagination). Omitted when
            total is unknown.
          format: int64
          type: integer
      required:
        - limit
        - offset
        - credits_used
        - cached
      type: object
    DataAPIErrorDetail:
      additionalProperties: false
      properties:
        code:
          type: string
        message:
          type: string
      required:
        - code
        - message
      type: object

````