Let's Build: document intelligence pipeline using Transloadit
Turn a PDF or DOCX document into a local JSON file containing its title, summary, and optional insights. This example combines document conversion with schema-guided AI extraction; you review the saved result against the original before using it elsewhere.
The downloadable TypeScript application runs outside this repository. It accepts one local document, sends it to Transloadit and an AI provider, and saves the response to a new output file. Use a synthetic or non-sensitive document that you have permission to upload for your first run. Processing is billed, including when you explicitly select Transloadit-provided AI test credentials.
What document intelligence really means
A document workflow can parse text, split pages, and extract structured fields. Those are separate operations: the application here sends PDFs directly to /ai/chat and converts DOCX files to PDF first. It does not run OCR or split documents into chunks.
The result is a starting point for review or indexing, rather than proof that every fact was extracted correctly. Its schema describes document insights, not invoice totals, line items, or confidence scores.
Setting up your TypeScript project
Follow the application's installation and access instructions from an empty, standalone directory outside an existing Node.js project or Yarn workspace. No private checkout or fixture download is needed; you supply your own PDF or DOCX. The shell examples use Bash.
The tested combination is Node.js 26.12.1, Yarn
4.12.0 through Corepack, @transloadit/node 4.14.0, zod 3.25.76, and zod-to-json-schema 3.25.2.
These are reproduction pins, not claims that they are the latest releases. Node 26 is a
maintained release line; keep security updates in
mind when adapting the example. Corepack is a separate prerequisite on Node 26: follow its
installation instructions if corepack is not
available. You also need cURL for the downloads.
The README installs the pinned packages and downloads both document-intelligence-pipeline/run.ts
and shared/runtime.ts. Keep those sibling directories together, because the program imports
../shared/runtime.ts. Its final --help command should work before you supply any credentials.
If setup fails, inspect the partial directory before retrying: the initial package.json creation
refuses to overwrite a file. Do not repeat it over an existing application.
Configure TRANSLOADIT_AUTH_KEY and TRANSLOADIT_AUTH_SECRET in the shell running the application,
as shown in the README. These authenticate your Transloadit Workspace. Keep them out of source
control and browser code. The program reads process environment variables and does not load an
environment file.
AI access is a separate choice. Either set TRANSLOADIT_AI_CREDENTIALS to the name of an existing
AI Credential containing an Anthropic key, or explicitly pass --test-credentials for billed
Transloadit-provided test keys. Select one mode. The program does not create or change credentials;
see the /ai/chat documentation for provider access and billing.
Step 1: Document parsing with OCR (optional)
The /document/ocr
Robot is useful when your separate workflow needs recognized
text or layout information from a PDF. This application instead uses the PDF input support of
anthropic/claude-sonnet-4-6, selected explicitly in its extraction Step.
For DOCX input, the /document/convert Robot produces the PDF sent to the model. Conversion and OCR serve different purposes; adding an OCR Step would require deciding how its output feeds your own extraction workflow.
Step 2: Document splitting
The /document/split Robot can select pages for a different workflow. The example below processes one whole file. Splitting a contract into independent requests can lose definitions or terms from other pages, so do not assume that combining per-page answers reproduces a whole document's meaning.
Step 3: Schema-driven data extraction with AI
The application exports example and documentInsightsSchema. Reuse these when inspecting or
adapting it instead of maintaining a second copy of its Instructions or schema. The extraction Step
uses format: 'json', a serialized JSON Schema, and result: true to expose the answer file.
title and summary are required strings. Optional fields are author, publication_date,
document_type, key_topics, and key_points. The document type, when present, is one of
whitepaper, report, contract, invoice, receipt, statement, or manual. An optional field
may be omitted; a required string can still be empty or factually wrong. Schema validation checks
shape, not truth.
Building a complete pipeline
Place a document at document.pdf in your reader directory, or change --input to its actual path.
Choose a writable output path that does not exist. With Workspace authentication already configured
and TRANSLOADIT_AI_CREDENTIALS unset, this command authorizes billed processing with test keys:
node document-intelligence-pipeline/run.ts --input ./document.pdf --output ./result.json --test-credentials
For an existing Anthropic AI Credential, set TRANSLOADIT_AI_CREDENTIALS as described above and
omit --test-credentials. The runner accepts a nonempty input of at most 20 MiB and downloads at
most 20 MiB of output. These are tutorial limits. It allows five minutes for the Assembly and a
separate 30-second result download; provider limits can still refuse a file within the local size
limit.
On success, the terminal prints Saved followed by the output path.
The input is unchanged, and result.json is a local file rather than a temporary result URL.
An existing output is refused before an Assembly is submitted. For sequential reruns, use another
destination; do not delete your previous result just to repeat a command.
Save this inspection script as inspect.ts beside package.json. It reads the saved output using
the same exported schema, rejects blank required text, and prints the two fields you should review:
import { readFile } from 'node:fs/promises'
import { documentInsightsSchema } from './document-intelligence-pipeline/run.ts'
const saved = JSON.parse(await readFile('./result.json', 'utf8'))
const insights = documentInsightsSchema.parse(saved)
if (!insights.title.trim() || !insights.summary.trim()) {
throw new Error('The title or summary is blank. Review the source and Assembly before retrying.')
}
console.log(insights.title)
console.log(insights.summary)
node inspect.ts
Check names, dates, quantities, and the summary's main assertions against your source. A report about repairing 12 bicycles with $240 of spare parts must not turn into a summary about selling bicycles or spending $24. The inspection script cannot make that factual judgment for you. Review optional fields in the JSON too, and keep sensitive results private.
If a run fails after printing an Assembly ID, inspect that Assembly in the Console before retrying. A timeout or interruption does not establish that remote processing stopped, and a failed run can still be billed. The runner disables SDK retries and removes its unfinished local output after a caught failure; it cannot guarantee cleanup after a forced termination. Inspect any leftover file before choosing a new destination.
Processing multiple document types
The runner accepts .pdf and .docx filenames, including uppercase extensions. The
/file/filter Robot routes files
with PDF MIME type directly to extraction; the other branch converts to PDF first. This does not
make every non-PDF format an accepted input to this CLI. Renaming a damaged file does not repair its
contents, and successful conversion does not establish an accurate summary.
Decide what to add beyond the local example
Run documents sequentially with distinct output filenames while evaluating results and costs. This CLI has no batch scheduler, review queue, or cloud-storage export. Before processing a collection, review current pricing and the Robot documentation.
Templates can make an adapted set of Assembly Instructions reusable. They are not required for this local run. Saving Instructions in a Template or adding storage does not by itself provide human review, access controls for your application, or a reliable extraction policy.
When to use this approach
This approach is useful when you want control over the conversion and extraction Steps in a file workflow and can supply the application around them. Compare a dedicated document AI product using your own documents if you need a packaged review experience or measured extraction quality. This small example does not establish feature parity or production readiness.
Ready to build?
Start with the application README and one non-sensitive document whose contents you know. Keep the saved JSON and your source together for review, then use the AI Robot docs to plan any changes to the extraction workflow.
