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

Important Considerations (Supported Features)

The library supports: The library does not support:
  • The legacy API

Install the Library

npm install landingai-ade

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.
export VISION_AGENT_API_KEY=<your-api-key>
When initializing the client, the library automatically reads from the VISION_AGENT_API_KEY environment variable:
import LandingAIADE from "landingai-ade";

const client = new LandingAIADE();
Alternatively, you can explicitly pass the API key when initializing the client:
import LandingAIADE from "landingai-ade";

const client = new LandingAIADE({
  apikey: process.env.VISION_AGENT_API_KEY
});
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.
import LandingAIADE from "landingai-ade";

const client = new LandingAIADE({
  environment: "eu",
});

// ... rest of your code
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().
import LandingAIADE from "landingai-ade";
import fs from "fs";

const client = new LandingAIADE();

// Replace with your file path
const response = await client.parse({
  document: fs.createReadStream("/path/to/file/document"),
  model: "dpt-2-latest"
});

console.log(response.chunks);

// Save Markdown output (useful if you plan to run extract on the Markdown)
fs.writeFileSync("output.md", response.markdown, "utf-8");

Parse Remote URLs

Use the document parameter with fetch() to parse files from remote URLs (http, https).
import LandingAIADE from "landingai-ade";
import fs from "fs";

const client = new LandingAIADE();

// Parse a remote file
const response = await client.parse({
  document: await fetch("https://example.com/document.pdf"),
  model: "dpt-2-latest"
});

console.log(response.chunks);

// Save Markdown output (useful if you plan to run extract on the Markdown)
fs.writeFileSync("output.md", response.markdown, "utf-8");

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.
import LandingAIADE from "landingai-ade";
import fs from "fs";

const client = new LandingAIADE();

const response = await client.parse({
  document: fs.createReadStream("/path/to/document.pdf"),
  model: "dpt-2-latest",
  split: "page"
});

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:
import LandingAIADE from "landingai-ade";
import fs from "fs";

const client = new LandingAIADE();

// Step 1: Create a parse job
const job = await client.parseJobs.create({
  document: fs.createReadStream("/path/to/file/document"),
  model: "dpt-2-latest"
});

const jobId = job.job_id;
console.log(`Job ${jobId} created.`);

// Step 2: Get the parsing results
while (true) {
  const response = await client.parseJobs.get(jobId);
  if (response.status === "completed") {
    console.log(`Job ${jobId} completed.`);
    break;
  }
  console.log(`Job ${jobId}: ${response.status} (${(response.progress * 100).toFixed(0)}% complete)`);
  await new Promise(resolve => setTimeout(resolve, 5000));
}

// Step 3: Access the parsed data
const response = await client.parseJobs.get(jobId);
console.log("Global Markdown:", response.data.markdown.substring(0, 200) + "...");
console.log(`Number of chunks: ${response.data.chunks.length}`);

// Save Markdown output (useful if you plan to run extract on the Markdown)
fs.writeFileSync("output.md", response.data.markdown, "utf-8");

List Parse Jobs

To list all async parse jobs associated with your API key, run this code:
import LandingAIADE from "landingai-ade";

const client = new LandingAIADE();

// List all jobs
const response = await client.parseJobs.list();
for (const job of response.jobs) {
  console.log(`Job ${job.job_id}: ${job.status}`);
}

Work with Parse Response Data

Access all text chunks:
for (const chunk of response.chunks) {
  if (chunk.type === 'text') {
    console.log(`Chunk ${chunk.id}: ${chunk.markdown}`);
  }
}
Filter chunks by page:
const page0Chunks = response.chunks.filter(chunk => chunk.grounding.page === 0);
console.log(page0Chunks);
Get chunk locations:
for (const chunk of response.chunks) {
  const box = chunk.grounding.box;
  console.log(`Chunk at page ${chunk.grounding.page}: (${box.left}, ${box.top}, ${box.right}, ${box.bottom})`);
}
Identify the chunk type for each chunk:
for (const [chunkId, grounding] of Object.entries(response.grounding)) {
  console.log(`Chunk ${chunkId} has type: ${grounding.type}`);
}

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.
import LandingAIADE from "landingai-ade";
import fs from "fs";

const client = new LandingAIADE();

// Parse the document
const parseResponse = await client.parse({
  document: fs.createReadStream("/path/to/document.pdf"),
  model: "dpt-2-latest"
});

// Define Split Rules
const splitClass = [
  {
    name: "Bank Statement",
    description: "Document from a bank that summarizes all account activity over a period of time."
  },
  {
    name: "Pay Stub",
    description: "Document that details an employee's earnings, deductions, and net pay for a specific pay period.",
    identifier: "Pay Stub Date"
  }
];

// Split using the Markdown string from parse response
const splitResponse = await client.split({
  split_class: splitClass,
  markdown: parseResponse.markdown,  // Pass Markdown string directly
  model: "split-latest"
});

// Access the splits
for (const split of splitResponse.splits) {
  console.log(`Classification: ${split.classification}`);
  console.log(`Identifier: ${split.identifier}`);
  console.log(`Pages: ${split.pages}`);
}

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.
import LandingAIADE, { toFile } from "landingai-ade";
import fs from "fs";

const client = new LandingAIADE();

// Define Split Rules
const splitClass = [
  {
    name: "Invoice",
    description: "A document requesting payment for goods or services.",
    identifier: "Invoice Number"
  },
  {
    name: "Receipt",
    description: "A document acknowledging that payment has been received."
  }
];

// Split from a local Markdown file
const splitResponse = await client.split({
  split_class: splitClass,
  markdown: fs.createReadStream("/path/to/parsed_output.md"),
  model: "split-latest"
});

// Or split from a remote Markdown file
const splitResponse = await client.split({
  split_class: splitClass,
  markdown: await fetch("https://example.com/document.md"),
  model: "split-latest"
});

// Access the splits
for (const split of splitResponse.splits) {
  console.log(`Classification: ${split.classification}`);
  if (split.identifier) {
    console.log(`Identifier: ${split.identifier}`);
  }
  console.log(`Number of pages: ${split.pages.length}`);
  console.log(`Markdown content: ${split.markdowns[0].substring(0, 100)}...`);
}

Set Parameters

The split method accepts optional parameters to customize split behavior. To see all available parameters, go to ADE Split API.
import LandingAIADE from "landingai-ade";
import fs from "fs";

const client = new LandingAIADE();

const splitResponse = await client.split({
  split_class: [
    { name: "Section A", description: "Introduction section" },
    { name: "Section B", description: "Main content section" }
  ],
  markdown: fs.createReadStream("/path/to/parsed_output.md"),
  model: "split-20251105"  // Use a specific model version
});

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:
for (const split of splitResponse.splits) {
  console.log(`Split Type: ${split.classification}`);
  console.log(`Pages included: ${split.pages}`);
}
Filter splits by classification:
const invoices = splitResponse.splits.filter(split => split.classification === "Invoice");
console.log(`Found ${invoices.length} invoices`);
Access Markdown content for each split:
for (const split of splitResponse.splits) {
  console.log(`Classification: ${split.classification}`);
  for (let i = 0; i < split.markdowns.length; i++) {
    console.log(`  Page ${split.pages[i]} Markdown: ${split.markdowns[i].substring(0, 100)}...`);
  }
}
Group splits by identifier:
const splitsByIdentifier = new Map<string, Array<typeof splitResponse.splits[0]>>();

for (const split of splitResponse.splits) {
  if (split.identifier) {
    const existing = splitsByIdentifier.get(split.identifier) || [];
    existing.push(split);
    splitsByIdentifier.set(split.identifier, existing);
  }
}

for (const [identifier, splits] of splitsByIdentifier.entries()) {
  console.log(`Identifier '${identifier}': ${splits.length} split(s)`);
}

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.
import LandingAIADE, { toFile } from "landingai-ade";
import fs from "fs";

// Define your extraction schema
const schemaDict = {
  type: "object",
  properties: {
    employee_name: {
      type: "string",
      description: "The employee's full name"
    }
  }
};

const client = new LandingAIADE();
const schemaJson = JSON.stringify(schemaDict);

// Parse the document
const parseResponse = await client.parse({
  document: fs.createReadStream("/path/to/document.pdf"),
  model: "dpt-2-latest"
});

// Extract data using the markdown string from parse response
const extractResponse = await client.extract({
  schema: schemaJson,
  markdown: await toFile(Buffer.from(parseResponse.markdown), "document.md"),
  model: "extract-latest"
});

// Access the extracted data
console.log(extractResponse.extraction);

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.
import LandingAIADE from "landingai-ade";
import fs from "fs";

// Define your extraction schema
const schemaDict = {
  type: "object",
  properties: {
    employee_name: {
      type: "string",
      description: "The employee's full name"
    },
    employee_ssn: {
      type: "string",
      description: "The employee's Social Security Number"
    },
    gross_pay: {
      type: "number",
      description: "The gross pay amount"
    }
  },
  required: ["employee_name", "employee_ssn", "gross_pay"]
};

const client = new LandingAIADE();
const schemaJson = JSON.stringify(schemaDict);

// Extract from a local markdown file
const extractResponse = await client.extract({
  schema: schemaJson,
  markdown: fs.createReadStream("/path/to/output.md"),
  model: "extract-latest"
});

// Or extract from a remote markdown file
const extractResponse = await client.extract({
  schema: schemaJson,
  markdown: await fetch("https://example.com/document.md"),
  model: "extract-latest"
});

// Access the extracted data
console.log(extractResponse.extraction);

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:
npm install zod
After installing zod, run extraction with the library:
import LandingAIADE, { toFile } from "landingai-ade";
import fs from "fs";
import { z } from "zod";

// Define your extraction schema as a Zod schema
const PayStubSchema = z.object({
  employee_name: z.string().describe("The employee's full name"),
  employee_ssn: z.string().describe("The employee's Social Security Number"),
  gross_pay: z.number().describe("The gross pay amount")
});

// Extract TypeScript type from schema
type PayStubData = z.infer<typeof PayStubSchema>;

// Initialize the client
const client = new LandingAIADE();

// First, parse the document to get markdown
const parseResponse = await client.parse({
  document: fs.createReadStream("/path/to/pay-stub.pdf"),
  model: "dpt-2-latest"
});

// Convert Zod schema to JSON schema
const schema = JSON.stringify(z.toJSONSchema(PayStubSchema));

// Extract structured data using the schema
const extractResponse = await client.extract({
  schema: schema,
  markdown: await toFile(Buffer.from(parseResponse.markdown), "document.md"),
  model: "extract-latest"
});

// Access the extracted data with type safety
const data = extractResponse.extraction as PayStubData;
console.log(data);

// Access extraction metadata to see which chunks were referenced
console.log(extractResponse.extraction_metadata);

Extraction with JSON Schema (Inline)

Define your extraction schema directly as a JSON string in your script.
import LandingAIADE, { toFile } from "landingai-ade";
import fs from "fs";

// Define your extraction schema as an object
const schemaDict = {
  type: "object",
  properties: {
    employee_name: {
      type: "string",
      description: "The employee's full name"
    },
    employee_ssn: {
      type: "string",
      description: "The employee's Social Security Number"
    },
    gross_pay: {
      type: "number",
      description: "The gross pay amount"
    }
  },
  required: ["employee_name", "employee_ssn", "gross_pay"]
};

// Initialize the client
const client = new LandingAIADE();

// First, parse the document to get markdown
const parseResponse = await client.parse({
  document: fs.createReadStream("/path/to/pay-stub.pdf"),
  model: "dpt-2-latest"
});

// Convert schema object to JSON string
const schemaJson = JSON.stringify(schemaDict);

// Extract structured data using the schema
const extractResponse = await client.extract({
  schema: schemaJson,
  markdown: await toFile(Buffer.from(parseResponse.markdown), "document.md"),
  model: "extract-latest"
});

// Access the extracted data
console.log(extractResponse.extraction);

// Access extraction metadata to see which chunks were referenced
console.log(extractResponse.extraction_metadata);

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:
{
  "type": "object",
  "properties": {
    "employee_name": {
      "type": "string",
      "description": "The employee's full name"
    },
    "employee_ssn": {
      "type": "string",
      "description": "The employee's Social Security Number"
    },
    "gross_pay": {
      "type": "number",
      "description": "The gross pay amount"
    }
  },
  "required": ["employee_name", "employee_ssn", "gross_pay"]
}
You can pass the JSON file defined above in the following script:
import LandingAIADE, { toFile } from "landingai-ade";
import fs from "fs";

// Initialize the client
const client = new LandingAIADE();

// First, parse the document to get markdown
const parseResponse = await client.parse({
  document: fs.createReadStream("/path/to/pay-stub.pdf"),
  model: "dpt-2-latest"
});

// Load schema from JSON file
const schemaJson = fs.readFileSync("pay_stub_schema.json", "utf-8");

// Extract structured data using the schema
const extractResponse = await client.extract({
  schema: schemaJson,
  markdown: await toFile(Buffer.from(parseResponse.markdown), "document.md"),
  model: "extract-latest"
});

// Access the extracted data
console.log(extractResponse.extraction);

// Access extraction metadata to see which chunks were referenced
console.log(extractResponse.extraction_metadata);

Extract Nested Subfields

Define nested Zod schemas to extract hierarchical data from documents. This approach organizes related information under meaningful section names. The schemas with nested fields must be defined before the main extraction schema. Otherwise you may get an error that the schemas with the nested fields are not defined. 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.
import LandingAIADE, { toFile } from "landingai-ade";
import fs from "fs";
import { z } from "zod";

// Define a nested schema for patient-specific information
const PatientDetailsSchema = z.object({
  patient_name: z.string().describe("Full name of the patient."),
  date: z.string().describe("Date the patient information form was filled out.")
});

// Define a nested schema for emergency contact details
const EmergencyContactInformationSchema = z.object({
  emergency_contact_name: z.string().describe("Full name of the emergency contact person."),
  relationship_to_patient: z.string().describe("Relationship of the emergency contact to the patient."),
  primary_phone_number: z.string().describe("Primary phone number of the emergency contact."),
  secondary_phone_number: z.string().describe("Secondary phone number of the emergency contact."),
  address: z.string().describe("Full address of the emergency contact.")
});

// Define the main extraction schema that combines all the nested schemas
const PatientAndEmergencyContactInformationSchema = z.object({
  patient_details: PatientDetailsSchema.describe("Information about the patient as provided in the form."),
  emergency_contact_information: EmergencyContactInformationSchema.describe("Details of the emergency contact person for the patient.")
});

// Extract TypeScript type from schema
type PatientAndEmergencyContactInformation = z.infer<typeof PatientAndEmergencyContactInformationSchema>;

// Initialize the client
const client = new LandingAIADE();

// Parse the document to get markdown
const parseResponse = await client.parse({
  document: fs.createReadStream("/path/to/medical-form.pdf"),
  model: "dpt-2-latest"
});

// Convert Zod schema to JSON schema
const schema = JSON.stringify(z.toJSONSchema(PatientAndEmergencyContactInformationSchema));

// Extract structured data using the schema
const extractResponse = await client.extract({
  schema: schema,
  markdown: await toFile(Buffer.from(parseResponse.markdown), "document.md"),
  model: "extract-latest"
});

// Display the extracted structured data
console.log(extractResponse.extraction);

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.
import LandingAIADE, { toFile } from "landingai-ade";
import fs from "fs";
import { z } from "zod";

// Nested schemas for array fields
const DescriptionItemSchema = z.object({
  description: z.string().describe("Invoice or Bill Description"),
  amount: z.number().describe("Invoice or Bill Amount")
});

const WireInstructionSchema = z.object({
  bank_name: z.string().describe("Bank name"),
  bank_address: z.string().describe("Bank address"),
  bank_account_no: z.string().describe("Bank account number"),
  swift_code: z.string().describe("SWIFT code"),
  aba_routing: z.string().describe("ABA routing number"),
  ach_routing: z.string().describe("ACH routing number")
});

// Invoice schema containing array fields
const InvoiceSchema = z.object({
  description_or_particular: z.array(DescriptionItemSchema).describe("List of invoice line items (description and amount)"),
  wire_instructions: z.array(WireInstructionSchema).describe("Wire transfer instructions")
});

// Main extraction schema
const ExtractedInvoiceFieldsSchema = z.object({
  invoice: InvoiceSchema.describe("Invoice list-type fields")
});

// Extract TypeScript type from schema
type ExtractedInvoiceFields = z.infer<typeof ExtractedInvoiceFieldsSchema>;

// Initialize the client
const client = new LandingAIADE();

// Parse the document to get markdown
const parseResponse = await client.parse({
  document: fs.createReadStream("/path/to/wire-transfer.pdf"),
  model: "dpt-2-latest"
});

// Convert Zod schema to JSON schema
const schema = JSON.stringify(z.toJSONSchema(ExtractedInvoiceFieldsSchema));

// Extract structured data using the schema
const extractResponse = await client.extract({
  schema: schema,
  markdown: await toFile(Buffer.from(parseResponse.markdown), "document.md"),
  model: "extract-latest"
});

// Display the extracted data
console.log(extractResponse.extraction);