Skip to main content
The Reducto JavaScript SDK provides a type-safe interface to the Reducto API. It handles authentication, request formatting, and response parsing automatically.

Quick Start

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

// Initialize the client (reads REDUCTO_API_KEY from environment)
const client = new Reducto();

// Upload a document
const upload = await client.upload({ 
  file: fs.createReadStream("invoice.pdf") 
});

// Parse the document
const result = await client.parse.run({ input: upload.file_id });

// Access the extracted content
for (const chunk of result.result.chunks) {
  console.log(chunk.content);
}

Key Features

TypeScript Support

Full TypeScript definitions with IDE autocomplete for all methods and responses.

Simple API

Intuitive method names that match the REST API endpoints.

Error Handling

Clear error classes with helpful error messages and status codes.

Automatic Retries

Built-in retry logic with exponential backoff for transient errors.

Installation

npm install reductoai
Or with yarn:
yarn add reductoai
Requires Node.js 14+. The SDK includes full TypeScript definitions.

Authentication

Set your API key as an environment variable:
export REDUCTO_API_KEY="your_api_key_here"
The SDK reads it automatically:
import Reducto from 'reductoai';

const client = new Reducto();  // Reads REDUCTO_API_KEY from environment
Or pass it explicitly:
const client = new Reducto({ apiKey: "your_api_key_here" });
Get your API key from Reducto Studio → API Keys.

Core Methods

The SDK provides methods for all Reducto endpoints:

Upload

Upload documents to Reducto’s servers before processing:
const upload = await client.upload({ 
  file: fs.createReadStream("document.pdf") 
});
// Returns: { file_id: "reducto://..." }

Upload Documentation

File upload options, size limits, and presigned URLs.

Parse

Convert documents into structured JSON with text, tables, and figures:
const result = await client.parse.run({ input: upload.file_id });
// Returns: ParseResponse with chunks, blocks, and metadata

Parse Documentation

Parse configuration, chunking options, and response structure.

Extract

Pull specific fields from documents using JSON schemas:
const result = await client.extract.run({
  input: upload.file_id,
  instructions: {
    schema: {
      type: "object",
      properties: {
        invoice_number: { type: "string" },
        total: { type: "number" }
      }
    }
  }
});

Extract Documentation

Schema design, array extraction, and citations.

Split

Divide documents into sections based on content type:
const result = await client.split.run({
  input: upload.file_id,
  split_description: [
    { name: "Introduction", description: "Introduction section" },
    { name: "Results", description: "Results section" }
  ]
});
// Returns: SplitResponse with splits array (name, pages, conf)

Split Documentation

Split configuration and section types.

Edit

Fill PDF forms and modify DOCX documents:
const result = await client.edit.run({
  document_url: upload.file_id,
  edit_instructions: "Fill name with 'John Doe' and date with '12/25/2024'"
});
// Returns: EditResponse with document_url

Edit Documentation

Form schemas and document modification.

Pipeline

Run pre-configured workflows from Reducto Studio:
const result = await client.pipeline.run({
  input: upload.file_id,
  pipeline_id: "your_pipeline_id"  // From Reducto Studio
});

Pipeline Documentation

Running studio-configured pipelines.

Async Jobs

For long-running operations, use runJob methods to get a job ID:
// Start async job
const job = await client.parse.runJob({ input: upload.file_id });
console.log(job.job_id);

// Check status
const status = await client.job.get(job.job_id);
if (status.status === "Completed") {
  console.log(status.result);
}

Async Processing

Concurrent processing, rate limiting, and batch operations.

Response Types

All SDK methods return strongly-typed response objects:
import Reducto, { ParseResponse } from 'reductoai';

const client = new Reducto();
const result: ParseResponse = await client.parse.run({ input: upload.file_id });

// Access typed fields
console.log(result.job_id);  // string
console.log(result.usage.num_pages);  // number
console.log(result.result.chunks);  // Chunk[]

Error Handling

The SDK throws specific error classes for different error conditions:
import Reducto, { 
  APIError, 
  AuthenticationError, 
  BadRequestError,
  RateLimitError 
} from 'reductoai';

try {
  const result = await client.parse.run({ input: "invalid-file-id" });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error(`Auth failed: ${error.message}`);
  } else if (error instanceof BadRequestError) {
    console.error(`Invalid request: ${error.status} - ${error.message}`);
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limited: ${error.message}`);
  } else if (error instanceof APIError) {
    console.error(`API error: ${error.status} - ${error.message}`);
  }
}

Error Handling Guide

Complete error handling reference with all error types.

Advanced Features

Per-Request Options

Override client settings for individual requests:
// Custom timeout
await client.parse.run({ input: upload.file_id }, { timeout: 60000 });

// Custom retry settings
const customClient = new Reducto({ maxRetries: 5 });

CommonJS Support

const Reducto = require('reductoai').default;
const client = new Reducto();

Next Steps

1

Get your API key

Create an API key in Reducto Studio and set it as REDUCTO_API_KEY.
2

Try the quickstart

Run your first parse operation with the quickstart example.
3

Explore the methods

Check out the core methods documentation for detailed usage.