Node.js & TypeScript
@thunderduck-io/client is the official TypeScript client for the Thunderduck
REST API. It works on Node 18 and later, and on Bun or Deno — anything with
fetch. Zero runtime dependencies, with ESM, CommonJS and type declarations.
Source, issues and the license are in the thunderduck-node repository on GitHub .
npm install @thunderduck-io/clientThe package is published on npm as
@thunderduck-io/client.
Connect
Create an API token in the console (Settings → API tokens; it is shown once), then:
import { Thunderduck } from "@thunderduck-io/client";
const td = new Thunderduck({ token: process.env.THUNDERDUCK_TOKEN! });
const { columns, rows } = await td.query(
'select * from "sales_pg"."public"."orders" limit 10',
);
for (const row of rows) console.log(row);The client defaults to https://api.thunderduck.ai and refuses to construct
without a token.
Querying
query() submits the SQL, waits for the run to finish, and returns the whole
result:
const result = await td.query("select * from lake.default.events", {
timeoutMs: 600_000,
maxRows: 10_000,
});
console.log(result.columns, result.total, result.rows);For results too large to buffer, iterate() yields pages instead:
for await (const batch of td.iterate("select * from lake.default.events", {
pageSize: 10_000,
})) {
console.log(`${batch.offset + batch.rows.length} / ${batch.total}`);
}If you already have a run going, submit(), awaitExecution(id) and
resultPage(id, { limit, offset }) are the separate steps. cancel(id) stops
a run; an unknown or already-finished run is not an error.
Catalog
const { catalogs } = await td.catalogSchema();
for (const catalog of catalogs) {
console.log(catalog.name, catalog.type);
}This reads metadata Thunderduck already collected and runs no SQL. Two-level
catalogs (Iceberg/Nessie) put tables on the catalog; three-level catalogs put
namespaces, each with its own tables.
Downloads
Results are stored as Parquet. downloadUrl(id) mints a short-lived presigned
URL, and download(id) fetches it for you:
import { createWriteStream } from "node:fs";
import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";
const response = await td.download(executionId);
await pipeline(Readable.fromWeb(response.body!), createWriteStream("rows.parquet"));The download request never carries your API token — the presigned URL authenticates itself.
Errors
Every error extends ThunderduckError, which carries status and the server’s
detail:
import {
ThunderduckAuthError,
ThunderduckQueryError,
ThunderduckResultExpiredError,
} from "@thunderduck-io/client";
try {
await td.query("select * from lake.default.events");
} catch (error) {
if (error instanceof ThunderduckAuthError) {
// missing, expired or rejected token: create a new one
} else if (error instanceof ThunderduckResultExpiredError) {
// the stored result aged out: re-run
} else if (error instanceof ThunderduckQueryError) {
console.error(error.message); // the engine's message
}
}ThunderduckNoAccessError means the token authenticated but the account has
not signed in to the console yet (or is suspended). ThunderduckTimeoutError
means the wait or a request hit its deadline. Every call accepts { signal }
for cancellation.
Limits
- Each query runs as a job, so expect seconds before the first row. Don’t use it for tight request/response loops.
- Statements are read-only: no DML, no DDL, no transactions.
- Stored results expire. Keep the execution id if you need to page a result
again later, and expect a
ThunderduckResultExpiredErroronce it does. - The server caps page size and stored result size. Aggregate in SQL rather than pulling raw rows.
- Redirects are followed within the API origin only; a redirect elsewhere is refused rather than sent your token.