Skip to main content
The library is a lightweight TypeScript library you can use for parsing documents, classifying pages, extracting data, generating tables of contents, and splitting documents into sub-documents. The library is automatically generated from our API specification, ensuring you have access to the latest endpoints and parameters.

Install the Library

Set the API Key as an Environment Variable

To use the library, first generate an API key. Save the key to a .zshrc file or another secure location on your computer. Then export the key as an environment variable.
When initializing the client, the library automatically reads from the VISION_AGENT_API_KEY environment variable:
Alternatively, you can explicitly pass the API key when initializing the client:
For more information about API keys and alternate methods for setting the API key, go to API Key.

Use with EU Endpoints

By default, the library uses the US endpoints. If your API key is from the EU endpoint, set the environment parameter to eu when initializing the client.
For more information about using in the EU, go to European Union (EU).

Parse: Getting Started

The parse method converts documents into structured Markdown with chunk and grounding metadata. Use these examples as guides to get started with parsing with the library.

Parse Local Files

Use the document parameter to parse files from your filesystem. Pass the file as a read stream using fs.createReadStream().

Parse Remote URLs

Use the document parameter with fetch() to parse files from remote URLs (http, https).

Set Parameters

The parse method accepts optional parameters to customize parsing behavior. To see all available parameters, go to ADE Parse API. Pass these parameters directly to the parse() method.

Parse Jobs

The parseJobs resource enables you to asynchronously parse documents that are up to 1,000 pages or 1 GB. For more information about parse jobs, go to Parse Large Files (Parse Jobs). Here is the basic workflow for working with parse jobs:
  1. Start a parse job.
  2. Copy the job_id in the response.
  3. Get the results from the parsing job with the job_id.
This script contains the full workflow:

List Parse Jobs

To list all async parse jobs associated with your API key, run this code:

Work with Parse Response Data

Access all text chunks:
Filter chunks by page:
Get chunk locations:
Identify the chunk type for each chunk:

Extract: Getting Started

The extract method extracts structured data from Markdown content using extraction schemas. Use these examples as guides to get started with extracting with the library. Pass Markdown Content The library supports a few methods for passing the Markdown content for extraction:
  • Extract data directly from the parse response
  • Extract data from a local Markdown file
  • Extract data from a Markdown file at a remote URL: markdown: await fetch("https://example.com/file.md")
Pass the Extraction Schema The library supports a few methods for passing the extraction schema:

Extract from Parse Response

After parsing a document, you can pass the markdown string directly from the ParseResponse to the extract method without saving it to a file.

Extract from Markdown Files

If you already have a Markdown file (from a previous parsing operation), you can extract data directly from it. Use the markdown parameter with fs.createReadStream() for local Markdown files or with fetch() for remote Markdown files.

Extraction with Zod

Use Zod schemas to define your extraction schema in a type-safe way. Zod provides TypeScript type inference and runtime validation for your extracted data. To use Zod with the library, install zod:
After installing zod, run extraction with the library:

Extraction with JSON Schema (Inline)

Define your extraction schema directly as a JSON string in your script.

Extraction with JSON Schema File

Load your extraction schema from a separate JSON file for better organization and reusability. For example, here is the pay_stub_schema.json file:
You can pass the JSON file defined above in the following script:

Extract Nested Subfields

Define nested Zod schemas to extract hierarchical data from documents. This approach organizes related information under meaningful section names. Define nested schemas before the main extraction schema. Otherwise, the nested schemas will not be defined when referenced. For example, to extract data from the Patient Details and Emergency Contact Information sections in this Medical Form, define separate schemas for each section, then combine them in a main schema.

Extract Variable-Length Data with List Objects

Use Zod’s z.array() to extract repeatable data structures when you don’t know how many items will appear. Common examples include line items in invoices, transaction records, or contact information for multiple people. For example, to extract variable-length wire instructions and line items from this Wire Transfer Form, use z.array(DescriptionItemSchema) for line items and z.array(WireInstructionSchema) for wire transfer details.

Classify: Getting Started

The classify method classifies each page in a document by type. Provide your document and a list of classes, and the API assigns a class to each page. Use these examples as guides to get started with classifying with the library.

Classify Local Files

Use the document parameter to classify files from your filesystem. Pass the file as a read stream using fs.createReadStream().

Classify Remote URLs

Use the document_url parameter to classify files from remote URLs (http, https).

Set Parameters

The classify method accepts optional parameters to customize classification behavior. To see all available parameters, go to API.

Classify Output

The classify method returns a ClassifyResponse object with the following fields:
  • classification: Array of Classification objects, one per page, each containing:
    • class: The predicted class label, or 'unknown' if the page could not be classified
    • page: The zero-indexed page number
    • reason: A brief explanation of the classification (for debugging)
    • suggested_class: A proposed class when the prediction is 'unknown'
  • metadata: Processing information (credit usage, duration, filename, job ID, page count, version)
For detailed information about the response structure, see JSON Response for Classification.

Work with Classify Response Data

Get classification for each page:
Filter pages by class:
Handle pages that could not be classified:

Section: Getting Started

The section method analyzes a parsed document and generates a hierarchical table of contents. Use these examples as guides to get started with sectioning with the library. Pass Markdown Content The library supports a few methods for passing the Markdown content for sectioning:
  • Section data directly from the parse response
  • Section data from a local Markdown file
  • Section data from a Markdown file at a remote URL: markdown: await fetch("https://example.com/file.md")

Section from Parse Response

After parsing a document, you can pass the Markdown string directly from the ParseResponse to the section method without saving it to a file.

Section from Markdown Files

If you already have a Markdown file (from a previous parsing operation), you can section it directly. Use the markdown parameter for local Markdown files or the markdown parameter with fetch() for remote Markdown files.

Set Parameters

The section method accepts optional parameters to customize sectioning behavior. To see all available parameters, go to API.

Section Output

The section method returns a SectionResponse object with the following fields:
  • table_of_contents: Array of SectionTOCEntry objects, each containing:
    • title: The generated section heading text
    • level: The hierarchy depth (1 = top-level, 2 = subsection, 3 = sub-subsection, and so on)
    • section_number: The hierarchical number (for example, "1", "1.2", "1.2.3")
    • start_reference: The chunk ID where this section begins, corresponding to a chunks[].id value from the parse response
  • table_of_contents_md: Markdown-formatted TOC string with anchor links
  • metadata: Processing information (credit usage, duration, filename, job ID, version)
For detailed information about the response structure, see JSON Response for Sectioning.

Split: Getting Started

The split method classifies and separates a parsed document into multiple sub-documents based on Split Rules you define. Use these examples as guides to get started with splitting with the library. Pass Markdown Content The library supports a few methods for passing the Markdown content for splitting:
  • Split data directly from the parse response
  • Split data from a local Markdown file
  • Split data from a Markdown file at a remote URL: markdown: await fetch("https://example.com/file.md")
Define Split Rules Split Rules define how the API classifies and separates your document. Each Split Rule consists of:
  • name: The Split Type name (required)
  • description: Additional context about what this Split Type represents (optional)
  • identifier: A field that makes each instance unique, used to create separate splits (optional)
For more information about Split Rules, see Split Rules.

Split from Parse Response

After parsing a document, you can pass the Markdown string directly from the ParseResponse to the split method without saving it to a file.

Split from Markdown Files

If you already have a Markdown file (from a previous parsing operation), you can split it directly. Use the markdown parameter for local Markdown files or the markdown parameter with fetch() for remote Markdown files.

Set Parameters

The split method accepts optional parameters to customize split behavior. To see all available parameters, go to ADE Split API.

Split Output

The split method returns a SplitResponse object with the following fields:
  • splits: Array of Split objects, each containing:
    • classification: The Split Type name assigned to this sub-document
    • identifier: The unique identifier value (or null if no identifier was specified)
    • pages: Array of zero-indexed page numbers that belong to this split
    • markdowns: Array of Markdown content strings, one for each page
  • metadata: Processing information (credit usage, duration, filename, job ID, page count, version)
For detailed information about the response structure, see JSON Response for Splitting.

Work with Split Response Data

Access all splits by classification:
Filter splits by classification:
Access Markdown content for each split:
Group splits by identifier:

Save Output

Use the optional saveTo parameter to save the full API response as a JSON file. The parameter is available on parse, extract, and split. The directory is created automatically if it doesn’t exist.

Use the Default File Name

Pass a directory path. The library names the file using the input document’s filename and the function called (for example, document_parse_output.json).
When passing Markdown content as a string (markdown: parseResponse.markdown), the library cannot derive a filename from the content. In this situation, use Set the File Name instead.

Set the File Name

Pass a path ending in .json to choose the exact location and filename.

Save the Markdown Field

The parse response includes a markdown field that you can pass directly to other functions in the same script. To save the Markdown for downstream tasks, write it to a file: