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

# Execute SQL query

> Execute a read-only SQL query against orchestration ClickHouse tables (spans, runs, batches, records). 



## OpenAPI

````yaml https://api.getcargo.io/openapi.json post /orchestration/query
openapi: 3.1.0
info:
  title: Cargo API
  version: 1.0.0
  description: Cargo Platform API v1
servers:
  - url: https://api.getcargo.io/v1
    description: Cargo API
security:
  - bearerAuth: []
paths:
  /orchestration/query:
    post:
      tags:
        - Orchestration - Query
      summary: Execute SQL query
      description: >-
        Execute a read-only SQL query against orchestration ClickHouse tables
        (spans, runs, batches, records). 
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: string
                  maxLength: 10000
                  title: SQL query
                  description: >-
                    A read-only SELECT statement. Available tables: logs, runs,
                    batches, records. Results are automatically scoped to the
                    authenticated workspace Example: "SELECT status, count()
                    FROM runs GROUP BY status"
              required:
                - query
              additionalProperties: false
              title: Request body
              description: Request body schema.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  rows:
                    type: array
                    items:
                      type: object
                      propertyNames:
                        type: string
                      additionalProperties: {}
                    title: Rows
                    description: Result rows.
                required:
                  - rows
                additionalProperties: false
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Internal server error
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````