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

# SQL Query



## OpenAPI

````yaml openapi.json POST /gateway/v1/onchain/sql
openapi: 3.1.0
info:
  title: Hermod
  version: 0.0.1
servers:
  - url: https://api.asksurf.ai
security: []
paths:
  /gateway/v1/onchain/sql:
    post:
      tags:
        - Onchain
      summary: Blockchain SQL Query
      description: >-
        Executes a raw SQL SELECT query against blockchain data.


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


        ## Rules

        - Only SELECT/WITH statements allowed (read-only)

        - All table references must be database-qualified: `agent.<table_name>`

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

        - **Always filter on block_date or block_number** — partition key,
        without it queries will timeout

        - Avoid `SELECT *` on large tables — specify only the columns you need


        **Data refresh:** ~24 hours.


        ## Example


        ```sql

        SELECT block_time, token_pair, amount_usd, taker, tx_hash

        FROM agent.ethereum_dex_trades

        WHERE block_date >= today() - 7
          AND project = 'uniswap' AND amount_usd > 100000
        ORDER BY amount_usd DESC LIMIT 20

        ```
      operationId: onchain-sql
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HumaOnchainSQLInputBody'
        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:
    HumaOnchainSQLInputBody:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          examples:
            - https://example.com/schemas/HumaOnchainSQLInputBody.json
          format: uri
          readOnly: true
          type: string
        max_rows:
          default: 1000
          description: Maximum number of rows to return
          examples:
            - 1000
          format: int64
          maximum: 10000
          minimum: 1
          type: integer
        sql:
          description: SQL query to execute against the blockchain data warehouse
          examples:
            - >-
              SELECT transaction_hash, from_address, value FROM
              agent.ethereum_transactions LIMIT 5
          type: string
      required:
        - sql
      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
    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

````