Limai Docs
API ReferenceWebhooks

Document Split Event

Webhook event fired when a splitter finishes breaking a document into segments.

The DOCUMENT_SPLIT event fires when a splitter finishes. It carries every segment the splitter produced, including the file id of each one, so you can follow the children downstream without polling.

When It Triggers

When a split run reaches COMPLETED. A split that produced no usable segments still fires this event with segmentCount of 0 -- it completed, it just found nothing to keep.

This is a splitter event, routed to subscriptions by splitter route.

Payload Structure

Response200
{
  "eventId": "evt_split_201",
  "eventType": "DOCUMENT_SPLIT",
  "timestamp": "2024-01-15T10:35:02Z",
  "organizationId": "org_xyz789",
  "projectId": "proj_abc123",
  "splitterId": "spl_123abc",
  "splitId": "split_456def",
  "fileId": "file_789ghi",
  "data": {
    "status": "completed",
    "sourcePageCount": 4,
    "segmentCount": 2,
    "segments": [
      {
        "segmentIndex": 0,
        "pageStart": 1,
        "pageEnd": 2,
        "detectedType": "COMMERCIAL_INVOICE",
        "confidence": 0.9,
        "outputFileId": "file_child_1",
        "outputType": "FILE",
        "discarded": false
      },
      {
        "segmentIndex": 1,
        "pageStart": 3,
        "pageEnd": 4,
        "detectedType": "DELIVERY_NOTE",
        "confidence": 0.85,
        "outputFileId": "file_child_2",
        "outputType": "UNCLASSIFIED_FILE",
        "discarded": false
      }
    ]
  }
}

Payload Fields

FieldTypeDescription
eventIdstringUnique event identifier. Use for idempotency.
eventTypestringAlways "DOCUMENT_SPLIT"
timestampISO 8601When the split completed (UTC)
organizationIdstringYour organization identifier
projectIdstringThe project the splitter belongs to
splitterIdstringThe splitter that ran
splitIdstringThis split run
fileIdstringThe source file that was split
data.status"completed"Always "completed" for this event
data.sourcePageCountnumber | nullPages in the source document
data.segmentCountnumberSegments kept (discarded segments are not counted)
data.segmentsarrayEvery segment, including discarded ones

Segment fields

FieldTypeDescription
segmentIndexnumberPosition in the source document, from 0
pageStartnumberFirst page of the segment, 1-based and inclusive
pageEndnumberLast page of the segment, inclusive
detectedTypestring | nullWhat the splitter thinks the segment is
confidencenumberHow confident it is, 0--1
outputFileIdstring | nullThe file created for this segment. null when the segment was discarded.
outputType"FILE" | "UNCLASSIFIED_FILE"UNCLASSIFIED_FILE means the segment went on to a classifier; FILE means it went straight to a deployment.
discardedbooleanWhether the splitter dropped this segment

Following the children

fileId at the top level is the source document. The children are data.segments[].outputFileId.

A segment whose outputType is UNCLASSIFIED_FILE is handed to a classifier next -- its outputFileId is the same id you will see on the resulting DOCUMENT_CLASSIFIED event, so you can join the two without any extra lookup.

Handling the Event

function handleDocumentSplit(event) {
const { fileId, data } = event

console.log(`${fileId} split into ${data.segmentCount} segments`)

for (const segment of data.segments) {
  if (segment.discarded) continue
  trackChild(segment.outputFileId, {
    parentFileId: fileId,
    pages: [segment.pageStart, segment.pageEnd],
    detectedType: segment.detectedType,
  })
}
}

On this page