Skip to main content
The TypeScript SDK lets you parse documents and extract fields without building HTTP requests by hand.

Install the package

Install from npm. You need Node 22 or newer, npm, version 0.18.19 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:
Keep your key out of source control and shared scripts.

Parse a document synchronously

Set UNSTRUCTURED_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.
Run node parse.mjs from the project directory in the shell where you exported your key. The call waits for processing to finish and prints the returned response. 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.

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 omit waitSeconds, the call waits for the result in the original request. Set waitSeconds to request a bounded wait, or use zero to return a pending job without waiting. See wait behavior and request progress for HTTP 200, HTTP 202, and timeout handling.

Retrieve an asynchronous Parse

Set waitSeconds: 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:
The two-second delay is an example polling interval, not a server requirement. Stop the script to stop polling; this does not cancel the server job. Keep the job ID to resume retrieval. If you request 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. Replace your-completed-parse-id with a completed Parse ID. The example schema requests an invoice number; adapt it using the schema guide.
The two-second delay is an example polling interval, not a server requirement. Keep the job ID to resume retrieval. Check the final status before using job.result.extractedData.

Iterate over jobs

iterate follows cursors and yields individual jobs. Use jobs.list() when you need one page at a time.

Configure retries

Add retries when creating your client:
Pass 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.