SaturnSQL Queries API

Save, list, execute and review SQL

GitHub OpenAPI

Operations 7

GET /queries/{id} Get a saved query #
POST /queries/{id}/run Run a saved query #
POST /queries/execute Execute SQL #
GET /queries/history Query run history #
GET /queries List saved queries #
POST /queries Save a query #
PUT /queries Update a query #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/saturnsql-com:saturnsql-com-queries-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

saturnsql-com-queries-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: SaturnSQL Queries API
  description: 'HTTP API for the SaturnSQL database query platform. SaturnSQL connects to your PostgreSQL, MySQL, MSSQL, Oracle, Amazon Redshift, ClickHouse, DynamoDB and BigQuery databases and lets people — and AI agents — explore their schema and run queries through one authenticated surface, without ever handling raw database credentials. **Connecting an AI assistant (Claude, ChatGPT, Cursor, Claude Code)?** Use the hosted MCP server at `https://mcp.saturnsql.com/mcp` instead of calling this API. It signs the user in with OAuth, so no API key is handled, and exposes the same connections, schema and query tools. Setup: https://saturnsql.com/help/mcp-connector


    ## Authentication


    Two bearer credentials are accepted on the `Authorization` header:


    - **API key** (recommended for scripts, CI and integrations) — a long-lived, scoped, revocable key in the `sat_live_...` format, created in Settings → API Keys. - **JWT session token** — obtained from `POST /auth/login`; expires after 24 hours and requires the TOTP step when MFA is enrolled. This is what the web app uses. ```

    Authorization: Bearer sat_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    ```


    ### API key scopes


    A key carries one or more scopes. Everything not in the list below fails closed — a key can never manage other keys, users, billing, or connections. | Scope | Grants |

    |-------|--------|

    | `read` | `GET /connections`, `GET /schema/{connectionId}`, `GET /schema/context`, `GET /queries`, `GET /queries/{id}`, `GET /queries/history` |

    | `execute` | `POST /queries/execute` (run SQL), `POST /queries/{id}/run` (run a saved query from values) |

    | `write` | `POST /queries`, `PUT /queries` (save / update saved queries); with `execute` also `POST /schedules` (create a schedule, which runs its saved query) |


    Give an agent the narrowest scope it needs: `read` alone to explore schema and saved queries, add `execute` only when it must run SQL, add `write` only when it should persist queries. Name the key after the agent and set an expiry. ## Building queries and insights with an AI agent


    The intended agent loop is **discover → understand → query → (optionally) save**. Every call is scoped to the company the key belongs to, and only connections the key''s owner can see are reachable. ### 1. Discover connections


    List the databases available to the key and pick a `connectionId`:


    ```

    curl -s https://saturnsql.com/api/connections \

    -H ''Authorization: Bearer sat_live_...''

    ```


    Each connection reports its `id`, `name`, database `type` and whether it is read-only. ### 2. Understand the schema


    Pull the tables, columns and types so the agent writes SQL against the real structure — never guess table or column names:


    ```

    # Full schema for a connection

    curl -s ''https://saturnsql.com/api/schema/CONNECTION_ID'' \

    -H ''Authorization: Bearer sat_live_...''


    # Relevance-ranked subset for a goal (best for large databases)

    curl -s ''https://saturnsql.com/api/schema/context?connection_id=CONNECTION_ID&intent=monthly%20revenue%20by%20plan'' \

    -H ''Authorization: Bearer sat_live_...''

    ```


    `GET /schema/context` accepts `connection_id` (required), `intent` (a natural-language description of what you''re after), `tables` (comma-separated allowlist) and `current_sql`, and returns only the slice of schema relevant to that intent. Feed it straight into your SQL-generation prompt to keep context small and accurate. ### 3. Run read-only queries


    Execute generated SQL and get rows back (`execute` scope required):


    ```

    curl -s https://saturnsql.com/api/queries/execute \

    -H ''Authorization: Bearer sat_live_...'' \

    -H ''Content-Type: application/json'' \

    -d ''{"connectionId":"CONNECTION_ID","sql":"SELECT plan, count(*) AS n FROM companies GROUP BY plan ORDER BY n DESC","limit":100}''

    ```


    `limit` defaults to 1000 and caps at 10000. The response returns the result rows plus column metadata.'
  version: 1.0.0
  contact:
    name: SaturnSQL Support
    email: support@saturnsql.com
servers:
- url: https://saturnsql.com/api
  description: Production server
security:
- BearerAuth: []
- ApiKeyAuth: []
tags:
- name: Queries
  description: Save, list, execute and review SQL
paths:
  /queries/{id}:
    get:
      tags:
      - Queries
      summary: Get a saved query
      description: Returns a single saved query by id. Available to API keys with the `read` scope.
      operationId: get_queries
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: cuid
      responses:
        '200':
          description: Saved query
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SavedQuery'
              example:
                id: cmr9q1
                name: Signups by month
                sql: SELECT date_trunc('month', created_at) m, count(*) FROM users GROUP BY 1 ORDER BY 1
                connectionId: cmrt9ccrc0001
                folderPath: Growth
                isShared: true
                userId: cmr9k2user
                createdAt: '2026-07-01T08:00:00.000Z'
                updatedAt: '2026-07-01T08:00:00.000Z'
        '401':
          description: Bad or missing credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Query not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /queries/{id}/run:
    post:
      tags:
      - Queries
      summary: Run a saved query
      description: 'Runs a saved query, substituting its declared `{{variables}}` from the values supplied. The caller sends values, never SQL: the SQL comes from the stored query and every value is type-checked and escaped server side. A value that is missing or invalid returns `422` with one entry per bad variable and executes nothing. An absent name falls back to that variable''s default; a name present with an empty string stays empty. Same read-only guard, rate limit and monthly quota as POST /queries/execute. Available to API keys with the `execute` scope.'
      operationId: create_queries_run
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: cuid
      - name: values
        in: query
        required: true
        description: Variable values by name. An absent name falls back to that variable's default; a name present with an empty string stays empty.
        schema:
          type: object
      - name: timeZone
        in: query
        required: true
        description: 'IANA time zone used to resolve relative date defaults (default: UTC)'
        schema:
          type: string
      - name: limit
        in: query
        required: true
        description: 'Maximum rows to return (default: 1000, max: 10000)'
        schema:
          type: number
      - name: refresh
        in: query
        required: true
        description: Skip the result cache and read the database now. Omit to allow a cached result.
        schema:
          type: boolean
      - name: approvalId
        in: query
        required: true
        description: Repeat a request held for approval with the id it returned, once a person has approved it.
        schema:
          type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                values:
                  type: object
                  additionalProperties:
                    type: string
                  description: Variable values by name
                timeZone:
                  type: string
                  description: IANA zone used to resolve relative date defaults (default UTC)
                limit:
                  type: integer
                  minimum: 1
                  maximum: 10000
                  description: Max rows (default 1000)
            example:
              values:
                start_date: '2026-06-01'
                end_date: ''
              timeZone: Europe/Helsinki
              limit: 100
      responses:
        '200':
          description: Result rows
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryResult'
              example:
                success: true
                result:
                  rows:
                  - id: 41
                    acquired_at: '2026-06-04'
                  fields:
                  - name: id
                    dataTypeID: 20
                  - name: acquired_at
                    dataTypeID: 1082
                  rowCount: 1
                  command: SELECT
                  duration: 24
                  truncated: false
        '400':
          description: Invalid request, no connection on the query, or variables on a DynamoDB connection
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Bad or missing credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Insufficient scope, paused connection, or non-read-only SQL
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Query not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: One or more variable values are missing or invalid; nothing was executed
          content:
            application/json:
              schema:
                type: object
                properties:
                  errors:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                        code:
                          type: string
                          enum:
                          - required
                          - invalid_date
                          - invalid_number
                          - invalid_boolean
                          - not_an_option
                          - unknown_variable
                          - illegal_character
                        message:
                          type: string
              example:
                errors:
                - name: start_date
                  code: invalid_date
                  message: Variable "start_date" must be a date in YYYY-MM-DD format.
        '429':
          description: Query quota or rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /queries/execute:
    post:
      tags:
      - Queries
      summary: Execute SQL
      description: 'Runs SQL against a connection and returns rows plus column metadata. Read-only guarded: only SELECT, WITH (CTE) and EXPLAIN are accepted, one statement at a time; write/DDL/admin verbs (INSERT, UPDATE, DELETE, DROP, …) are rejected with `400`, the same status as any invalid or multi-statement SQL. `limit` defaults to 1000, caps at 10000. Available to API keys with the `execute` scope. Exceeding the monthly query quota or the rate limit returns `429`.'
      operationId: create_queries_execute
      parameters:
      - name: connectionId
        in: query
        required: true
        description: Database connection ID
        schema:
          type: string
      - name: sql
        in: query
        required: true
        description: Read-only SQL query to execute (SELECT / WITH / EXPLAIN). May contain {{variable}} placeholders, in which case `variables` must define every one of them.
        schema:
          type: string
      - name: limit
        in: query
        required: true
        description: 'Maximum rows to return (default: 1000, max: 10000)'
        schema:
          type: number
      - name: variables
        in: query
        required: true
        description: Definitions for the {{placeholders}} in `sql`. Values are type-checked and escaped against these server side.
        schema:
          type: object
      - name: values
        in: query
        required: true
        description: Variable values by name. An absent name falls back to that variable's default; a name present with an empty string stays empty.
        schema:
          type: object
      - name: timeZone
        in: query
        required: true
        description: 'IANA time zone used to resolve relative date defaults (default: UTC)'
        schema:
          type: string
      - name: readOnly
        in: query
        required: true
        description: Reject anything but a read, even where the connection allows writes
        schema:
          type: boolean
      - name: approvalId
        in: query
        required: true
        description: Repeat a request held for approval with the id it returned, once a person has approved it.
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - connectionId
              - sql
              properties:
                connectionId:
                  type: string
                sql:
                  type: string
                  description: 'Read-only SQL: SELECT / WITH / EXPLAIN'
                limit:
                  type: integer
                  minimum: 1
                  maximum: 10000
                  description: Max rows (default 1000)
            example:
              connectionId: cmrt9ccrc0001
              sql: SELECT plan, count(*) AS n FROM companies GROUP BY plan ORDER BY n DESC
              limit: 100
      responses:
        '200':
          description: Result rows
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryResult'
              example:
                success: true
                result:
                  rows:
                  - plan: pro
                    n: 42
                  - plan: starter
                    n: 17
                  fields:
                  - name: plan
                    dataTypeID: 25
                  - name: n
                    dataTypeID: 20
                  rowCount: 2
                  command: SELECT
                  duration: 38
                  truncated: false
        '400':
          description: Invalid SQL or non-read-only statement
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Bad or missing credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Insufficient scope
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Query quota or rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /queries/history:
    get:
      tags:
      - Queries
      summary: Query run history
      description: Returns the caller's recent query executions (SQL, connection, timing, status). Available to API keys with the `read` scope.
      operationId: list_queries_history
      parameters: []
      responses:
        '200':
          description: History
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/QueryHistoryEntry'
              example:
              - id: cmr9h1
                sqlContent: SELECT count(*) FROM users
                connectionId: cmrt9ccrc0001
                rowCount: 1
                executionTimeMs: 42
                errorMessage: null
                createdAt: '2026-07-26T09:12:00.000Z'
        '401':
          description: Bad or missing credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /queries:
    get:
      tags:
      - Queries
      summary: List saved queries
      description: Returns the saved queries visible to the caller (own + company-shared). Available to API keys with the `read` scope.
      operationId: list_queries
      parameters: []
      responses:
        '200':
          description: Saved queries
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SavedQuery'
              example:
              - id: cmr9q1
                name: Signups by month
                sql: SELECT date_trunc('month', created_at) m, count(*) FROM users GROUP BY 1 ORDER BY 1
                connectionId: cmrt9ccrc0001
                folderPath: Growth
                isShared: true
                userId: cmr9k2user
                createdAt: '2026-07-01T08:00:00.000Z'
                updatedAt: '2026-07-01T08:00:00.000Z'
        '401':
          description: Bad or missing credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      tags:
      - Queries
      summary: Save a query
      description: 'Saves a query for reuse, optionally filed into a folder with `folderPath` (null = root). Available to API keys with the `write` scope. Sharing a query company-wide is plan-gated and done in the web app.


        The fields below are the whole create surface: `description` and `chart` are ignored if sent. The saved query is immediately readable at `/app/report/{id}`, where the result shape decides the chart.'
      operationId: create_queries
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - name
              - sql
              properties:
                name:
                  type: string
                sql:
                  type: string
                connectionId:
                  type: string
                  description: Optional; the connection this query targets
                folderPath:
                  type:
                  - string
                  - 'null'
                  description: A single flat folder label, not a nested path ("A/B" is one label); null = root
                variables:
                  type: array
                  items:
                    $ref: '#/components/schemas/QueryVariable'
                  description: Declarations for the `{{name}}` placeholders in `sql`. Omit or send [] when there are none.
            example:
              name: Signups by month
              sql: SELECT date_trunc('month', created_at) m, count(*) FROM users GROUP BY 1 ORDER BY 1
              connectionId: cmrt9ccrc0001
              folderPath: Growth
      responses:
        '201':
          description: Saved
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SavedQuery'
              example:
                id: cmr9qNEW
                name: Signups by month
                sql: SELECT date_trunc('month', created_at) m, count(*) FROM users GROUP BY 1 ORDER BY 1
                connectionId: cmrt9ccrc0001
                folderPath: Growth
                isShared: false
                userId: cmr9k2user
                createdAt: '2026-07-26T10:00:00.000Z'
                updatedAt: '2026-07-26T10:00:00.000Z'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Bad or missing credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Saved-query limit reached (plan)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    put:
      tags:
      - Queries
      summary: Update a query
      description: Updates a saved query. Only the fields you send change; `sql` and `folderPath` are optional. Available to API keys with the `write` scope. Changing the `sql` or `variables` of a query that has a schedule also needs the `execute` scope, since the schedule runs it.
      operationId: update_queries
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - queryId
              - name
              properties:
                queryId:
                  type: string
                name:
                  type: string
                sql:
                  type: string
                folderPath:
                  type:
                  - string
                  - 'null'
                  description: A single flat folder label, not a nested path ("A/B" is one label); null moves to root; omit to leave unchanged
                variables:
                  type: array
                  items:
                    $ref: '#/components/schemas/QueryVariable'
                  description: Replaces the stored declarations. Omit to leave them unchanged; send [] to clear them.
            example:
              queryId: cmr9q1
              name: Signups by month (v2)
              sql: SELECT date_trunc('week', created_at) w, count(*) FROM users GROUP BY 1 ORDER BY 1
              folderPath: Growth
      responses:
        '200':
          description: Updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SavedQuery'
              example:
                id: cmr9q1
                name: Signups by month (v2)
                sql: SELECT date_trunc('week', created_at) w, count(*) FROM users GROUP BY 1 ORDER BY 1
                connectionId: cmrt9ccrc0001
                folderPath: Growth
                isShared: true
                userId: cmr9k2user
                createdAt: '2026-07-01T08:00:00.000Z'
                updatedAt: '2026-07-26T10:05:00.000Z'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Bad or missing credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Insufficient scope or plan restriction
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    QueryResult:
      type: object
      properties:
        success:
          type: boolean
        result:
          type: object
          properties:
            rows:
              type: array
              items:
                type: object
                additionalProperties: true
            fields:
              type: array
              description: Column descriptors. `name` and `dataTypeID` are always present; the driver may include additional fields (e.g. dataTypeSize, format, tableID) which are safe to ignore.
              items:
                type: object
                properties:
                  name:
                    type: string
                  dataTypeID:
                    type: integer
                additionalProperties: true
            rowCount:
              type: integer
            command:
              type: string
            duration:
              type: integer
              description: Execution time in ms
            truncated:
              type: boolean
              description: True when rows/cells were capped to fit the memory budget.
    SavedQuery:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        sql:
          type: string
        connectionId:
          type:
          - string
          - 'null'
        folderPath:
          type:
          - string
          - 'null'
          description: A single flat folder label (not a nested path); "A/B" is one folder named "A/B", not "A" containing "B". null = root.
        isShared:
          type: boolean
        description:
          type:
          - string
          - 'null'
          description: Subtitle on the report page. Returned by GET /queries; nothing can set it yet, so always null.
        chart:
          allOf:
          - $ref: '#/components/schemas/ChartSpec'
          description: Pinned chart, or null to let the result shape decide. Returned by GET /queries for editors only (absent from GET /queries/{id}); set with PUT /queries/{id}/chart (session token only).
        userId:
          type: string
        variables:
          type: array
          description: Declared `{{name}}` variables, in first-appearance order in the SQL. Empty when the query has none.
          items:
            $ref: '#/components/schemas/QueryVariable'
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    Error:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message
        details:
          type: object
          additionalProperties: true
          description: Optional field-level validation details
      required:
      - error
      example:
        error: Insufficient scope
    QueryVariable:
      type: object
      description: One `{{name}}` variable declared by a saved query. Values are supplied to POST /queries/{id}/run and substituted server side.
      required:
      - name
      - type
      properties:
        name:
          type: string
          description: Matches `[A-Za-z_][A-Za-z0-9_]*`
        type:
          type: string
          enum:
          - date
          - text
          - number
          - boolean
          - dropdown
        required:
          type: boolean
          description: An empty value for a required variable is a 422, not an empty substitution.
        default:
          type:
          - object
          - 'null'
          description: Used when the value is absent. A `relative` default is only valid on a `date` variable and resolves against the caller time zone (or the schedule time zone).
          properties:
            kind:
              type: string
              enum:
              - fixed
              - relative
            value:
              type: string
              description: Literal for `fixed`; one of today, yesterday, 7_days_ago, 30_days_ago, 90_days_ago, start_of_this_month, start_of_last_month, end_of_last_month, start_of_this_year for `relative`.
        options:
          type: array
          items:
            type: string
          description: Dropdown only, non-empty. A value outside this list is a 422.
    QueryHistoryEntry:
      type: object
      properties:
        id:
          type: string
        sqlContent:
          type: string
        connectionId:
          type:
          - string
          - 'null'
        rowCount:
          type: integer
        executionTimeMs:
          type: integer
        errorMessage:
          type:
          - string
          - 'null'
        createdAt:
          type: string
          format: date-time
    ChartSpec:
      type: object
      description: 'How a report should be drawn. Stored verbatim and interpreted at render time, since the columns a spec refers to only exist after a run: a spec naming a column the SELECT list no longer returns falls back to the shape-derived guess rather than failing.


        With no spec stored, the result shape decides — see the "saved query is also a report page" section of the API guide for the rules an agent should write SQL against.'
      required:
      - type
      properties:
        type:
          type: string
          enum:
          - line
          - area
          - bar
          - scatter
          - share
          - number
          - none
          description: '`none` suppresses the chart for good, which is why it is distinct from a null `chart`. `share` is never guessed and must be set explicitly: its shape is identical to `bar` and nothing in the data says which is meant.'
        x:
          type: string
          description: Column for the x axis or the category. Absent for `number`.
        series:
          type: array
          items:
            type: string
          maxItems: 3
          description: 'Measure columns, in order. Capped at 3: the validated palette separates three series by lightness and a fourth has no colour.'
        group:
          type: string
          description: Low-cardinality column splitting a scatter into groups.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 24h session token from POST /auth/login
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: sat_live_...
      description: 'Long-lived scoped API key (sat_live_ prefix), created in Settings. Scopes: read, execute.'