Skip to main content
Automatically identify and split PDFs that contain multiple documents (like batch-scanned files) into their component parts. Before you begin, make sure you have:
  1. A Datalab account with an API key (new accounts include $5 in free credits)
  2. Python 3.10+ installed
  3. The Datalab SDK: pip install datalab-python-sdk
  4. Your DATALAB_API_KEY environment variable set
EU requests return a signed result_url; the REST examples below download it before reading the output. See Regional Result Downloads, including the Python SDK 0.5.0 limitation.
Building for production? Use Pipelines to chain processors, version your configuration, and deploy with a single API call.

Choose Page or Block Boundaries

With fast or balanced parsing, the standard block-level base rate is $4.50 / 1K pages. Accurate parsing costs more. See Billing for regional and account pricing.
Set granularity="page" explicitly to skip parsing. segmentation_strategy="document_boundary" alone still produces parsed output and incurs conversion charges. Page-only mode does not accept named segments or a custom prompt.

Quick Start

This example requests page boundaries without parsing the text.

When to Use

Segmentation is useful when:
  • Batch-scanned documents are combined into a single PDF
  • Multiple document types are stapled together
  • You need to apply different processing to different sections

Block-Level Segmentation

Use block boundaries when multiple documents share a page. The parsed output belongs to the whole document; use each segment’s start_block, end_block, and blocks references to locate its content. Splitting only by pages can include content from neighboring segments.

Segmentation Schema

Pass a JSON-encoded object in segmentation_schema:

Response Format

Example page-boundary result:

Process Each Segment

After page-level segmentation, process each segment separately. The example below handles names matching Invoice or Contract; adapt the routing to the names in your results.

Using Checkpoints

If you already converted a document with save_checkpoint=True using the Convert API, pass the checkpoint_id to SegmentOptions to skip re-parsing. This saves time and cost when running segmentation on a previously converted document.

Custom Segmentation Schema

Define expected segment types with name and description. Named segmentation requires parsed content. Automatic segment names are generated from the document and are not guaranteed to match your application labels.

Next Steps

Structured Extraction

Extract structured data from document segments using JSON schemas.

Handling Long Documents

Tips for TOC-based segmentation on documents with 50+ pages.

Document Conversion

Convert documents to Markdown, HTML, JSON, or chunks.

Pipelines

Chain processors into versioned, reusable pipelines.