---
title: "JavaScript SDK Overview"
description: "Get started with the Reducto JavaScript SDK"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript SDK Overview

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

---

## Quick Start

```javascript
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

- **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

```bash
npm install reductoai
```

Or with yarn:

```bash
yarn add reductoai
```

Requires Node.js 14+. The SDK includes full TypeScript definitions.

---

## Authentication

Set your API key as an environment variable:

```bash
export REDUCTO_API_KEY="your_api_key_here"
```

The SDK reads it automatically:

```javascript
import Reducto from 'reductoai';

const client = new Reducto();  // Reads REDUCTO_API_KEY from environment
```

Or pass it explicitly:

```javascript
const client = new Reducto({ apiKey: "your_api_key_here" });
```

Get your API key from [Reducto Studio](https://studio.reducto.ai/) → API Keys.

---

## Core Methods

The SDK provides methods for all Reducto endpoints:

### Upload

Upload documents to Reducto's servers before processing:

```javascript
const upload = await client.upload({ 
  file: fs.createReadStream("document.pdf") 
});
// Returns: { file_id: "reducto://..." }
```

- [Upload Documentation](/sdk/javascript/upload): File upload options, size limits, and presigned URLs.

### Parse

Turn full documents into LLM-ready text, tables, and figures:

```javascript
const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });
// Returns: ParseResponse with chunks, blocks, and metadata
```

- [Parse Documentation](/sdk/javascript/parse): Parse configuration, chunking options, and response structure.

### Extract

Pull specific fields from documents using JSON schemas:

```javascript
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' } },
});
```

- [Extract Documentation](/sdk/javascript/extract): Schema design, array extraction, and citations.

### Split

Divide documents into sections based on content type:

```javascript
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)
```

- [Split Documentation](/sdk/javascript/split): Split configuration and section types.

### Edit

Fill PDF forms and modify DOCX documents:

```javascript
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](/sdk/javascript/edit): Form schemas and document modification.

### Pipeline

Run pre-configured workflows from Reducto Studio:

```javascript
const result = await client.pipeline.run({
  input: upload.file_id,
  pipeline_id: "your_pipeline_id"  // From Reducto Studio
});
```

- [Pipeline Documentation](/sdk/javascript/pipeline): Running studio-configured pipelines.

---

## Async Jobs

For long-running operations, use `runJob` methods to get a job ID:

```javascript
// 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);
}
```

- [Async Processing](/sdk/javascript/async): Concurrent processing, rate limiting, and batch operations.

---

## Response Types

All SDK methods return strongly-typed response objects:

```typescript
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:

```javascript
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}`);
  }
}
```

- [Error Handling Guide](/sdk/javascript/error-handling): Complete error handling reference with all error types.

---

## Advanced Features

### Per-Request Options

Override client settings for individual requests:

```javascript
// 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

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

---

## Next Steps

1. **Get your API key**

   Create an API key in [Reducto Studio](https://studio.reducto.ai/) and set it as `REDUCTO_API_KEY`.
2. **Try the quickstart**

   Run your first parse operation with the [quickstart example](/quickstart).
3. **Explore the methods**

   Check out the [core methods documentation](/sdk/javascript/parse) for detailed usage.

Source: https://docs.reducto.ai/sdk/javascript/overview/index.mdx
