Limai Docs
API ReferenceClassification

Classify (Async)

Classify a document and automatically trigger extraction in a single call.

POST/api/v1/classify/{classifierId}/asyncASYNC

Classify a document and automatically trigger extraction with a single API call. Classification happens immediately and returns the result, while extraction runs in the background. This eliminates the need to manually queue extraction after classification.

Parameters

NameTypeInRequiredDescription
classifierIdstringpathYesThe classifier ID from your classifier settings.
fileIdstringbodyYesThe file ID returned from the classifier get-url endpoint after uploading.

Request

const response = await fetch(
`https://app.limai.io/api/v1/classify/${CLASSIFIER_ID}/async`,
{
  method: "POST",
  headers: {
    "Authorization": `Bearer ${API_TOKEN}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({ fileId })
}
)
const { fileId: classifiedFileId, deploymentName, extractionSchemaId } = await response.json()

Response

Returns the classification result immediately. Extraction is triggered automatically in the background.

Response200
{
  "fileId": "file_abc123def456",
  "deploymentName": "Invoice Processing",
  "extractionSchemaId": "schema_789xyz012"
}
FieldTypeDescription
fileIdstringThe classified file ID. Use this to poll for extraction results.
deploymentNamestringThe deployment the document was routed to.
extractionSchemaIdstringThe extraction schema used for data extraction.

Polling for Results

After async classification, poll the get-file-data endpoint using just the fileId. The status may transition through CLASSIFYING and PROCESSING before reaching COMPLETED.

async function pollForResults(fileId) {
while (true) {
  const response = await fetch(
    `https://app.limai.io/api/v1/document/get-file-data?fileId=${fileId}`,
    { headers: { "Authorization": `Bearer ${API_TOKEN}` } }
  )
  const data = await response.json()

  if (data.status === "COMPLETED") return data
  if (data.status === "FAILED") throw new Error(data.errorMessage)

  await new Promise(r => setTimeout(r, 5000))
}
}

Sync vs Async Classification

Sync (/classify/{id})Async (/classify/{id}/async)
ClassificationReturns result immediatelyReturns result immediately
ExtractionMust be queued manuallyTriggered automatically
PollingRequires fileId + extractionSchemaIdRequires only fileId
Best forCustom routing logic after classificationSimple end-to-end pipelines