Install the package
Install from npm. You need Node 22 or newer, npm, version 0.18.122 or newer of the SDK, and a Transform API key. Run this command from your project directory:Set your API key
In zsh, export your key before running a script:Parse a document synchronously
SetUNSTRUCTURED_API_KEY to your API key and save your input as document.pdf. Use Node 22 or newer.
To try the example without your own file, download the ACME Corp Annual Report sample PDF and save it as document.pdf in your project directory.
Save this example as parse.mjs. These examples use JavaScript syntax with the TypeScript SDK, so Node can run them directly.
node parse.mjs from the project directory in the shell where you exported your key.
The call waits up to 30 seconds and prints the completed result or pending job handle. Follow request progress for a pending job. A completed Parse contains Markdown by default; no output options are required.
If you omit apiKey, the TypeScript SDK reads UNSTRUCTURED_API_KEY from the environment.
The client defaults to https://transform.unstructured.io. Pass serverUrl only when you target a different deployment.
Process a directory
To parse each file in a directory and save one response per file, see Process a directory.Extract fields next
To extract structured fields, follow Chain Parse and Extract. That guide defines a schema and reuses a completed Parse ID.Handle long-running requests
If you omitwaitSeconds, the parse.run, extract.run, and extract.fromDocument methods wait until the job finishes. They return the job’s result, however long the job takes. You don’t need to raise timeoutMs for long jobs. If the job fails, the call throws an error. To stop waiting, pass an AbortSignal as signal. Stopping does not cancel the server job.
Set waitSeconds: 0 to receive a pending job handle immediately. Then poll the job, as the following examples show. Any other waitSeconds value waits at most that long and returns either the result or a pending job handle. Keep that value shorter than timeoutMs, which defaults to 60,000 milliseconds. On Node, also keep it at 240 seconds or less, because built-in fetch stops waiting for response headers after 300 seconds. See wait behavior and request progress.
Retrieve an asynchronous Parse
SetwaitSeconds: 0 on client.parse.run to receive a pending job handle. Server-side asynchronous processing is separate from JavaScript promises: await waits for that response, not for the document to finish processing.
Save this complete example as parse-async.mjs and run node parse-async.mjs with your API key set and document.pdf in the project directory:
output: "elements", pass it to jobs.get too and read job.result.elements after success.
Poll an accepted extraction
Use the current Transform SDK release. Replaceyour-completed-parse-id with a completed Parse ID. The example schema requests an invoice number; adapt it using the schema guide.
job.result.extractedData.
Iterate over jobs
iterate follows cursors and yields individual jobs. Use jobs.list() when you need one page at a time.
Filter by operation, read the count across all matching pages, and iterate over every matching job:
totalCount is null when the server cannot count matching jobs. An older server might omit the field.
Configure retries
Addretries when creating your client:
retries: false to disable retries. The client uses backoff for eligible transient failures. A submission that might already have created a job is not retried after a read timeout or server response, to avoid duplicate jobs.
See Chain Parse and Extract for a complete sequence that passes the Parse ID into Extract.
