Docs
API Reference

SQL over HTTP

Run SQL statements against a database directly over HTTP, without a persistent Postgres connection.

The SQL endpoint runs SQL against a database directly over HTTP. It's a good fit for serverless functions and edge environments where opening a persistent Postgres connection is awkward, and for quick one-off queries from any HTTP client.

The API is stabilizing. The request and response shapes below reflect the current interface; field-level details may still change before general availability.

Run a query

POST /v1/sql/{database_id}

Send a SQL statement and optional bound parameters. Parameters use PostgreSQL's $1, $2, … placeholders.

Terminal
curl -X POST https://api.silos.sh/v1/sql/db_abc123 \
  -H "Authorization: Bearer $SILOS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "select id, email from users where id = $1",
    "params": [123]
  }'
Response
{
  "rows": [
    { "id": 123, "email": "ada@example.com" }
  ],
  "row_count": 1
}

Request fields

FieldTypeDescription
querystringThe SQL statement to run. Required.
paramsarrayPositional parameters bound to $1, $2, … Optional.
optionsobjectOptional execution options (see below).

Options

FieldTypeDescription
timeout_msnumberMaximum time to wait for the query, in milliseconds.
row_limitnumberCap on the number of rows returned.
Terminal
curl -X POST https://api.silos.sh/v1/sql/db_abc123 \
  -H "Authorization: Bearer $SILOS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "select * from events order by created_at desc",
    "options": { "timeout_ms": 30000, "row_limit": 1000 }
  }'

Parameterize to stay safe

Always pass user-supplied values through params rather than concatenating them into the query string. This uses PostgreSQL's bound-parameter handling and avoids SQL injection.

Terminal
# Good — value is bound as a parameter
-d '{ "query": "select * from users where email = $1", "params": ["ada@example.com"] }'

Never interpolate untrusted input directly into the query string. Use params for every value that comes from outside your code.

When to use SQL over HTTP

Serverless & edge

No connection pool to manage — each request is a stateless HTTP call.

One-off queries

Quick reads and writes from scripts or any HTTP client.

Agent workloads

Lightweight query access for automated workflows that create and tear down databases.

For interactive sessions, long transactions, or high-throughput workloads, connect over the standard PostgreSQL wire protocol instead — see Connecting and the CLI. A WebSocket SQL surface is also available for streaming use cases and is maturing alongside the rest of the API.

On this page