Node.js SDK
Updated
Install#
npm install @docxtract/sdk
Node 18+. No dependencies — native fetch, FormData, and AbortSignal.timeout. TypeScript types ship with the package; no build step and no @types install.
Extract a document#
import { DocXtract } from '@docxtract/sdk';
const dx = new DocXtract(process.env.DOCXTRACT_API_KEY);
const result = await dx.extract('invoice.pdf', { model: 'invoice' });
console.log(result.data.vendor);
console.log(result.get('line_items.0.hsn'));
sk_). A hyphen means the key is from a
different API provider; the SDK rejects it immediately rather than letting you debug a 401.Large PDFs#
A PDF over 3 pages returns 202 and requires the multi-page flow. extract() handles it:
const result = await dx.extract('500-page-statement.pdf', { model: 'bank_statement' });
Same call, any page count. Progress callback:
await dx.extract('big.pdf', { model: 'invoice' }, (done, total) => console.log(`${done}/${total}`));
Chunks run sequentially by design — the default rate limit is 10 requests per minute, so parallel calls only produce 429s.
Error handling#
import { RateLimitError, QuotaError, DocXtractError } from '@docxtract/sdk';
try {
await dx.extract('invoice.pdf', { model: 'invoice' });
} catch (err) {
if (err instanceof RateLimitError) await sleep((err.retryAfter ?? 30) * 1000);
else if (err instanceof QuotaError) return; // out of credits
else if (err instanceof DocXtractError && err.retryable) requeue();
else throw err;
}
retryable is conservative: input errors, expired jobs, and exhausted credits are all false. See Error codes for the full mapping.
Discovering document types#
await dx.models(); // costs no credits
Configuration#
| Option | Default | Notes |
|---|---|---|
apiKey | — | Required |
baseUrl | https://api.docxtract.io | No /api prefix |
basePath | /v3.1 | /v3 only if pinned to the old version |
timeout | 120000 | Milliseconds per request |
maxRetries | 3 | Retryable errors only |
chunkPauseMs | 0 | Pace chunk calls on tight rate limits |
Pre-flight validation runs locally: a bad file type or oversized file fails before any request, costing no round trip and no credits.
Full reference#
sdk/node/README.md in the platform repository.
Something wrong or missing on this page? Tell us.