Skip to content
Log in

Parse

Parse full documents into LLM-ready content using the JavaScript SDK

The parse.run() method turns full documents into LLM-ready content: text, tables, figures, layout, and formatting. Set settings.model to "r-1" on every request (requires reductoai>=0.17.0). Parse returns content organized into chunks for LLM and RAG workflows.


Basic Usage

import Reducto from 'reductoai';
import fs from 'fs';

const client = new Reducto();

// Upload and parse
const upload = await client.upload({ 
  file: fs.createReadStream("invoice.pdf") 
});
const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });

// Access the results
for (const chunk of result.result.chunks) {
  console.log(chunk.content);
  for (const block of chunk.blocks) {
    console.log(`  ${block.type} on page ${block.bbox.page}`);
  }
}

Method Signatures

Synchronous Parse

parse.run(params: {
  input: string | Upload;
  enhance?: Enhance;
  formatting?: Formatting;
  retrieval?: Retrieval;
  settings?: Settings;
  spreadsheet?: Spreadsheet;
}, options?: RequestOptions): Promise<ParseRunResponse>

Asynchronous Parse

parse.runJob(params: {
  input: string | Upload;
  async?: ConfigV3AsyncConfig;
  enhance?: Enhance;
  formatting?: Formatting;
  retrieval?: Retrieval;
  settings?: Settings;
  spreadsheet?: Spreadsheet;
}, options?: RequestOptions): Promise<ParseRunJobResponse>

The runJob method returns a job_id that you can use with client.job.retrieve() to retrieve results.


Input Options

The input parameter accepts several formats:

// From upload
const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });

// Public URL
const result = await client.parse.run({ input: "https://example.com/doc.pdf", settings: { model: "r-1" } });

// Presigned S3 URL
const result = await client.parse.run({ 
  input: "https://bucket.s3.amazonaws.com/doc.pdf?X-Amz-...",
  settings: { model: "r-1" },
});

// Reprocess previous job
const result = await client.parse.run({ 
  input: "jobid://7600c8c5-a52f-49d2-8a7d-d75d1b51e141",
  settings: { model: "r-1" },
});

Configuration Examples

Select the Parse Model

Set settings.model to "r-1", or "r-1-mini" for r-1 mini. Until December 7, 2026, a request that omits settings.model runs legacy Parse. Legacy-only settings are listed on Legacy Parse settings.

const result = await client.parse.run({
  input: upload.file_id,
  settings: {
    model: "r-1"  // Options: "r-1", "r-1-mini", "legacy"
  }
});

Chunking

By default, Parse returns the entire document as one chunk. For RAG applications, use variable chunking:

const result = await client.parse.run({
  input: upload.file_id,
  retrieval: {
    chunking: {
      chunk_mode: "variable"  // Options: "disabled", "variable", "page", "section"
    }
  },
  settings: { model: "r-1" },
});

Table Output Format

Control how tables appear in the output:

const result = await client.parse.run({
  input: upload.file_id,
  formatting: {
    table_output_format: "html"  // Options: "dynamic", "html", "md", "json", "csv"
  },
  settings: { model: "r-1" },
});

Augment r-1 with Customized Agentic Processing

Legacy Parse supports promptless agentic scopes as general-purpose accuracy enhancements. r-1 handles those improvements natively. With r-1, add agentic processing when you need a custom prompt for a specific scope. Agentic processing adds latency.

const result = await client.parse.run({
  input: upload.file_id,
  enhance: {
    agentic: [
      {
        scope: "table",
        prompt: "Preserve domain-specific notation such as <0.01, ±, and N/A exactly as written."
      }
    ]
  },
  settings: { model: "r-1" },
});

For structured chart data, use advanced chart extraction.

Figure Descriptions

r-1 writes a short description of every figure by default. No setting is needed.

Filter Blocks

Remove specific content types from output:

const result = await client.parse.run({
  input: upload.file_id,
  retrieval: {
    filter_blocks: ["Header", "Footer", "Page Number"]
  },
  settings: { model: "r-1" },
});

Response Structure

The ParseResponse object contains:

const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });

// Top-level fields
console.log(result.job_id);          // string: Unique job identifier
console.log(result.duration);        // number: Processing time in seconds
console.log(result.studio_link);     // string: Link to view in Studio

// Usage information
console.log(result.usage.num_pages);  // number: Pages processed
console.log(result.usage.credits);    // number: Credits consumed

// Result content
if (result.result.type === "full") {
  const chunks = result.result.chunks;
  for (const chunk of chunks) {
    console.log(chunk.content);    // string: Full text content
    console.log(chunk.embed);       // string: Embedding-optimized content
    console.log(chunk.blocks);      // Array: Individual elements
  }
}

URL Results

For large documents, the response may return a URL instead of inline content:

const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });

if (result.result.type === "url") {
  // Fetch the content from the URL
  const response = await fetch(result.result.url);
  const chunks = await response.json();
} else {
  // Content is inline
  const chunks = result.result.chunks;
}

Error Handling

import Reducto, { APIError, BadRequestError } from 'reductoai';

try {
  const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });
} catch (error) {
  if (error instanceof BadRequestError) {
    console.error(`Invalid request: ${error.status} - ${error.message}`);
  } else if (error instanceof APIError) {
    console.error(`API error: ${error.status} - ${error.message}`);
  }
}

Complete Example

import Reducto from 'reductoai';
import fs from 'fs';

const client = new Reducto();

// Upload
const upload = await client.upload({ 
  file: fs.createReadStream("fidelity-example.pdf") 
});

// Parse with r-1 and additional configuration
const result = await client.parse.run({
  input: upload.file_id,
  formatting: {
    table_output_format: "html"
  },
  retrieval: {
    chunking: { chunk_mode: "variable" }
  },
  settings: { model: "r-1",
    page_range: { start: 1, end: 5 }
  }
});

// Process results
console.log(`Processed ${result.usage.num_pages} pages`);
console.log(`Used ${result.usage.credits} credits`);
console.log(`View in Studio: ${result.studio_link}`);

for (let i = 0; i < result.result.chunks.length; i++) {
  const chunk = result.result.chunks[i];
  console.log(`\n=== Chunk ${i + 1} ===`);
  console.log(chunk.content.substring(0, 500));  // First 500 chars
  
  // Count block types
  const blockTypes = {};
  for (const block of chunk.blocks) {
    blockTypes[block.type] = (blockTypes[block.type] || 0) + 1;
  }
  
  console.log(`Block types:`, blockTypes);
}

Best Practices

Enable chunk_mode: "variable" for RAG pipelines to get semantically meaningful chunks.

Add a scoped custom prompt when your workflow needs use-case-specific parsing instructions. r-1 handles scanned documents natively.

Use filter_blocks to remove headers and footers that pollute search results.

Always check result.type and handle URL results for large documents.


Next Steps

Type to search…

escClose