Getting Started

Parse documents to markdown in a few lines of code.

Installation

npm install flense

Quick Start

import { Flense } from 'flense';

const flense = new Flense({ apiKey: 'flense_...' });

// Parse a PDF from URL
const result = await flense.parseUrl('https://example.com/doc.pdf').wait();
console.log(result.markdown);

Parse a File

import { Flense } from 'flense';
import fs from 'fs';

const flense = new Flense({ apiKey: 'flense_...' });

// Parse a local file
const file = fs.readFileSync('document.pdf');
const result = await flense.parseFile(file, 'document.pdf').wait();
console.log(result.markdown);

Parse Options

All features are OFF by default for fastest processing. Enable them as needed using fluent API methods:

const result = await flense
  .parseFile(file, 'document.pdf')
  .withOCR()          // Enable OCR for scanned documents
  .withTables()       // Enable table structure detection
  .withImages()       // Enable image extraction
  .disableCaching()   // Force re-parse (skip cache)
  .wait();

Options Reference

.withOCR(enabled?)

Enable OCR for scanned or image-based PDFs. Adds ~5-8s per page.

.withTables(enabled?)

Enable table structure detection. Adds ~2-3s per page.

.withImages(enabled?)

Enable image extraction and upload to cloud storage.

.disableCaching()

Force re-parsing even if the same file was parsed before. Caching is enabled by default.

Selective Options

Enable only the features you need:

// Only enable OCR, leave tables and images off
const result = await flense
  .parseUrl('https://example.com/scanned.pdf')
  .withOCR()
  .wait();

Caching

File parsing results are cached by default. When the same file is uploaded with the same parse options, the cached result is returned instantly — no re-processing needed.

The cache key is a SHA-256 hash of the file content and parse options. Changing any option (e.g. enabling OCR) produces a different hash and triggers a fresh parse.

// Caching is ON by default — identical files return instantly
const result = await flense.parseFile(file, 'doc.pdf').wait();

// Disable caching to force a fresh parse
const fresh = await flense
  .parseFile(file, 'doc.pdf')
  .disableCaching()
  .wait();

Real-time Progress

For large documents, subscribe to real-time updates:

const job = flense.parseFile(file, 'document.pdf');

job.subscribe({
  onProgress: ({ progress, stage, currentPage, totalPages }) => {
    console.log(`${progress}% - ${stage}`);
    if (currentPage && totalPages) {
      console.log(`Page ${currentPage}/${totalPages}`);
    }
  },
  onContent: ({ page, content }) => {
    console.log(`Page ${page} ready`);
  },
  onComplete: (status) => {
    console.log('Done!', status.output?.markdown);
  },
  onError: (error) => {
    console.error('Failed:', error.message);
  },
});

Environment Variable

Set FLENSE_API_KEY to avoid passing the key explicitly:

export FLENSE_API_KEY=flense_your_key_here
import { Flense } from 'flense';

// API key is read from FLENSE_API_KEY
const flense = new Flense();

Supported Formats

PDF
Documents
DOCX
Word
PPTX
PowerPoint
PNG
Images
JPG
Images
WEBP
Images
XLS
Excel
CSV
Spreadsheets

API Reference

See the full API documentation at api.flense.dev/docs

Need Help?

Reach out to us at hello@flense.dev