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

# Run Query

> Execute a query synchronously and return results.

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url "https://api.roe-ai.com/v1/database/query/?organization_id=YOUR_ORG_ID" \
    --header "Authorization: Bearer YOUR_API_KEY" \
    --header "Content-Type: application/json" \
    --data '{
      "query": "SELECT * FROM my_table LIMIT 10"
    }'
  ```
</RequestExample>


## OpenAPI

````yaml POST /v1/database/query/
openapi: 3.1.0
info:
  title: Roe AI API
  version: 1.0.0
  description: Complete API documentation for Roe AI platform
servers:
  - url: https://api.roe-ai.com
    description: Production API
security: []
paths:
  /v1/database/query/:
    post:
      tags:
        - v1
      description: Execute a query synchronously and return results.
      operationId: v1_database_query_create
      parameters:
        - name: organization_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: >-
            Organization ID. This is required for access control. It can be
            provided via query or request body depending on the endpoint.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DatabaseQueryRequestRequest'
            examples:
              DatabaseQueryExample:
                value:
                  query: SELECT * FROM users LIMIT 10
                  worksheet_id: 123e4567-e89b-12d3-a456-426614174000
                  use_admin: false
                  organization_id: 123e4567-e89b-12d3-a456-426614174000
                summary: Database Query Example
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/DatabaseQueryResult'
              examples:
                DatabaseQueryExample:
                  value:
                    - query: SELECT * FROM users LIMIT 10
                      worksheet_id: 123e4567-e89b-12d3-a456-426614174000
                      use_admin: false
                      organization_id: 123e4567-e89b-12d3-a456-426614174000
                  summary: Database Query Example
          description: ''
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad request
components:
  schemas:
    DatabaseQueryRequestRequest:
      type: object
      properties:
        query:
          type: string
          minLength: 1
          description: SQL query to execute
        worksheet_id:
          type: string
          format: uuid
          description: Optional worksheet ID
        use_admin:
          type: boolean
          default: false
          description: Use admin privileges
        organization_id:
          type: string
          format: uuid
          description: Organization ID
      required:
        - query
    DatabaseQueryResult:
      type: object
      properties:
        query_id:
          type: string
          description: The query UUID.
        query:
          type: string
          description: The query that was run.
        summary:
          allOf:
            - $ref: '#/components/schemas/DatabaseQueryResultSummary'
          description: The summary of the query results.
        row_count:
          type: integer
          description: The number of rows returned by the query.
        column_names:
          type: array
          items:
            type: string
          description: A list of strings representing the column names
        column_types:
          type: array
          items:
            type: string
          description: A list of strings representing the column types
        result_rows:
          type: array
          items:
            type: array
            items:
              type: string
          description: >-
            A matrix of the data returned in the form of a Sequence of rows,
            with each row element being a sequence of column values.
        start_timestamp:
          type: number
          format: double
          description: The timestamp when the query started running.
        end_timestamp:
          type: number
          format: double
          description: The timestamp when the query finished running.
      required:
        - column_names
        - column_types
        - end_timestamp
        - query
        - result_rows
        - row_count
        - start_timestamp
        - summary
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
          description: Error message
      required:
        - message
    DatabaseQueryResultSummary:
      type: object
      properties:
        read_rows:
          type: integer
        read_bytes:
          type: integer
        written_rows:
          type: integer
        written_bytes:
          type: integer
        total_rows_to_read:
          type: integer
        result_rows:
          type: integer
        result_bytes:
          type: integer
        elapsed_ns:
          type: integer
        query_id:
          type: string

````