JavaScript / TypeScript SDK
The official DocLD SDK for Node.js and browsers. Published as docld on npm. Supports ESM and CJS and ships full TypeScript types.
Installation
npm install docld- Node.js: 18 or later.
- Bundlers: Use ESM (
import) or CJS (require); the package exports both.
Configuration
Create a client with your API key and optional base URL:
import { DocLD } from 'docld';
const client = new DocLD({
apiKey: process.env.DOCLD_API_KEY,
baseUrl: 'https://api.docld.com', // optional
});| Option | Description |
|---|---|
apiKey | Your DocLD API key. Create one in Settings → API Keys. Required unless DOCLD_API_KEY is set. |
baseUrl | API base URL. Defaults to https://api.docld.com or the DOCLD_BASE_URL environment variable (for self-hosted or custom deployments). |
Quick start
import { DocLD } from 'docld';
const client = new DocLD({ apiKey: 'docld_...' });
// Parse a document from a URL
const result = await client.parse.parse('https://example.com/document.pdf');
console.log(result.result.chunks);
// List documents
const { documents, total } = await client.documents.list({ limit: 10 });API reference
Upload
client.upload.upload(file, options?)
Upload a document. Returns upload metadata and document record.
file — One of:
BloborFile(browser or Node with fetch)Buffer(Node.js){ buffer: ArrayBuffer, name: string }
options (optional):
| Property | Type | Description |
|---|---|---|
parsing_config | Record<string, unknown> | Parsing options (e.g. enhance, settings). |
knowledge_base_id | string | Add the document to this knowledge base. |
organization_id | string | Scope to this organization. |
classification | string | One of: internal, confidential, pii, restricted, public. |
Returns: UploadResult
file_id— e.g.docld://<documentId>for use in parse/extract.document—{ id, name, status, file_type, file_format, parsing_config? }.filename,size,mime_type.queue—{ queued, error }.usage—{ num_pages, credits }.
Parse
client.parse.parse(input, config?)
Parse a document. Input can be a URL, a docld:// reference, or a file upload.
input — One of:
- URL string (
https://...orhttp://...). - DocLD reference string (
docld://<documentId>). File,Blob,Buffer, or{ buffer: ArrayBuffer, name: string }(multipart upload).
config (optional) — Parsing configuration object, e.g.:
enhance— AI enhancement options.settings— e.g.change_tracking.formatting— e.g.include_hyperlinks,include_comments,include_highlights.
Returns: ParseResponse
job_id,duration,usage(num_pages,credits).result—{ type: 'full', chunks: [...] }(each chunk hascontent,blocks, optionalmetadata).studio_link— Link to view in DocLD Studio.
Documents
client.documents.list(params?)
List documents with optional filters and pagination.
params (optional):
| Property | Type | Description |
|---|---|---|
search | string | Filter by name or content. |
status | string | string[] | Filter by status. |
file_type | string | string[] | Filter by file type. |
file_format | string | string[] | Filter by format. |
knowledge_base_id | string | Only documents in this knowledge base. |
tags | string[] | Filter by tags. |
date_from | string | Created on or after (ISO date). |
date_to | string | Created on or before (ISO date). |
sort_by | 'name' | 'created_at' | 'file_size' | 'status' | 'updated_at' | Sort field. |
sort_order | 'asc' | 'desc' | Sort direction. |
limit | number | Page size (default 50, max 100). |
offset | number | Pagination offset. |
Returns: DocumentListResponse — { documents, total, limit, offset, has_more }.
client.documents.get(id) — Get a single document by ID. Returns a Document (includes file_url as signed URL when applicable).
client.documents.delete(id) — Delete a document. Returns void.
client.documents.getParse(id) — Get parsed content for a document. Returns parsed result object.
client.documents.getStatus(id) — Get processing status for a document. Returns status object.
Extract
client.extract.run(body)
Run extraction on a document. Provide exactly one of: input (or document_id), and one of: schema_id, config, or description.
body — ExtractRunInput:
| Property | Type | Description |
|---|---|---|
input | string | Document reference: URL, docld://<id>, or jobid://<jobId>. |
document_id | string | Legacy: document ID. |
schema_id | string | ID of a saved schema (from schemas.list or schemas.get). |
config | Record<string, unknown> | Inline extraction config (fields, instructions). |
description | string | Natural language description for zero-shot extraction. |
include_citations | boolean | Include per-field citations. |
variant_label | string | null | Experiment variant (when using experiments). |
experiment_id | string | Run within an experiment. |
Returns: ExtractResponse
success,job_id,extraction_id?,document_id.data— Extracted key-value object (ornull).field_results?— Per-field value, confidence, and optional citations.overall_confidence?,processing_time?,usage?,error?.
client.extract.schemas.list(params?) — List extraction schemas. Optional params: organization, organization_only, organization_id. Returns { schemas: ExtractionSchema[] }.
client.extract.schemas.get(id) — Get a schema by ID. Returns ExtractionSchema.
client.extract.schemas.create(payload) — Create a schema. payload: CreateSchemaInput (name, description?, instructions?, fields?, settings?, ground_truth_template?, organization_id?, is_shared?, version?). Returns ExtractionSchema.
Errors
Failed requests throw DocLDError (extends Error) with:
message— Human-readable message.code— Optional error code (e.g.NOT_FOUND,VALIDATION_ERROR,UNAUTHORIZED).details— Optional object with extra context.errors— Optional array of{ field, message }for validation errors.
import { DocLD, DocLDError } from 'docld';
try {
await client.documents.get('invalid-id');
} catch (err) {
if (err instanceof DocLDError) {
console.error(err.code, err.message, err.details);
}
throw err;
}TypeScript types
The package includes TypeScript definitions. You can import types for responses and options:
import {
DocLD,
DocLDError,
type ParseResponse,
type DocumentListResponse,
type UploadResult,
type ExtractResponse,
type DocumentListParams,
type ExtractRunInput,
} from 'docld';See also
- API Reference — Full REST endpoint documentation.
- Python SDK — Official Python client.