Connecting Claude, ChatGPT or Cursor? Use the hosted MCP server at
https://mcp.saturnsql.com/mcp instead of this API. Your assistant signs in with your SaturnSQL account, so there is no key to paste. See the
MCP connector setup. This API is for scripts, CI jobs and your own integrations.
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.
Read-only enforcement. Execution is guarded so an agent cannot mutate data: only SELECT, WITH (CTEs) and EXPLAIN are accepted, one statement at a time, and write / DDL / admin verbs (INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, TRUNCATE, GRANT, EXEC, SELECT … INTO, …) are rejected. Connections flagged read-only are additionally enforced at the driver level. Design agent prompts around exploration and reporting, not mutation.
Insight-query patterns
Once the schema is known, these read-only patterns surface useful insights on almost any database — adapt table and column names from step 2:
- Shape & volume —
SELECT count(*) FROM <table>; row counts per table to find the big / active ones.
- Distributions —
SELECT <dim>, count(*) n FROM <table> GROUP BY <dim> ORDER BY n DESC LIMIT 20 for top categories, statuses, plans.
- Trends over time —
SELECT date_trunc('month', <ts>) m, count(*) FROM <table> GROUP BY 1 ORDER BY 1 for growth and seasonality.
- Data-quality audit — null / blank counts per column, duplicate keys, orphaned foreign keys.
- Cohorts & funnels — first-seen vs last-seen per entity, step-to-step conversion with
WITH CTEs.
Run EXPLAIN first on unfamiliar or large tables, and keep a LIMIT on ad-hoc SELECTs.
4. Save the good ones (optional, write scope)
Persist a query the user will want again, optionally filed into a folder with folderPath (null = root):
curl -s https://saturnsql.com/api/queries \
-H 'Authorization: Bearer sat_live_...' \
-H 'Content-Type: application/json' \
-d '{"name":"Signups by month","sql":"SELECT ...","connectionId":"CONNECTION_ID","folderPath":"Growth"}'
Browse queries the team already trusts with GET /queries, and recent runs with GET /queries/history, to reuse rather than reinvent. (Sharing a query company-wide is a plan-gated action available in the web app, not over an API key.)
5. A saved query is also a report page
Every saved query is readable at https://saturnsql.com/app/report/{id} — the result as a table, with a chart above it when the shape allows one. With no chart pinned (the only case an API key can produce), the shape decides:
- 1 date/timestamp column + 1–3 numeric columns → line / area
- no date column + exactly 2 numeric columns → scatter
- no date column + 1 text column (2–12 values) + 1 numeric → bar
- anything else, including a 4th numeric column → table only
So keep the numeric columns to three and the date columns to one; emit the rest as text. Rows plot in result order, so a time series needs ORDER BY <time> ASC.
Pinning a chart (PUT /queries/{id}/chart) is session-token, owner-only. Save the query, hand over the link, and leave that to the web app.
Limits & errors
- Query quota — each company has a monthly execution quota; exceeding it (or hitting the rate limit) returns
429 with usage / limit details.
- Errors — non-2xx responses return
{ "error": "..." }: 400 validation, 401 bad or missing credential, 403 insufficient scope, 404 unknown connection or query.
Guide: Using SaturnSQL with AI coding agents.
Context
PATCH/context/{connectionId}/definitions/{definitionId}
Update a definition
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
| definitionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
DELETE/context/{connectionId}/definitions/{definitionId}
Delete a definition
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
| definitionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
GET/context/{connectionId}/definitions
List definitions
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
POST/context/{connectionId}/definitions
Create or replace a definition
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
PUT/context/{connectionId}/descriptions
Set a table or column 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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
GET/context/{connectionId}/export
Export context
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
| format | string | No | ossie or dbt |
| layout | string | No | For dbt: models or sources |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
POST/context/{connectionId}/import
Import an Apache Ossie model
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
GET/context/{connectionId}
Get context
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
PATCH/context/{connectionId}
Update notes for AI
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error
GET/context/{connectionId}/summary
Get context for AI
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.
Parameters
| Name | Type | Required | Description |
|---|
| connectionId | string | Yes | — |
| intent | string | No | What the caller wants to answer, e.g. "revenue by customer last month" |
Responses
200 — Success400 — Bad Request401 — Unauthorized500 — Internal Server Error