DocPeeldocs

JavaScript / TypeScript SDK

@doc-peel/sdk is the official Node + browser client. Type definitions ship with the package — no extra @types needed.

Install

npm install @doc-peel/sdk
# or: pnpm add @doc-peel/sdk
# or: yarn add @doc-peel/sdk

Initialise

import { DocPeel } from '@doc-peel/sdk';

const client = new DocPeel({
  apiKey: process.env.DOCPEEL_API_KEY!,
  // baseUrl:  'https://api.docpeel.com',  // override for staging
  // timeoutMs: 120_000,
});

Methods

client.ping()

Verify the key is valid. Returns metadata about the key and workspace.

const me = await client.ping();
//  { api_key: { id, name, prefix, scopes, workspace_id }, request_id }

client.extractions.create()

The DocPeel API is JSON-only — documents are sent as a base64 string in the request body. The SDK accepts a base64 string directly, or any common file representation (which it base64-encodes for you).

Recommended: base64 string

import { DocPeel } from '@doc-peel/sdk';
import fs from 'node:fs';

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

// You bring the base64 — the SDK passes it through untouched.
const fileB64 = fs.readFileSync('./invoice.pdf').toString('base64');

const extraction = await client.extractions.create({
  file:         fileB64,                // base64 string
  fileName:     'invoice.pdf',
  contentType:  'application/pdf',      // optional, inferred from fileName
  templateId:   'tpl_invoice',          // optional
});

Convenience: let the SDK encode for you

// Buffer / Uint8Array / ArrayBuffer / Blob / File / Node ReadableStream
await client.extractions.create({
  file:     fs.readFileSync('./invoice.pdf'),  // Buffer — SDK base64-encodes it
  fileName: 'invoice.pdf',
});

The file parameter accepts:

  • A base64 string (with optional data: URI prefix) — sent as-is
  • A Blob or File (browsers)
  • A Buffer, Uint8Array, or ArrayBuffer
  • A Node ReadableStream from fs.createReadStream

Wire format. Every call POSTs a JSON body to /v1/extractions with the shape { file, file_name, content_type, template_id? }. There is no multipart/form-data involved, so the SDK works in edge runtimes, serverless functions, and behind strict egress proxies. Max 20 MB per file (decoded).

client.extractions.retrieve(id)

const extraction = await client.extractions.retrieve('ext_01HZX...');

Errors

All HTTP errors throw a DocPeelError instance with status, code, message, and requestId.

import { DocPeelError } from '@doc-peel/sdk';

try {
  await client.extractions.create({ file });
} catch (err) {
  if (err instanceof DocPeelError && err.code === 'rate_limited') {
    await sleep(1000);
  } else {
    throw err;
  }
}

Browser usage

The SDK works in modern browsers via the global fetch. Pass a File or Blob from an <input type="file" /> — the SDK reads the bytes, base64-encodes them, and sends a JSON request (no FormData or multipart involved).

Never ship a server-side API key to the browser. For browser uploads, route through your backend or use a short-lived signed URL.

See also