DocPeeldocs

Batch Extraction

DocPeel does not have a dedicated batch endpoint — instead, fan out concurrent calls to POST /v1/extractions. This guide shows how to do it efficiently while respecting rate limits.

Concurrency

Each API key allows 120 requests/minute. A concurrency of 5 – 10 is a safe sweet spot for most workloads.

import fs from 'fs';
import path from 'path';
import { DocPeel } from '@doc-peel/sdk';
import pLimit from 'p-limit';

const client = new DocPeel({ apiKey: process.env.DOCPEEL_API_KEY });
const limit  = pLimit(8);

async function processAll(filePaths) {
  return Promise.all(filePaths.map(filePath => limit(async () => {
    const fileName = path.basename(filePath);
    const fileB64  = fs.readFileSync(filePath).toString('base64');
    try {
      return await client.extractions.create({ file: fileB64, fileName });
    } catch (err) {
      // Persist failure for later retry; don't fail the whole batch.
      await recordFailure(fileName, err);
      return null;
    }
  })));
}

Backpressure on 429

If you start seeing 429 rate_limited, drop concurrency or add a backoff:

async function withBackoff(fn) {
  for (let attempt = 0; attempt < 5; attempt++) {
    try { return await fn(); }
    catch (e) {
      if (e.code !== 'rate_limited') throw e;
      await new Promise(r => setTimeout(r, 1000 * 2 ** attempt));
    }
  }
}

Asynchronous fan-out via webhooks

For very large batches (10k+ documents), enqueue jobs in your own queue, process them with workers, and rely on the extraction.completed webhook to signal completion. This decouples your dashboard from the API roundtrip.

Cost & credits

Each successful extraction costs 1 credit. Failed extractions are refunded automatically. Watch the billing.credits_low webhook to top up before you run out.