ScalixScalix Docs
Sign up

Database API

Database API to run single and batch SQL queries, read query logs, and get anomaly detection, optimization, scaling, and natural-language-to-SQL help.

REST API endpoints for Database. 13 operations.

Detect database anomalies

plaintext
POST /api/v1/anomalies

Classifies the activity window YOU supply (query_rate, error_rate, avg_response_time_ms, connection_count — all required; audit 2026-10-21: the old description implied the service observed recent activity itself).

Auth: Bearer API key

Request body

application/json (required) — schema AnomalyDetectionRequest.

Body of POST /api/v1/anomalies — the caller supplies the activity window; the endpoint classifies it (the old description claimed it "analyzes recent activity" on its own). Mirrors anomaly::DatabaseMetrics.

FieldTypeRequiredDescription
query_ratenumber (double)YesObserved queries per second.
error_ratenumber (double)YesObserved error rate (0.0–1.0).
avg_response_time_msnumber (double)YesObserved average response time in milliseconds.
connection_countinteger (int64)YesObserved open connection count.

Responses

StatusDescription
200Anomaly report
401Missing or invalid API key
500Internal error

operationId: detectAnomalies

Translate natural language to SQL

plaintext
POST /api/v1/nl-to-sql

Generates a SQL statement from a natural-language description of the desired query.

Auth: Bearer API key

Responses

StatusDescription
200Generated SQL
401Missing or invalid API key
500Internal error

operationId: naturalLanguageToSql

Get query optimization suggestions

plaintext
POST /api/v1/optimize

Analyzes the SQL statement you supply (sql is REQUIRED — this is not a whole-database analyzer; audit 2026-10-21) and returns indexing and query optimization suggestions.

Auth: Bearer API key

Request body

application/json (required) — schema OptimizeQueryRequest.

Body of POST /api/v1/optimize — the advisory analyzes the GIVEN statement (the old description claimed it "analyzes the tenant's database"; sql is required and unknown fields are rejected). Mirrors server.rs OptimizeBody.

FieldTypeRequiredDescription
sqlstringYesThe SQL statement to analyze for index/rewrite advice.

Responses

StatusDescription
200Optimization suggestions
401Missing or invalid API key
500Internal error

operationId: optimizeQuery

List recent query logs

plaintext
GET /api/v1/query-logs/{tenant_id}

Returns recent query-log entries for a tenant, newest first.

Auth: Bearer API key

Parameters

NameInTypeRequiredDescription
tenant_idpathstringYesTenant id (UUID)
limitqueryinteger (int64)NoMax entries to return (default 100, max 1000)

Responses

StatusDescription
200Recent query log entries
401Missing or invalid API key
500Internal error

operationId: listQueryLogs

Get scaling suggestions

plaintext
GET /api/v1/scaling

Returns capacity and scaling recommendations for the tenant's database.

Auth: Bearer API key

Responses

StatusDescription
200Scaling suggestions
401Missing or invalid API key
500Internal error

operationId: getScalingSuggestions

Execute a SQL query

plaintext
POST /api/v1/sql

Runs a parameterized SQL statement against the tenant's database and returns the result set.

Auth: Bearer API key

Request body

application/json (required) — schema SqlRequest.

A parameterized SQL query to execute against the tenant's database.

FieldTypeRequiredDescription
querystringYesThe SQL statement, with $1, $2, … placeholders for params.
paramsobject | nullNoPositional bind parameters for the placeholders, in order.
timeline_idstring | nullNoBranch timeline to run the query against, as returned by scalix_db_branch_create (optionally in its db_<timeline> connection-string form). Omit for the project's primary. A timeline that is not a branch of this project is rejected — it never falls back to the primary (F17).

Responses

StatusDescription
200Query results
400Invalid SQL
401Missing or invalid API key
429Rate limit exceeded
500Internal error

operationId: executeSql

Execute a batch of SQL queries

plaintext
POST /api/v1/sql/batch

Runs multiple SQL statements in one request; each query executes independently and returns its own result set.

Auth: Bearer API key

Request body

application/json (required) — schema BatchSqlRequest.

A batch of SQL queries executed in one request (each runs independently).

FieldTypeRequiredDescription
queriesarray&lt;SqlRequest&gt;Yes

Nested schema — SqlRequest:

FieldTypeRequiredDescription
querystringYesThe SQL statement, with $1, $2, … placeholders for params.
paramsobject | nullNoPositional bind parameters for the placeholders, in order.
timeline_idstring | nullNoBranch timeline to run the query against, as returned by scalix_db_branch_create (optionally in its db_<timeline> connection-string form). Omit for the project's primary. A timeline that is not a branch of this project is rejected — it never falls back to the primary (F17).

Responses

StatusDescription
200Array of query results
401Missing or invalid API key
500Internal error

operationId: batchSql

List databases

plaintext
GET /v1/databases

Lists the project's databases. include_deleted=true also returns soft-deleted databases still inside the recovery grace window.

Auth: Bearer API key

Parameters

NameInTypeRequiredDescription
include_deletedquerybooleanNoAlso return soft-deleted databases restorable within the grace window

Responses

StatusDescription
200Databases in the project
401Missing or invalid API key

operationId: listDatabases

Create a database

plaintext
POST /v1/databases

Creates a ScalixNova database in the project on the requested PostgreSQL major version (16 default, 17, or 18). The version is fixed at creation; branches and point-in-time restores keep it.

Auth: Bearer API key

Request body

application/json (required) — schema CreateDatabaseRequest.

Request to create a ScalixNova database.

FieldTypeRequiredDescription
namestringYesDisplay name, unique within the org.
pg_versionstring | nullNoPostgreSQL major version: "16" (default), "17", or "18". Accepts a string or number. Fixed for the life of the database — branches and point-in-time restores keep this major. Unsupported values return 400 listing the supported set.
isolationstring | nullNoIsolation tier: "shared" (default) or "dedicated" (Firecracker microVM; PostgreSQL 16 only, returns 501 where the tier isn't provisioned).

Responses

StatusDescription
201Database created
400Invalid name, isolation, or pg_version (message lists the supported versions)
401Missing or invalid API key
409A database with this name already exists in the org
501Dedicated tier not provisionable on this deployment

operationId: createDatabase

Delete a database

plaintext
DELETE /v1/databases/{id}

Soft-deletes the database: it is hidden from listings and restorable via POST /v1/databases/{id}/restore until the grace window ends, after which it is purged permanently.

Auth: Bearer API key

Parameters

NameInTypeRequiredDescription
idpathstringYesDatabase id

Responses

StatusDescription
202Database scheduled for deletion (async teardown; the row enters its recovery grace window)
401Missing or invalid API key
404Database not found

operationId: deleteDatabase

Get a database

plaintext
GET /v1/databases/{id}

Fetches one database by id, including its PostgreSQL version and isolation tier.

Auth: Bearer API key

Parameters

NameInTypeRequiredDescription
idpathstringYesDatabase id

Responses

StatusDescription
200The database
401Missing or invalid API key
404Database not found

operationId: getDatabase

Restore a soft-deleted database

plaintext
POST /v1/databases/{id}/restore

Undoes a delete within the recovery grace window; the database returns to active with its data, version, and tier intact.

Auth: Bearer API key

Parameters

NameInTypeRequiredDescription
idpathstringYesDatabase id

Responses

StatusDescription
200Database restored to active
401Missing or invalid API key
404Database not found or past the grace window

operationId: restoreDatabase

Get or create the project's default database

plaintext
POST /v1/databases/provision

Idempotent: returns the project's default database connection info, creating the database (on the default PostgreSQL version) if none exists.

Auth: Bearer API key

Responses

StatusDescription
200Connection info for the project's default database
401Missing or invalid API key

operationId: provisionDatabase