> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ndi.nace.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Split a packet

> Cut a scanned packet or workbook into classified segments

Split finds logical documents inside one file. PDFs become page-range
segments. Spreadsheets become one segment per worksheet, then each sheet is
classified against your classes.

<Tabs>
  <Tab title="Python">
    ```python theme={"dark"}
    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)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```ts theme={"dark"}
    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);
    ```
  </Tab>

  <Tab title="curl">
    ```bash theme={"dark"}
    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\"}]}"
    ```
  </Tab>
</Tabs>

## Options

* **`unknown_policy`** — `include` (default), `force`, or `error`
* **`overlap_policy`** — `exclusive` (default). `shared_boundary_page` is reserved
* **`output.include_content`** — attach segment text
* **`output.materialize_files`** — write document segments as child artifacts. Spreadsheet segments always materialize as single-sheet `.xlsx`

`page_ranges` is not supported for spreadsheet sources. Sheet position is
`start_page == end_page == sheet_index + 1`.

A `parse_result` source is supported. After split, extract or ground each
segment (or its materialized file) separately.
