- Python
- TypeScript
- curl
from ndi_sdk import NdiClient
from ndi_sdk.models.document_ops import SplitCategory
with NdiClient() as client:
packet = client.documents.create_upload("packet.pdf")
job = client.jobs.wait(
client.documents.split(
packet,
classes=[
SplitCategory(id="invoice", label="Invoice", description="A supplier invoice"),
SplitCategory(id="receipt", label="Receipt", description="A payment receipt"),
],
wait_seconds=30,
).job_id
)
for segment in job.result.segments:
print(segment.start_page, segment.end_page, segment.split_class)
import { NdiClient } from "ndi-sdk";
const client = new NdiClient();
const packet = await client.documents.createUpload("packet.pdf");
const job = await client.jobs.wait(
(
await client.documents.split(packet, {
classes: [
{ id: "invoice", label: "Invoice", description: "A supplier invoice" },
{ id: "receipt", label: "Receipt", description: "A payment receipt" },
],
wait_seconds: 30,
})
).job_id,
);
console.log(job.result);
UPLOAD_ID=$(curl -s -X POST "$NDI_BASE_URL/v1/uploads" \
-H "X-API-Key: $NDI_API_KEY" \
-F "file=@packet.pdf" | jq -r '.upload_id')
curl -s -X POST "$NDI_BASE_URL/v1/split?wait_seconds=60" \
-H "X-API-Key: $NDI_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"source\":{\"type\":\"upload\",\"upload_id\":\"$UPLOAD_ID\"},\"classes\":[{\"id\":\"invoice\",\"label\":\"Invoice\",\"description\":\"A supplier invoice\"},{\"id\":\"receipt\",\"label\":\"Receipt\",\"description\":\"A payment receipt\"}]}"
Options
| Option | Default | Meaning |
|---|---|---|
classes | you must set this | Document classes to cut on. Spreadsheets classify each worksheet against these classes |
unknown_policy | include | include keeps unmatched pages as unclassified; force assigns the best class; error fails the job |
overlap_policy | exclusive | exclusive keeps segments disjoint; shared_boundary_page includes a boundary page in both adjacent segments |
split_rules | none | Optional free-text guidance for how to cut the packet |
output.include_content | false | When true, each segment includes its extracted markdown in content |
output.materialize_files | false | When true, each document segment includes a downloadable artifact. Spreadsheet segments always materialize as single-sheet .xlsx |
page_ranges | all pages | One-based inclusive ranges. Not supported for spreadsheet sources |
Result
result.segments is the ordered cut list.
| Field | Meaning |
|---|---|
start_page / end_page | Inclusive page range of this cut. For workbooks, both equal sheet_index + 1 — one segment per worksheet |
status | Whether this cut was assigned a class. matched has class. unclassified was kept because unknown_policy is include |
class | JSON name of the winning request class for a matched segment. Null when unclassified. The Python SDK attribute is split_class |
content | Segment markdown when output.include_content is true. Null otherwise |
artifacts | Downloadable files when output.materialize_files ran (spreadsheet segments always materialize as a single-sheet .xlsx) |
parse_result source is supported. After split, extract or ground each
segment (or its materialized file) separately.