Submit a cross-tenant query
POST /query-all
Runs the same SQL query across all warehouse tenant databases (or a
specified subset) and combines results with a _bucket column. Returns
a job ID for async polling.
Supports two modes:
- SQL mode: provide
sqlwith a read-only query - NL mode: provide
question— SQL is generated once via MotherDuck’sprompt_sql()against the first database, then executed across all databases
The query is wrapped in SELECT * FROM (...) LIMIT {limit} per
database. Results are combined and stored in DynamoDB. Poll via
GET /query-all/jobs/{jobId}.
Cost note: Each invocation runs ~1 USE + 1 query per database (~260 MotherDuck operations for all tenants).
Authorizations
Section titled “Authorizations ”Request Body required
Section titled “Request Body required ”Provide either sql or question, not both. Optional buckets array
limits which databases are queried.
object
Read-only SQL to execute against each database.
Example
SELECT count(*) as total FROM personNatural language question (generates SQL via prompt_sql).
Example
total payments by currency for januarySpecific bucket IDs to query. If omitted, queries all warehouse databases. Bucket names with hyphens are converted to underscores for database matching.
Example
[ "example", "jec", "rrec"]Maximum rows returned per database.
Skip databases missing this table. Useful when querying tables that may not exist in all tenant databases.
Example
paymentExamples
Count people across all tenants
{ "sql": "SELECT count(*) as total FROM person"}Query specific buckets
{ "sql": "SELECT count(*) as total FROM person WHERE lower(first_name) = 'bob'", "buckets": [ "example", "jec", "rrec", "oxpip" ]}Natural language query
{ "question": "total payments by currency for january"}Skip databases missing a table
{ "sql": "SELECT count(*) FROM payment", "table": "payment"}Responses
Section titled “ Responses ”Job submitted successfully
object
object
Example
503a73be-9119-43ba-8e30-4f278f978d49Example
processingInvalid request
object
object
Machine-readable error code.
Example
unauthorizedHuman-readable error message.
Example
Authentication requiredExample
{ "error": { "code": "bad_request", "message": "Missing 'sql' field" }}Authentication required
object
object
Machine-readable error code.
Example
unauthorizedHuman-readable error message.
Example
Authentication requiredExample
{ "error": { "code": "unauthorized", "message": "Authentication required" }}Access denied to bucket
object
object
Machine-readable error code.
Example
unauthorizedHuman-readable error message.
Example
Authentication requiredExample
{ "error": { "code": "forbidden", "message": "Access denied to bucket 'example'" }}