SaturnSQL Context API

The Context API from SaturnSQL — 7 operation(s) for context.

GitHub OpenAPI

Operations 10

PATCH /context/{connectionId}/definitions/{definitionId} Update a definition #
DELETE /context/{connectionId}/definitions/{definitionId} Delete a definition #
GET /context/{connectionId}/definitions List definitions #
POST /context/{connectionId}/definitions Create or replace a definition #
PUT /context/{connectionId}/descriptions Set a table or column description #
GET /context/{connectionId}/export Export context #
POST /context/{connectionId}/import Import an Apache Ossie model #
GET /context/{connectionId} Get context #
PATCH /context/{connectionId} Update notes for AI #
GET /context/{connectionId}/summary Get context for AI #

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-context-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-context-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: SaturnSQL Context 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: Context
paths:
  /context/{connectionId}/definitions/{definitionId}:
    patch:
      tags:
      - Context
      summary: Update a definition
      description: 'Changes a definition''s `name`, `description` or `sql` (JSON body, any of them). `sql: null` or an empty string removes the SQL. Needs the connection owner or an admin, and a plan with the context layer. Available to API keys with the `write` scope.'
      operationId: update_context_definitions
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      - name: definitionId
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
      - Context
      summary: Delete a definition
      description: Deletes a definition by id, or by its exact name (any case) for callers that only know the name. Needs the connection owner or an admin, and a plan with the context layer. Available to API keys with the `write` scope.
      operationId: delete_context_definitions
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      - name: definitionId
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /context/{connectionId}/definitions:
    get:
      tags:
      - Context
      summary: List definitions
      description: The connection's business definitions, e.g. "active customer", each with a description and an optional SQL expression in the connection's dialect. For people under access rules, definitions that name a hidden table or column are left out. Available to API keys with the `read` scope.
      operationId: get_context_definitions
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      tags:
      - Context
      summary: Create or replace a definition
      description: 'Creates a definition from a JSON body `{ name, description?, sql? }`, or replaces the one with the same name (names match in any case). Returns 201 when created and 200 when replaced. Omitted fields keep their value on replace; `sql: null` removes the SQL. Needs the connection owner or an admin, and a plan with the context layer. Available to API keys with the `write` scope.'
      operationId: create_context_definitions
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /context/{connectionId}/descriptions:
    put:
      tags:
      - Context
      summary: Set a table or column description
      description: 'Sets SaturnSQL''s description and/or synonyms for one table, or one column when `column` is given, as a JSON body `{ table, column?, description?, synonyms? }`. To set many at once, send `{ items: [...] }` with up to 200 of those objects: they are saved together or, if any table or column is not found, not at all, and the response is `{ items: [...] }`. The text overrides the database''s own comment for AI tools; an empty description falls back to the comment again, and clearing both fields removes the entry. Omitted fields are kept. The table and column must exist in the schema the caller may see. Needs the connection owner or an admin, and a plan with the context layer. Available to API keys with the `write` scope.'
      operationId: update_context_descriptions
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /context/{connectionId}/export:
    get:
      tags:
      - Context
      summary: Export context
      description: 'Downloads a connection''s context as YAML in an open format. `format=ossie` (default) is an Apache Ossie semantic model (core spec 0.3.0.dev0): datasets and fields with descriptions and synonyms, notes for AI as `ai_context.instructions`, definitions with SQL as metrics, and anything Ossie has no slot for under a `SATURNSQL` extension. `format=dbt` is a dbt properties file: `layout=models` (default) lists tables as models with column descriptions and puts notes and definitions in a header comment; `layout=sources` declares the tables as a dbt source and keeps notes and definitions under its `meta`. Works on every plan. Available to API keys with the `read` scope.'
      operationId: get_context_export
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      - name: format
        in: query
        required: false
        description: ossie or dbt
        schema:
          type: string
      - name: layout
        in: query
        required: false
        description: 'For dbt: models or sources'
        schema:
          type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /context/{connectionId}/import:
    post:
      tags:
      - Context
      summary: Import an Apache Ossie model
      description: 'Reads an Apache Ossie semantic model (core spec 0.3.0.dev0, or the older `semantic_model` list) from a JSON body `{ yaml, apply? }` into the connection''s context. Datasets and fields are matched to tables and columns by name, or by the dataset''s `source`. Descriptions are replaced where the file has one, `ai_context` synonyms and field labels are added to the existing synonyms, the model''s description and `ai_context` become the description and notes for AI, and metrics become definitions, keeping the SQL for the connection''s dialect when the file has one. Nothing the file leaves out is changed or removed, and relationships are not stored. Without `apply: true` nothing is saved and the response is a preview: what would change, and the datasets and fields that matched nothing. Needs the connection owner or an admin, and a plan with the context layer. Available to API keys with the `write` scope.'
      operationId: create_context_import
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /context/{connectionId}:
    get:
      tags:
      - Context
      summary: Get context
      description: 'Returns a connection''s context layer: every table and column the caller may see, each with the description AI tools receive (`description`), whose text it is (`descriptionSource`: `database` for the database''s own comment, `saturnsql` for text written in SaturnSQL), both raw sources (`databaseDescription`, `saturnDescription`), synonyms and generated stats; plus the model `description`, notes for AI (`instructions`), definitions, and `orphans` (text whose table or column the schema no longer has). Stored context is returned on every plan so it can always be read and exported. Hidden tables and columns are left out for people under access rules. Available to API keys with the `read` scope.'
      operationId: get_context
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    patch:
      tags:
      - Context
      summary: Update notes for AI
      description: Sets the connection's notes for AI tools (`instructions`, e.g. "Amounts are in cents. Use orders_v2, not orders.") and/or its `description`, as a JSON body with either field. An empty string clears it. Needs the connection owner or an admin, and a plan with the context layer. Every change is recorded with who made it and from where. Available to API keys with the `write` scope.
      operationId: update_context
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /context/{connectionId}/summary:
    get:
      tags:
      - Context
      summary: Get context for AI
      description: 'The short form of a connection''s context for an AI tool: notes for AI, definitions, and only the tables and columns that carry a description or synonyms, with SaturnSQL''s text in place of the database''s comment where both exist. Pass `intent` to narrow tables and definitions to the ones that mention it; matched tables then list all their columns. Without a plan that includes the context layer, only the database''s own comments are returned. Available to API keys with the `read` scope.'
      operationId: get_context_summary
      parameters:
      - name: connectionId
        in: path
        required: true
        schema:
          type: string
      - name: intent
        in: query
        required: false
        description: What the caller wants to answer, e.g. "revenue by customer last month"
        schema:
          type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    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
  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.'