Node.js SDK
Official Node.js library for the DocuTray API
Node.js SDK
The official Node.js library for the DocuTray API, providing access to document processing capabilities including OCR, document identification, data extraction, and knowledge bases.
Installation
npm install docutrayRequires Node.js 20+.
Quick Start
import DocuTray from 'docutray';
import { readFileSync } from 'fs';
const client = new DocuTray({ apiKey: 'your-api-key' });
// Convert a document
const result = await client.convert.run({
file: readFileSync('invoice.pdf'),
documentTypeCode: 'invoice',
});
console.log(result.data);Async Conversion
For large documents, use async conversion with polling:
const status = await client.convert.runAsync({
file: readFileSync('large_document.pdf'),
documentTypeCode: 'invoice',
});
// Poll for completion
const final = await status.wait();
if (final.isSuccess()) {
console.log(final.data);
}Configuration
// Via constructor
const client = new DocuTray({ apiKey: 'your-api-key' });
// Via environment variable (DOCUTRAY_API_KEY)
const client = new DocuTray();Resources
Client
The main entry point for the SDK:
DocuTray— Client class with resource properties
API Resources
- Convert — Document conversion and data extraction
- Identify — Automatic document type identification
- DocumentTypes — Document type catalog and schema validation
- Steps — Workflow step execution
- KnowledgeBases — Knowledge base management and semantic search
Error Handling
- Error Hierarchy — Comprehensive error classes with status-specific exceptions
Types
Response and model types:
Get monthly usage for your organization GET
Returns how many pages and operations your organization has successfully processed in a given month. Use it to surface consumption in your own admin UI, build usage alerts before hitting your plan's quota, or reconcile invoices. The organization is identified by the API key in the request — there is no `organizationId` parameter and you cannot query other organizations. **Behavior:** - When `year` and `month` are omitted, the endpoint returns counters for the current month. - When the organization has no recorded usage for the requested month (e.g. the month is in the future, or the organization didn't process anything), both counters return `0` — this is not an error. - This endpoint is **not** subject to quota enforcement. Calling it does not count toward your usage and is never blocked by 429/402. **What `successful_conversions` counts:** any operation that completed successfully — both document conversions and document identifications. The name is kept singular for backwards compatibility.
Client
DocuTray client class and configuration options