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

# Query Connector

> Run an ad-hoc SQL query against a connector's source and return the bounded result inline. Read-only by default (enforced node-side); write mode must also be allowed by the connection's local policy on the connector box. Requires a connector advertising query:sql (0.1.26+).



## OpenAPI

````yaml POST /orgs/{org_id}/connectors/{connector_id}/query
openapi: 3.1.0
info:
  title: Timbal Platform API
  description: Public API documentation for the Timbal platform
  license:
    name: ''
  version: 2.0.0
servers:
  - url: https://api.timbal.ai
    description: Production
  - url: https://api.dev.timbal.ai
    description: Development
security: []
tags:
  - name: ace
    description: Action Control Engine (ACE) operations
  - name: analytics
    description: Org and project analytics
  - name: billing
    description: Subscriptions, usage, and payment-related operations
  - name: content
    description: Re-sign stored content URLs
  - name: files
    description: File operations
  - name: iam
    description: IAM — actions, roles, users, and authorization introspection
  - name: k2
    description: Knowledge Bases v2 operations
  - name: orgs
    description: Organization operations
  - name: projects
    description: Project operations
  - name: runs
    description: Execution operations
  - name: templates
    description: Public project template catalog
  - name: users
    description: Authenticated user profile
paths:
  /orgs/{org_id}/connectors/{connector_id}/query:
    post:
      tags:
        - connectors
      summary: '`POST /orgs/{org_id}/connectors/{connector_id}/query`'
      description: >-
        Run an ad-hoc SQL query against a connector's source and return the
        bounded result inline. Read-only by default (enforced node-side); write
        mode must also be allowed by the connection's local policy on the
        connector box. Requires a connector advertising query:sql (0.1.26+).
      operationId: handler
      parameters:
        - name: org_id
          in: path
          required: true
          schema:
            type: string
        - name: connector_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueryReq'
        required: true
      responses:
        '200':
          description: Query executed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryRes'
        '400':
          description: Invalid request
        '403':
          description: Forbidden
        '404':
          description: Connector not found
        '422':
          description: Connector offline / refused / timed out / too old
      security:
        - bearer_auth: []
components:
  schemas:
    QueryReq:
      type: object
      required:
        - connection_ref
        - sql
      properties:
        connection_ref:
          type: string
          description: Connection ref on the node (from `/browse/connections`).
        max_rows:
          type:
            - integer
            - 'null'
          format: int32
          description: Row cap on the returned result. Defaults to 500, ceiling 10000.
          minimum: 0
        mode:
          type:
            - string
            - 'null'
          description: |-
            `read` (default) | `write`. `read` is enforced node-side with
            engine-level read-only semantics; `write` additionally requires the
            connection's local policy (`connections.json`) to allow writes.
        sql:
          type: string
          description: >-
            The SQL to run. One statement on MySQL; multi-statement batches work
            on

            Postgres and SQL Server (the **last** result set is returned; on

            Postgres that's the last *row-returning* set — zero-row sets are

            invisible to the node's driver — while SQL Server returns the true

            last set even when empty).
        timeout_ms:
          type:
            - integer
            - 'null'
          format: int64
          description: |-
            Node-side execution budget in milliseconds. Defaults to 30000,
            ceiling 60000.
          minimum: 0
    QueryRes:
      type: object
      required:
        - columns
        - rows
        - row_count
        - truncated
      properties:
        columns:
          type: array
          items:
            $ref: '#/components/schemas/QueryColumnView'
        row_count:
          type: integer
          minimum: 0
        rows:
          type: array
          items:
            type: array
            items:
              type: object
          description: |-
            Row-major, aligned with `columns`. Cells are plain JSON scalars:
            numbers stay numbers, exact decimals and timestamps are strings,
            binary is `0x`-prefixed hex, NULL is `null`.
        rows_affected:
          type:
            - integer
            - 'null'
          format: int64
          description: >-
            Rows changed by non-row-returning statements, when the engine
            reports

            it (Postgres/MySQL; `null` on SQL Server = unknown, not zero).
          minimum: 0
        truncated:
          type: boolean
          description: >-
            The node's row or byte cap bit — `rows` is a prefix of the real
            result.
    QueryColumnView:
      type: object
      required:
        - name
        - data_type
      properties:
        data_type:
          type: string
          description: Source-native type name (`int4`, `nvarchar`, `decimal`, …).
        name:
          type: string
  securitySchemes:
    bearer_auth:
      type: http
      scheme: bearer
      description: >-
        Timbal API key. Obtain your API key from the Timbal platform settings.
        See [Authentication](/api-reference/authentication) for more
        information.

````