Identify
Node.js SDK reference for the Identify resource — methods, parameters, and return types for the DocuTray API.
Identify
Resource for identifying document types from images. Access via client.identify.
Methods
run(params, options?)
Creates a synchronous identification request. documentTypeCodeOptions is required: the document type codes to choose from. Without at least one, the SDK throws a DocuTrayError before sending the request.
const result = await client.identify.run({
url: 'https://example.com/document.pdf',
documentTypeCodeOptions: ['invoice', 'receipt'],
});
console.log(result.document_type); // best match
console.log(result.alternatives ?? []); // other matchesParameters: IdentifyParams
Returns: Promise<IdentificationResult>
runAsync(params, options?)
Creates an asynchronous identification request. Returns the enqueue response (id and status: 'ENQUEUED'; documentTypeCode is always null at this point) with a .wait() method for polling.
import fs from 'fs';
const enqueued = await client.identify.runAsync({
file: fs.readFileSync('document.pdf'),
documentTypeCodeOptions: ['invoice', 'receipt'],
});
const result = await enqueued.wait();
if (result.status === 'SUCCESS') {
console.log(result.document_type);
}wait() accepts WaitOptions (pollInterval, timeout, onStatus) and resolves with the final status on both SUCCESS and ERROR: it does not throw when the operation fails, so check status. It rejects only on timeout (APITimeoutError) or when a status request fails.
Parameters: IdentifyParams
Returns: Promise<IdentificationEnqueued & { wait(options?): Promise<IdentificationStatus> }>
getStatus(identificationId, options?)
Retrieves the current status of an identification operation. document_type, alternatives and error are only present once the operation reaches a terminal state.
const status = await client.identify.getStatus('id_abc123');Parameters: identificationId: string
Returns: Promise<IdentificationStatus>
Raw Responses
Access raw HTTP response details via withRawResponse:
const raw = await client.identify.withRawResponse.run({
url: 'https://example.com/document.pdf',
documentTypeCodeOptions: ['invoice', 'receipt'],
});
console.log(raw.statusCode);
const data = await raw.parse();