A typed SDK and a CLI

@pendral/docuflow covers every endpoint an API key can call, with request and response types generated from the API's own schemas. The docuflow CLI checks a key, follows the event log and forwards signed events to a handler on your machine.

TypeScript that uploads a document with @pendral/docuflow, waits until it needs review or is approved, then reads every field with its value, page, box and confidence. Below it, the CLI: npm install, docuflow whoami and docuflow events --follow.
intake.ts@pendral/docuflow 0.1.0
TypeScript
import { readFile } from "node:fs/promises";
import DocuFlow from "@pendral/docuflow";

const docuflow = new DocuFlow(); // reads DOCUFLOW_API_KEY

const { documents } = await docuflow.documents.upload({
  queueId: "q_prior_auth",
  files: [{ data: await readFile("fax-0412.pdf"), name: "fax-0412.pdf" }],
});

// Waits on the live event stream, then re-reads the document so nothing is missed.
await docuflow.documents.waitFor(documents[0]!.id, { status: ["needs_review", "approved"] });

// Every field with its value, page, box and confidence.
const { values, fields } = await docuflow.documents.fields.get(documents[0]!.id);
CLI
$ npm install @pendral/docuflow
$ npx docuflow whoami
$ npx docuflow events --events document.needs_review --follow

Types from the
API's own schemas

The request and response types are generated from the same schemas that validate requests on the server, so the SDK cannot drift from the API. List methods return the first page when awaited and every item when iterated, fetching the next page as you go. Any endpoint the SDK does not wrap yet is one raw call away.

Retries that never
make a second document

Every write carries an idempotency key, so a retried upload after a timeout returns the first answer instead of creating a duplicate. Pass your own key to make an operation idempotent across your own job runs. Errors arrive as typed classes: a plan limit names the plan and feature, a permission error names the permission the key lacks.

Webhooks verified
before your code runs

The SDK checks each webhook delivery's signature and timestamp, and unsigned, wrongly signed or stale deliveries never reach your handler. A handler that throws is retried. While you build, docuflow listen forwards the workspace's events to a local URL, signed exactly like real deliveries, so you never expose your machine to the internet.

Included

docuflow whoamiwhich key, which workspace, what it may do and its rate budget
docuflow eventsread the event log, and --follow to keep polling
docuflow listenforward signed events to a handler on your machine
docuflow tailprint live document progress as it happens
docuflow requestcall any endpoint with your key before writing code for it
docuflow openapiprint the OpenAPI document

The specifics

Package@pendral/docuflow on npm, ESM and CommonJS
RuntimesNode.js 20+, Bun, Deno, Vercel and Cloudflare Workers
Coverageevery endpoint an API key can call
Authenticationa dfk_ API key from DOCUFLOW_API_KEY or passed to the client
Docsthe SDK guide lists every method, option and error class

Wire DocuFlow into your systems this week

A working session on your own documents: one queue, your fields, your rules, and a count of what would have gone straight through.