Protocol & Authentication
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 Group | Required Headers | Description |
|---|---|---|
GET /health | None | Public liveness probe. Exempt from rate limits. Returns {"status":"ok"}. |
/admin/* | x-admin | Gateway administrator password generated on first startup or configured in environment. |
/query, /transaction | x-api-key, x-database | Active 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-keyor standardAuthorization: <raw-key>(withoutBearerprefix). - Database:
x-databaseorx-db-name. - Query ID:
x-query-idorquery-idheader (or?queryId=...query parameter). - Transaction ID:
x-transaction-idortransaction-idheader (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
fieldsarray 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, andnumeric[]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: falseonly 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 STDINorCOPY TO STDOUTover JSON endpoints; these are rejected withCOPY_STREAM_UNSUPPORTED.
