Skip to main content

Document Processing

The document processing API extracts structured content from uploaded files. You can process documents asynchronously (submit a job, poll for results) or synchronously (block until done). This guide covers both workflows, plus streaming trace events for real-time progress.

Parse a document (async)

Submit a document for asynchronous parsing. The API returns a job ID immediately so your application stays responsive while the server processes the file.
Store the job_id from the response to check status, retrieve results, and stream trace events.

Poll for status

Check the processing status of a submitted document job. Poll until the status reaches "completed" or "failed".
A 2-second polling interval is recommended. For long-running jobs, consider using the streaming trace endpoint instead.

Get results

Once processing is complete, retrieve the extracted content in markdown or structured JSON format.
The markdown format returns a clean, readable representation of the document. The json format returns structured data including headings, tables, and extracted metadata.

Process synchronously

For smaller documents where you want the result in a single call, use the synchronous endpoint. It blocks until processing completes and returns the result directly.
The synchronous endpoint is best for small files (under 10 MB). For larger documents, use the async workflow with polling or trace streaming.

List child documents

Some documents (e.g., archives, multi-part files) produce child documents during processing. List them by job ID.

Stream trace events

Stream real-time processing events for a document job. Trace events provide fine-grained progress updates such as page extraction, OCR steps, and content classification.
Trace events are delivered as Server-Sent Events (SSE). In Python, each event is an SSEEvent with an .event name and a .data payload; call event.json() to parse the payload into a dict. In TypeScript, each event is the already-parsed payload object. The stream ends with a terminal event once processing completes.