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 StatusGateway Error CodeCauseResolution
400INVALID_QUERY_TYPEtype was neither "sync" nor "async".Use "sync" or "async".
400INVALID_DATABASE_SCOPEMalformed database scope parameter.Verify database scope array format.
400INVALID_TABLE_SCOPEMalformed table scope parameter.Use ["schema.table"] format.
400DATABASE_SCOPES_REQUIREDUpdating an explicitly scoped key requires CRUD scopes.Supply scope-database or scope-table.
401UNAUTHORIZEDMissing or invalid API key or admin password.Verify x-api-key or x-admin header.
401API_KEY_SCOPE_REBIND_REQUIREDKey requires re-binding after schema or permission change.Send PATCH /admin/keys/:id to refresh bindings.
403INSUFFICIENT_PRIVILEGEPostgreSQL denied SQL execution to the key's role.Check key's CRUD scopes for the targeted table.
403DATABASE_SCOPE_CHANGEDThe database identity differs from key's stored binding.Rebind key using PATCH /admin/keys/:id.
404QUERY_NOT_FOUNDAsync query ID does not exist for this key and database.Check query ID or wait for creation.
404TRANSACTION_NOT_FOUNDTransaction ID does not exist.Check transaction ID.
404TABLE_NOT_FOUNDA table in the requested scope does not exist.Verify table name in PostgreSQL schema.
409IDEMPOTENCY_KEY_CONFLICTReusing an Idempotency-Key with different SQL/params.Use a new unique idempotency key.
409QUERY_IN_PROGRESSAttempted to delete a query that is currently running.Wait for query to finalize before deleting.
409TRANSACTION_IN_PROGRESSAttempted to delete an active transaction batch.Wait for transaction to finalize.
409UNSAFE_DATABASE_SCOPEPostgreSQL inherited/PUBLIC grants conflict with scope.Revoke CONNECT and CREATE from PUBLIC.
409DATABASE_IN_USEDatabase is currently undergoing maintenance.Retry after maintenance finishes.
410TRANSACTION_RECORD_REMOVEDKeyed transaction was pruned or deleted (tombstone exists).Generate a new transaction and idempotency key.
413TRANSACTION_QUEUE_LIMIT_EXCEEDEDExceeded 100 statements or 256 KiB queue size.Split into smaller transaction units.
413RESULT_LIMIT_EXCEEDEDResult exceeded 50,000 rows or ~8 MiB limit.Add LIMIT or use pagination.
422DATABASE_VERSION_UNSUPPORTEDOperation requires a newer PostgreSQL version (e.g. PG15+).Upgrade PostgreSQL server version.
429TRANSACTION_LIMIT_EXCEEDEDProcess transaction memory limit reached (1,000 txs).Complete or delete old pending transactions.
429RATE_LIMIT_EXCEEDEDRequest rate exceeded per-minute or per-IP limit.Inspect Retry-After header and back off.
500QUERY_OUTCOME_UNKNOWNSQL was sent to PostgreSQL but result was lost.Check error.cause. Verify application state!
503QUERY_POOL_BUSYPool was saturated after waiting checkout timeout.Increase pool size or reduce query concurrency.
503QUERY_CONNECTION_LIMITGlobal process query budget reached (maxGlobalQueries).Increase database.pool.maxGlobalQueries.
503QUERY_POOL_WAIT_TIMEOUTNo connection became available within checkout deadline.Check PostgreSQL server load and locks.
503QUERY_DATABASE_UNAVAILABLEDatabase connection could not be opened or verified.Verify PostgreSQL connection string and server health.
503QUERY_QUEUE_FULLConcurrent async query limit reached (32 per process).Wait for active async queries to finish.
503QUERY_STORE_UNAVAILABLECould not write to persistent async query storage table.Check PostgreSQL administrator connection.
503ANALYTICS_UNAVAILABLESQLite analytics worker is stopped or restarting.Check analytics file permissions.
504EXECUTION_DEADLINE_EXCEEDEDQuery 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:

SQLSTATEPostgreSQL Error NameCommon Cause
42501insufficient_privilegeKey role lacks SELECT, INSERT, UPDATE, or DELETE.
42P01undefined_tableTable name misspelled or schema not in search path.
42703undefined_columnColumn name does not exist.
23505unique_violationPrimary key or unique constraint violation.
23503foreign_key_violationReferenced foreign key does not exist.
23502not_null_violationRequired non-null column missing a value.
57014query_canceledCancelled by statement_timeout (30s default).
40001serialization_failureConcurrent conflict in serializable transaction mode.
40P01deadlock_detectedTwo 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.
Copyright © 2026