transform-results. Use the sequential example to test two or three files. For larger directories, use the asynchronous example, which submits up to three files at a time and can resume unfinished jobs after an interruption.
Each job tracks one document until processing finishes. The asynchronous example saves each filename, job ID, status, output name, and error so a rerun can continue unfinished work.
Set UNSTRUCTURED_API_KEY in your zsh session and install the Python SDK or TypeScript SDK before running an example. The examples use the SDK’s default Transform API endpoint.
The
documents list includes every file directly under the input directory. If the directory contains unrelated files, filter that list to the file types you want to process before calling Extract.- Python
- TypeScript
Process files sequentially
Save this asextract_directory.py. Pass a directory as the first argument. If you omit it, the script reads from Documents:Process files asynchronously
Use this workflow for larger directories or when you may need to stop and resume. It submits up to three files at a time, saves state before and after submission, polls every 30 seconds, and writes each result once. A rerun reuses saved job IDs and skips completed files.The API does not publish request-rate or concurrent-job limits. See supported files and limits, and follow recovery guidance if a request returnsrate_limited or quota_exceeded.Save this as extract_directory_async.py. Pass a directory as the first argument. If you omit it, the script reads from Documents:wait_seconds=0 returns a job handle immediately. The state file records each handle before polling. If the process stops while polling or the connection fails, rerunning the command uses the saved job IDs instead of submitting completed files again. A job with status failed or cancelled stays in the state file with its error so you can inspect it or rerun with --retry-failed.An interruption during submission can leave a record as submitting without a job ID. A request error can leave it as submission_unknown. The script does not retry either state automatically because the API may already have accepted the document.To recover either state:- Stop all copies of the script. In the selected input directory, open
transform-results/.extract-state.json(for example,./Documents/transform-results/.extract-state.json). - Check your job history for the document and submission time. If you identify the accepted job, add its ID as
job_idand change the record’sstatustoqueued. Keep the other fields. - If you confirm that no job was accepted, change the record’s
statustoreadyand remove anyjob_id. The next run submits the document again. - Save the state file and rerun the command. If you cannot confirm whether a job was accepted, leave the record unchanged and investigate before retrying. Retrying an uncertain submission can create a duplicate job.

