API Reference

Protocol & Authentication

Base URL, authentication headers, request formatting, and serialization options.

API Overview & Authentication

The gateway exposes a JSON-based RESTful API over HTTP/1.1 and HTTP/2. The default local base URL is http://localhost:8080.

Always include the Content-Type: application/json header for requests with JSON bodies.


Authentication Schemes

The gateway uses header-based bearer authentication with role-based routing:

Endpoint GroupRequired HeadersDescription
GET /healthNonePublic liveness probe. Exempt from rate limits. Returns {"status":"ok"}.
/admin/*x-adminGateway administrator password generated on first startup or configured in environment.
/query, /transactionx-api-key, x-databaseActive scoped API key and target PostgreSQL database name.

Header Aliases

For flexibility with various HTTP client libraries and proxies, the gateway supports the following aliases:

  • API Key: x-api-key or standard Authorization: <raw-key> (without Bearer prefix).
  • Database: x-database or x-db-name.
  • Query ID: x-query-id or query-id header (or ?queryId=... query parameter).
  • Transaction ID: x-transaction-id or transaction-id header (or ?transactionId=... query parameter).

Standard Response Envelopes

Successful Response Envelope

{ "success": true, "data": { "database": "sales", "command": "SELECT", "rowCount": 2, "rows": [ {"id": 1, "name": "Enterprise Plan"}, {"id": 2, "name": "Startup Plan"} ], "fields": [ {"name": "id", "dataTypeID": 20}, {"name": "name", "dataTypeID": 25} ], "durationMs": 2.15 } }

When multiple SQL statements are executed in a single request, the response returns a results array ordered by statement.

Error Response Envelope

{ "success": false, "error": { "code": "INSUFFICIENT_PRIVILEGE", "message": "permission denied for table secret_accounts", "pgCode": "42501" } }

Result Serialization Options

Customize how results are encoded by passing an options object in the request body:

{ "query": "SELECT id, price, created_at FROM products", "options": { "arrayMode": false, "lossless": true, "fullResults": true } }

1. arrayMode (Default: false)

When true, rows are returned as arrays of values matching column order rather than key-value objects.

  • Preserves duplicate column names in SQL queries.
  • Reduces JSON payload size by omitting repetitive column keys.
  • The fields array follows the identical index order as each row.

2. lossless (Default: true)

JavaScript numbers are IEEE 754 double-precision floats, which lose precision for 64-bit integers (bigint) and exact fixed-point decimals (numeric / decimal).

  • When lossless: true (default):
    • numeric, decimal, and numeric[] are returned as exact decimal strings (e.g., "123456789.987654321").
    • Dates, timestamps, and intervals are returned as exact ISO strings.
    • Non-finite floating-point values (NaN, Infinity, -Infinity) are returned as strings.
    • JSON and JSONB columns are returned as serialized JSON text.
  • Set options.lossless: false only if you need raw driver conversions.

3. fullResults (Default: true)

When false, returns only the rows array directly inside data, omitting command, fields, and execution metadata while preserving the outer API response envelope.


Execution Budgets & Limits

  • Max Rows: Up to 50,000 rows per query response or transaction batch.
  • Max Memory: Up to approximately 8 MiB of result data and metadata per response.
  • Copy Streaming: The gateway does not support COPY FROM STDIN or COPY TO STDOUT over JSON endpoints; these are rejected with COPY_STREAM_UNSUPPORTED.
Copyright © 2026