npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

leapocr

v0.0.5

Published

Official JavaScript/TypeScript SDK for LeapOCR API

Readme

LeapOCR JavaScript SDK

npm version License: MIT TypeScript

Official JavaScript/TypeScript SDK for LeapOCR - Transform documents into structured data using AI-powered OCR.

Overview

LeapOCR provides enterprise-grade document processing with AI-powered data extraction. This SDK offers a JavaScript/TypeScript-native interface for seamless integration into your Node.js and browser applications.

Installation

npm install leapocr
# or
yarn add leapocr
# or
pnpm add leapocr

Quick Start

Prerequisites

Basic Example

import { LeapOCR } from "leapocr";

// Initialize the SDK with your API key
const client = new LeapOCR({
  apiKey: process.env.LEAPOCR_API_KEY,
});

// Submit a document for processing
const job = await client.ocr.processURL("https://example.com/document.pdf", {
  format: "structured",
  model: "standard-v1",
});

// Wait for processing to complete
const result = await client.ocr.waitUntilDone(job.jobId);

console.log("Extracted data:", result.data);

Key Features

  • TypeScript First - Full type safety with comprehensive TypeScript definitions
  • Multiple Processing Formats - Structured data extraction, markdown output, or per-page processing
  • Flexible Model Selection - Choose from standard, pro, or custom AI models
  • Custom Schema Support - Define extraction schemas for your specific use case
  • Built-in Retry Logic - Automatic handling of transient failures
  • Universal Runtime - Works in Node.js and modern browsers
  • Direct File Upload - Efficient multipart uploads for local files

Processing Models

| Model | Use Case | Credits/Page | Priority | | ---------------- | ---------------------------------- | ------------ | -------- | | standard-v1 | General purpose (default) | 1 | 1 | | english-pro-v1 | English documents, premium quality | 2 | 4 | | pro-v1 | Highest quality, all languages | 5 | 5 |

Specify a model in the processing options. Defaults to standard-v1.

Usage Examples

Processing from URL

const client = new LeapOCR({
  apiKey: process.env.LEAPOCR_API_KEY,
});

const job = await client.ocr.processURL("https://example.com/invoice.pdf", {
  format: "structured",
  model: "standard-v1",
  instructions: "Extract invoice number, date, and total amount",
});

const result = await client.ocr.waitUntilDone(job.jobId);

console.log(`Processing completed in ${result.processing_time_seconds}s`);
console.log(`Credits used: ${result.credits_used}`);
console.log("Data:", result.data);

Processing Local Files

import { readFileSync } from "fs";

const client = new LeapOCR({
  apiKey: process.env.LEAPOCR_API_KEY,
});

const job = await client.ocr.processFile("./invoice.pdf", {
  format: "structured",
  model: "pro-v1",
  schema: {
    invoice_number: "string",
    total_amount: "number",
    invoice_date: "string",
    vendor_name: "string",
  },
});

const result = await client.ocr.waitUntilDone(job.jobId);
console.log("Extracted data:", result.data);

Custom Schema Extraction

const schema = {
  type: "object",
  properties: {
    patient_name: { type: "string" },
    date_of_birth: { type: "string" },
    medications: {
      type: "array",
      items: {
        type: "object",
        properties: {
          name: { type: "string" },
          dosage: { type: "string" },
        },
      },
    },
  },
};

const job = await client.ocr.processFile("./medical-record.pdf", {
  format: "structured",
  schema,
});

Output Formats

| Format | Description | Use Case | | --------------------- | ------------------ | ---------------------------------------------- | | structured | Single JSON object | Extract specific fields across entire document | | markdown | Text per page | Convert document to readable text | | per-page-structured | JSON per page | Extract fields from multi-section documents |

Monitoring Job Progress

// Poll for status updates
const pollInterval = 2000; // 2 seconds
const maxAttempts = 150; // 5 minutes max
let attempts = 0;

while (attempts < maxAttempts) {
  const status = await client.ocr.getJobStatus(job.jobId);

  console.log(
    `Status: ${status.status} (${status.progress?.toFixed(1)}% complete)`,
  );

  if (status.status === "completed") {
    const result = await client.ocr.getJobResult(job.jobId);
    console.log("Processing complete!");
    break;
  }

  await new Promise((resolve) => setTimeout(resolve, pollInterval));
  attempts++;
}

Using Template Slugs

// Process a document using a predefined template
const job = await client.ocr.processFile("./invoice.pdf", {
  templateSlug: "my-invoice-template",
  model: "pro-v1",
});

const result = await client.ocr.waitUntilDone(job.jobId);
console.log("Extracted data:", result.data);

Deleting Jobs

// Delete a completed job to free up resources
await client.ocr.deleteJob(job.jobId);
console.log("Job deleted successfully");

For more examples, see the examples/ directory.

Configuration

Custom Configuration

import { LeapOCR } from "leapocr";

const client = new LeapOCR({
  apiKey: "your-api-key",
  baseURL: "https://api.leapocr.com", // optional
  timeout: 30000, // 30 seconds (optional)
});

Environment Variables

export LEAPOCR_API_KEY="your-api-key"
export LEAPOCR_BASE_URL="https://api.leapocr.com"  # optional

Error Handling

The SDK provides typed errors for robust error handling:

import {
  AuthenticationError,
  ValidationError,
  JobFailedError,
  TimeoutError,
  NetworkError,
} from "leapocr";

try {
  const result = await client.ocr.waitUntilDone(job.jobId);
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error("Authentication failed - check your API key");
  } else if (error instanceof ValidationError) {
    console.error("Validation error:", error.message);
  } else if (error instanceof NetworkError) {
    // Retry the operation
    console.error("Network error, retrying...");
  } else if (error instanceof JobFailedError) {
    console.error("Processing failed:", error.message);
  } else if (error instanceof TimeoutError) {
    console.error("Operation timed out");
  }
}

Error Types

  • AuthenticationError - Invalid API key or authentication failures
  • AuthorizationError - Permission denied for requested resource
  • RateLimitError - API rate limit exceeded
  • ValidationError - Input validation errors
  • FileError - File-related errors (size, format, etc.)
  • JobError - Job processing errors
  • JobFailedError - Job completed with failure status
  • TimeoutError - Operation timeouts
  • NetworkError - Network/connectivity issues (retryable)
  • APIError - General API errors

API Reference

Full API documentation is available in the TypeScript definitions.

Core Methods

// Initialize SDK
new LeapOCR(config: ClientConfig)

// Process documents
client.ocr.processURL(url: string, options?: UploadOptions): Promise<UploadResult>
client.ocr.processFile(filePath: string, options?: UploadOptions): Promise<UploadResult>
client.ocr.processBuffer(buffer: Buffer, filename: string, options?: UploadOptions): Promise<UploadResult>

// Job management
client.ocr.getJobStatus(jobId: string): Promise<JobStatus>
client.ocr.getJobResult(jobId: string): Promise<OCRResult>
client.ocr.waitUntilDone(jobId: string, options?: PollOptions): Promise<OCRResult>
client.ocr.deleteJob(jobId: string): Promise<void>

Processing Options

interface UploadOptions {
  format?: "structured" | "markdown" | "per-page-structured";
  model?: OCRModel;
  schema?: Record<string, any>;
  instructions?: string;
  templateSlug?: string;
}

Development

Prerequisites

  • Node.js 18+
  • pnpm 9+

Setup

# Install dependencies
pnpm install

# Build the SDK
pnpm build

Common Tasks

pnpm build              # Build the SDK
pnpm test               # Run unit tests
pnpm typecheck          # Type check
pnpm format             # Format code
pnpm dev                # Development mode with watch
pnpm generate           # Generate types from OpenAPI spec

Contributing

We welcome contributions! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support & Resources


Version: 0.0.5