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, settings: { model: "r-1" } });
// Access the extracted content
for (const chunk of result.result.chunks) {
console.log(chunk.content);
}Key Features
Full TypeScript definitions with IDE autocomplete for all methods and responses.
Intuitive method names that match the REST API endpoints.
Clear error classes with helpful error messages and status codes.
Built-in retry logic with exponential backoff for transient errors.
Installation
npm install reductoaiOr with yarn:
yarn add reductoaiRequires 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 environmentOr 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://..." }Parse
Turn full documents into LLM-ready text, tables, and figures:
const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });
// Returns: ParseResponse with chunks, blocks, and metadataExtract
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" }
}
}
},
parsing: { settings: { model: 'r-1' } },
});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" }
],
parsing: { settings: { model: 'r-1' } },
});
// Returns: SplitResponse with splits array (name, pages, conf)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_urlPipeline
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
});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, settings: { model: "r-1" } });
console.log(job.job_id);
// Check status
const status = await client.job.retrieve(job.job_id);
if (status.status === "Completed") {
console.log(status.result);
}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, settings: { model: "r-1" } });
// 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", settings: { model: "r-1" } });
} 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}`);
}
}Advanced Features
Per-Request Options
Override client settings for individual requests:
// Custom timeout
await client.parse.run({ input: upload.file_id }, { timeout: 60000, settings: { model: "r-1" } });
// Custom retry settings
const customClient = new Reducto({ maxRetries: 5 });CommonJS Support
const Reducto = require('reductoai').default;
const client = new Reducto();Next Steps
Get your API key
Create an API key in Reducto Studio and set it as
REDUCTO_API_KEY.Try the quickstart
Run your first parse operation with the quickstart example.
Explore the methods
Check out the core methods documentation for detailed usage.