Classify (Sync)
Classify a document synchronously and receive the routing result immediately.
/api/v1/classify/{classifierId}SYNCClassify a document using AI-powered classification. The classifier analyzes the document and determines which model should be used for optimal data extraction. Returns the classification result immediately.
After classification, you must manually queue the extraction using the process-file-async endpoint with the returned fileId and extractionSchemaId.
The call is identical for project-scoped and global classifiers. With a global classifier the document may be routed to a model in another project of your organization, so resolve the returned extractionSchemaId rather than assuming the model is local.
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. |
Context
context gives the classifier information the file itself does not carry: "Email subject: PO 4411\nFrom: orders@acme.com", or "Folder: Finance/Purchase Orders". It informs both the routing decision and the label. It is evidence, not an instruction: when the context and the document disagree, the document wins, and instructions written inside the context are ignored.
A context longer than 8,000 characters is rejected before the file is looked up or the classifier runs, and nothing is written:
{
"error": "context must be at most 8000 characters (got 9123)"
}A context that is not a string also returns 400.
Request
const response = await fetch(
`https://app.limai.io/api/v1/classify/${CLASSIFIER_ID}`,
{
method: "POST",
headers: {
"Authorization": `Bearer ${API_TOKEN}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ fileId, context: "Email subject: PO 4411" })
}
)
const result = await response.json()Response
Classified Successfully
{
"fileId": "file_abc123def456",
"deploymentName": "Invoice Processing v2",
"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 with process-file to extract data. |
deploymentName | string | Human-readable name of 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 chosen route targets one of the model's deployments, the file is stamped with that deployment, and process-file addressed to the returned extractionSchemaId extracts it through the deployment — its pinned version and pause apply.
Unclassified (not routed)
When the document does not match any of the classifier's routes, or every route that fits it targets a paused deployment:
{
"fileId": null,
"status": "UNCLASSIFIED",
"classificationId": "cls_789jkl",
"cached": false,
"label": {
"id": "lbl_po01",
"name": "Purchase Order",
"isNew": true
}
}UNCLASSIFIED means the document was classified but not routed. The classifier still looked at it and, through label, says what kind of document it is.
Labels
Every classifier keeps its own set of labels, one per document type it has seen. The status says whether a document was routed; the label says what it is.
- Routed documents carry their route's label. Each route has a label named after it.
- Unrouted documents get an existing label when one fits, or a new one the classifier creates, such as
"Purchase Order". The next document of that kind reuses it.isNewistrueonly on the run that created the label. labelisnullwhen the classifier assigned none: the document fits no label and creating one is switched off (the classifier'sallowNewLabelssetting), or the classifier has reached its label limit.
The classifier sees the current labels when it classifies, which keeps names stable. List them with GET /labels, and filter documents by label with GET /classifications.
Repeated Calls
POSTing a file that already has a CLASSIFIED verdict returns that verdict with cached: true. The classifier does not run again, so a retry after a dropped connection or a redelivered message is safe.
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 — caching that verdict would make the second call a no-op. To skip the re-run, read the verdict from get-url instead of POSTing.
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.
Send contentHash on the get-url call to find out, before you upload, whether the classifier already holds these bytes and what it decided about them.
Complete Workflow
const headers = { "Authorization": `Bearer ${API_TOKEN}` }
const urlRes = await fetch(
`https://app.limai.io/api/v1/classify/${CLASSIFIER_ID}/get-url?filename=doc.pdf`,
{ headers }
)
const { url, fileId } = await urlRes.json()
await fetch(url, {
method: "PUT",
headers: { "Content-Type": "application/pdf" },
body: fileData
})
const classifyRes = await fetch(
`https://app.limai.io/api/v1/classify/${CLASSIFIER_ID}`,
{
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ fileId })
}
)
const { extractionSchemaId, deploymentName } = await classifyRes.json()
await fetch(
`https://app.limai.io/api/v1/document/${extractionSchemaId}/process-file-async/${fileId}`,
{
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({})
}
)Webhooks
Every classification also fires the DOCUMENT_CLASSIFIED webhook, whether the document routed or came back unclassified, with the same label. Subscribe to it if you want the decision pushed to you rather than read from the response. When the classifier creates a label, CLASSIFIER_LABEL_CREATED fires as well.