API Reference
Errors & Diagnostics
Comprehensive dictionary of HTTP status codes, gateway error codes, and PostgreSQL SQLSTATE diagnostics.
Error Codes & Diagnostics Reference
When a request fails, the gateway returns a standard error envelope:
{
"success": false,
"error": {
"code": "INSUFFICIENT_PRIVILEGE",
"message": "permission denied for table secret_accounts",
"pgCode": "42501"
}
}Gateway Error Code Directory
| HTTP Status | Gateway Error Code | Cause | Resolution |
|---|---|---|---|
400 | INVALID_QUERY_TYPE | type was neither "sync" nor "async". | Use "sync" or "async". |
400 | INVALID_DATABASE_SCOPE | Malformed database scope parameter. | Verify database scope array format. |
400 | INVALID_TABLE_SCOPE | Malformed table scope parameter. | Use ["schema.table"] format. |
400 | DATABASE_SCOPES_REQUIRED | Updating an explicitly scoped key requires CRUD scopes. | Supply scope-database or scope-table. |
401 | UNAUTHORIZED | Missing or invalid API key or admin password. | Verify x-api-key or x-admin header. |
401 | API_KEY_SCOPE_REBIND_REQUIRED | Key requires re-binding after schema or permission change. | Send PATCH /admin/keys/:id to refresh bindings. |
403 | INSUFFICIENT_PRIVILEGE | PostgreSQL denied SQL execution to the key's role. | Check key's CRUD scopes for the targeted table. |
403 | DATABASE_SCOPE_CHANGED | The database identity differs from key's stored binding. | Rebind key using PATCH /admin/keys/:id. |
404 | QUERY_NOT_FOUND | Async query ID does not exist for this key and database. | Check query ID or wait for creation. |
404 | TRANSACTION_NOT_FOUND | Transaction ID does not exist. | Check transaction ID. |
404 | TABLE_NOT_FOUND | A table in the requested scope does not exist. | Verify table name in PostgreSQL schema. |
409 | IDEMPOTENCY_KEY_CONFLICT | Reusing an Idempotency-Key with different SQL/params. | Use a new unique idempotency key. |
409 | QUERY_IN_PROGRESS | Attempted to delete a query that is currently running. | Wait for query to finalize before deleting. |
409 | TRANSACTION_IN_PROGRESS | Attempted to delete an active transaction batch. | Wait for transaction to finalize. |
409 | UNSAFE_DATABASE_SCOPE | PostgreSQL inherited/PUBLIC grants conflict with scope. | Revoke CONNECT and CREATE from PUBLIC. |
409 | DATABASE_IN_USE | Database is currently undergoing maintenance. | Retry after maintenance finishes. |
410 | TRANSACTION_RECORD_REMOVED | Keyed transaction was pruned or deleted (tombstone exists). | Generate a new transaction and idempotency key. |
413 | TRANSACTION_QUEUE_LIMIT_EXCEEDED | Exceeded 100 statements or 256 KiB queue size. | Split into smaller transaction units. |
413 | RESULT_LIMIT_EXCEEDED | Result exceeded 50,000 rows or ~8 MiB limit. | Add LIMIT or use pagination. |
422 | DATABASE_VERSION_UNSUPPORTED | Operation requires a newer PostgreSQL version (e.g. PG15+). | Upgrade PostgreSQL server version. |
429 | TRANSACTION_LIMIT_EXCEEDED | Process transaction memory limit reached (1,000 txs). | Complete or delete old pending transactions. |
429 | RATE_LIMIT_EXCEEDED | Request rate exceeded per-minute or per-IP limit. | Inspect Retry-After header and back off. |
500 | QUERY_OUTCOME_UNKNOWN | SQL was sent to PostgreSQL but result was lost. | Check error.cause. Verify application state! |
503 | QUERY_POOL_BUSY | Pool was saturated after waiting checkout timeout. | Increase pool size or reduce query concurrency. |
503 | QUERY_CONNECTION_LIMIT | Global process query budget reached (maxGlobalQueries). | Increase database.pool.maxGlobalQueries. |
503 | QUERY_POOL_WAIT_TIMEOUT | No connection became available within checkout deadline. | Check PostgreSQL server load and locks. |
503 | QUERY_DATABASE_UNAVAILABLE | Database connection could not be opened or verified. | Verify PostgreSQL connection string and server health. |
503 | QUERY_QUEUE_FULL | Concurrent async query limit reached (32 per process). | Wait for active async queries to finish. |
503 | QUERY_STORE_UNAVAILABLE | Could not write to persistent async query storage table. | Check PostgreSQL administrator connection. |
503 | ANALYTICS_UNAVAILABLE | SQLite analytics worker is stopped or restarting. | Check analytics file permissions. |
504 | EXECUTION_DEADLINE_EXCEEDED | Query or transaction exceeded its deadline. | Optimize SQL or increase timeouts. |
PostgreSQL SQLSTATE Diagnostics
When PostgreSQL returns an error, the gateway populates error.pgCode with the standard 5-character SQLSTATE:
| SQLSTATE | PostgreSQL Error Name | Common Cause |
|---|---|---|
42501 | insufficient_privilege | Key role lacks SELECT, INSERT, UPDATE, or DELETE. |
42P01 | undefined_table | Table name misspelled or schema not in search path. |
42703 | undefined_column | Column name does not exist. |
23505 | unique_violation | Primary key or unique constraint violation. |
23503 | foreign_key_violation | Referenced foreign key does not exist. |
23502 | not_null_violation | Required non-null column missing a value. |
57014 | query_canceled | Cancelled by statement_timeout (30s default). |
40001 | serialization_failure | Concurrent conflict in serializable transaction mode. |
40P01 | deadlock_detected | Two transactions locked rows in opposing order. |
Detailed Error Fields
In addition to code and pgCode, immediate PostgreSQL errors include:
severity: Error severity level (ERROR,FATAL).schema: Targeted schema name.table: Targeted table name.column: Targeted column name (for constraint violations).constraint: Name of the violated constraint.position: Character position of the syntax error in the SQL string.
PostgreSQL's
detail and hint fields are null by default because they may quote sensitive literal data values. In trusted internal environments, enable them with database.exposeErrorDetails: true in gateway.yaml.