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

# Run a scoped SQL query or mutation

> Requires host authentication and current database grants. Names and stable UUIDs are accepted as resource references. SQL availability and dialect depend on the provider; the PostgreSQL adapter supports a bounded subset, not arbitrary server SQL.



## OpenAPI

````yaml /agent-openapi.json post /api/v1/data/{resource}/query
openapi: 3.1.0
info:
  title: Polpo API
  version: 1.0.0
  description: >-
    REST API for Polpo — an AI agent that manages teams of AI coding agents.
    Manage tasks, missions, agents, playbooks, skills, and approvals. For
    conversational interaction, use the OpenAI-compatible POST
    /v1/chat/completions endpoint.
servers:
  - url: http://localhost:3890
    description: Local development
security:
  - bearerAuth: []
tags:
  - name: Databases
    description: >-
      Named application databases, records, scoped SQL, and versioned
      migrations.
paths:
  /api/v1/data/{resource}/query:
    post:
      tags:
        - Databases
      summary: Run a scoped SQL query or mutation
      description: >-
        Requires host authentication and current database grants. Names and
        stable UUIDs are accepted as resource references. SQL availability and
        dialect depend on the provider; the PostgreSQL adapter supports a
        bounded subset, not arbitrary server SQL.
      parameters:
        - schema:
            type: string
            minLength: 1
            maxLength: 128
          required: true
          name: resource
          in: path
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                sql:
                  type: string
                  minLength: 1
                  maxLength: 65536
                params:
                  type: array
                  items:
                    anyOf:
                      - type: string
                        maxLength: 65536
                      - type: number
                      - type: boolean
                      - type: 'null'
                  maxItems: 1000
                mode:
                  type: string
                  enum:
                    - read
                    - write
                maxRows:
                  type: integer
                  minimum: 1
                  maximum: 200
                idempotencyKey:
                  type: string
                  minLength: 1
                  maxLength: 200
                  pattern: ^[\x21-\x7e]+$
              required:
                - sql
              additionalProperties: false
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - true
                  data:
                    type: object
                    properties:
                      rows:
                        type: array
                        items:
                          type: object
                          additionalProperties: {}
                      rowCount:
                        type: integer
                      truncated:
                        type: boolean
                    required:
                      - rows
                      - rowCount
                      - truncated
                required:
                  - ok
                  - data
        '400':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
        '401':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
        '403':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
        '404':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
        '409':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
        '413':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
        '422':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
        '503':
          description: Invalid, denied, conflicting, bounded or unavailable request
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                  code:
                    type: string
                  error:
                    type: string
                required:
                  - ok
                  - code
                  - error
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key passed as a Bearer token. Configure via the apiKeys field in
        project.json or the POLPO_API_KEY environment variable.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.