Classify (Async)
Classify a document and automatically trigger extraction in a single call.
/api/v1/classify/{classifierId}/asyncASYNCClassify 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.
The call is identical for project-scoped and global classifiers. With a global classifier the extraction runs in whichever project owns the routed model.
Parameters
| Name | Type | In | Required | Description |
|---|---|---|---|---|
classifierId | string | path | Yes | The classifier ID from your classifier settings. |
fileId | string | body | Yes | The file ID returned from the classifier get-url endpoint after uploading. |
context | string | body | No | Free text the classifier reads as supporting evidence, such as an email subject and sender, a SharePoint folder path, or a note. At most 8,000 characters. Stored on the classification. Works as on the sync endpoint. |
A context longer than 8,000 characters is rejected before the file is looked up, the classifier runs, or extraction is queued:
{
"error": "context must be at most 8000 characters (got 9123)"
}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.
{
"fileId": "file_abc123def456",
"deploymentName": "Invoice Processing",
"extractionSchemaId": "schema_789xyz012",
"classificationId": "cls_456def",
"cached": false,
"label": {
"id": "lbl_invoice01",
"name": "Invoice",
"isNew": false
}
}| Field | Type | Description |
|---|---|---|
fileId | string | The classified file ID. Use this to poll for extraction results. |
deploymentName | string | The model the document was routed to. |
extractionSchemaId | string | The routed model's extraction schema ID, or the model's own ID when it has no legacy extraction schema. Pass it to the process-file endpoints. |
classificationId | string | The classification run this verdict comes from. Read it back with the status endpoint. |
cached | boolean | true when the file already had this verdict and it was returned without running the classifier. |
label | object | null | The document type: { id, name, isNew }. A routed document carries its route's label. See Labels. |
When the document does not match any of the classifier's routes, or every route that fits it targets a paused deployment, the response is {"fileId": null, "status": "UNCLASSIFIED", "classificationId": "cls_789jkl", "cached": false, "label": {"id": "lbl_po01", "name": "Purchase Order", "isNew": true}} and no extraction is queued. UNCLASSIFIED means classified but not routed; label still says what the document is.
Repeated Calls
POSTing a file that already has a CLASSIFIED verdict returns that verdict with cached: true; the classifier does not run again. Extraction is still queued, because this endpoint's contract is that a call ends with the document on its way through extraction — so re-sending a classified file re-processes it, and a fresh extraction replaces that document's rows.
A file whose latest verdict is UNCLASSIFIED, and which is therefore still unclassified, is re-run. An unclassified document usually means no route matched it, so re-sending it after adding a route is how you classify it. To find out what the classifier already decided before you send anything, pass contentHash to get-url.
A POST that arrives while a classification of the same file is still running waits for that run and returns its verdict with cached: true, instead of starting a second one.
Reading a Verdict Back
GET /api/v1/classify/{classifierId} returns a classification's status. Identify it either by the run or by the file — exactly one of the two query parameters is required.
| Name | Type | In | Required | Description |
|---|---|---|---|---|
classifierId | string | path | Yes | The classifier ID from your classifier settings. |
classificationId | string | query | No | The classification run, as returned by the classify endpoints. Mutually exclusive with fileId. |
fileId | string | query | No | A file ID. Returns the latest classification of that file in this classifier. Mutually exclusive with classificationId. |
const response = await fetch(
`https://app.limai.io/api/v1/classify/${CLASSIFIER_ID}?fileId=${fileId}`,
{ headers: { "Authorization": `Bearer ${API_TOKEN}` } }
)
const { classificationId, status, routedDeployment } = await response.json()The response carries classificationId, status, fileId, fileName, classifierName, routedDeployment ({ id, name } or null), the confidence scores, the classifier's reasoning, unclassifiedReason, errorMessage, the manual-routing fields, label ({ id, name } or null), context (the context the run used, or null), createdAt and updatedAt.
{
"classificationId": "cls_789jkl",
"status": "UNCLASSIFIED",
"fileId": "file_012mno",
"fileName": "po-4411.pdf",
"classifierName": "Inbox",
"routedDeployment": null,
"confidenceScore": 0.22,
"decisionConfidence": 0.88,
"reasoning": "A purchase order; no route covers purchase orders",
"unclassifiedReason": "No route matches this document type",
"errorMessage": null,
"manualRoutedBy": null,
"manualRoutedAt": null,
"label": {
"id": "lbl_po01",
"name": "Purchase Order"
},
"context": "Email subject: PO 4411",
"createdAt": "2026-11-12T10:32:05.000Z",
"updatedAt": "2026-11-12T10:32:11.000Z"
}Classifications made before labels existed have label: null until they are classified again.
To list many classifications at once, filtered by status or label, use GET /classifications.
Querying by fileId is what makes a lost response recoverable: after a timeout or a redelivered message, ask the classifier what it holds for that file rather than classifying it again.
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) | |
|---|---|---|
| Classification | Returns result immediately | Returns result immediately |
| Extraction | Must be queued manually | Triggered automatically |
| Polling | Requires fileId + extractionSchemaId | Requires only fileId |
| Best for | Custom routing logic after classification | Simple end-to-end pipelines |
Skip the Polling
Rather than polling get-file-data, subscribe to the DOCUMENT_CLASSIFIED webhook. It fires once the classifier reaches a decision and carries the outcome, the confidence, the classifier's own reasoning, and the routed model -- for documents that routed and for documents that did not, on the same event. DOCUMENT_CLASSIFICATION_FAILED covers the runs that broke.