Limai Docs
API ReferenceClassification

Get Classifier Upload URL

Get a pre-signed URL for uploading files to be classified.

GET/api/v1/classify/{classifierId}/get-url

Request a pre-signed URL for uploading files that need to be classified. Returns both the upload URL and a file ID that you will use in the classification request.

The endpoint works the same way for project-scoped and global classifiers.

Parameters

NameTypeInRequiredDescription
classifierIdstringpathYesThe classifier ID. Found in your classifier settings in the platform.
filenamestringqueryYesThe original filename of the document to classify.
contentHashstringqueryNoSHA-256 of the file's bytes, lowercase hex. Turns on duplicate detection; without it every request creates a new file.
allowDuplicatebooleanqueryNoSet to true to skip duplicate detection and always create a new file, which is how you re-classify the same bytes on purpose. Omitting it is the same as false.

Duplicate Detection

Detection is scoped to this classifier: it looks for a file already sent to the same classifier whose content hash matches. "Same file" means the same bytes, not the same name — a renamed copy of a document you already sent is a duplicate, and two different documents that share a filename are not.

Detection only runs when you send contentHash. Compute the SHA-256 of the bytes you are about to upload and pass it as lowercase hex; the platform never hashes the content for you on this path.

On a match no new file is created. The response carries the existing file's fileId, isDuplicate is true, url is an empty string, and classification carries the latest verdict that classifier reached for that file:

Response200
{
  "url": "",
  "fileId": "file_abc123def456",
  "isDuplicate": true,
  "existingFileId": "file_abc123def456",
  "classification": {
    "classificationId": "cls_456def",
    "status": "CLASSIFIED",
    "deploymentName": "Invoice Processing v2",
    "extractionSchemaId": "schema_789xyz012",
    "modelId": "dep_123abc",
    "classifiedAt": "2024-01-15T10:31:05Z"
  }
}

When url is empty, do not upload. There is nothing to PUT: the bytes are already stored. Skip the upload and continue with the returned fileId.

classification is null when the matching file was uploaded but never classified. Otherwise it describes the most recent classification run for that file in this classifier:

FieldTypeDescription
classificationIdstringThe classification run. Read it back with the status endpoint.
statusstringCLASSIFIED, UNCLASSIFIED, PROCESSING, or FAILED.
deploymentNamestring | nullHuman-readable name of the deployment the document was routed to. null unless the status is CLASSIFIED.
extractionSchemaIdstring | nullThe extraction schema ID of the routed model or deployment. null unless the status is CLASSIFIED.
modelIdstring | nullThe routed model's own ID. null unless the status is CLASSIFIED.
classifiedAtstringISO timestamp of the run.

What to do next depends on classification.status:

  • CLASSIFIED — you already have the verdict. Skip the classify call and go straight to process-file with the returned fileId and extractionSchemaId.
  • Anything else, or classification: null — call classify with the returned fileId. A file whose latest verdict is UNCLASSIFIED is re-run, so re-sending it after adding a route works.

With allowDuplicate=true the lookup is skipped and a genuine second file is created, with a new fileId, a pre-signed upload URL, and isDuplicate set to false. That is the way to force a fresh classification run on bytes that were already classified.

The file ID is stable through routing: when the classifier routes a document, the same file row moves to the routed model, so the fileId this endpoint returns is the id the document endpoints use for that document afterwards.

Request

import { createHash } from "node:crypto"

const contentHash = createHash("sha256").update(fileData).digest("hex")

const response = await fetch(
`https://app.limai.io/api/v1/classify/${CLASSIFIER_ID}/get-url?filename=${filename}&contentHash=${contentHash}`,
{
  headers: { "Authorization": `Bearer ${API_TOKEN}` }
}
)
const { url, fileId, isDuplicate, classification } = await response.json()

if (!isDuplicate) {
await fetch(url, {
  method: "PUT",
  headers: { "Content-Type": "application/pdf" },
  body: fileData
})
}

Response

Response200
{
  "url": "https://s3.amazonaws.com/bucket/path?AWSAccessKeyId=...",
  "fileId": "abc123def456",
  "isDuplicate": false
}

Response Fields

FieldTypeDescription
urlstringPre-signed URL for uploading the file. Temporary and expires after a short period. Empty when the content is a duplicate.
fileIdstringUnique file identifier. Use this in the classification request after uploading. For a duplicate, the identifier of the file the classifier already holds.
isDuplicatebooleanWhether these bytes were already sent to this classifier. Always false when you send no contentHash.
existingFileIdstringThe matched file's identifier, same value as fileId. Returned with a duplicate.
classificationobject | nullThe latest verdict for the matched file, or null when it was never classified. Returned with a duplicate.

Next Steps

After receiving the upload URL:

  1. Upload your file to the pre-signed URL using a PUT request, unless url is empty
  2. Classify the document using sync classification or async classification

On this page