Skip to Content

Node.js SDK — Client

The Node.js SDK provides a single Expunct client class. All methods are asynchronous and return promises.

Expunct

import { Expunct } from '@expunct/sdk'; const client = new Expunct({ apiKey: string; baseUrl?: string; // default: "https://api.expunct.ai" timeout?: number; // default: 30000 (ms) maxRetries?: number; // default: 3 });

Constructor Options

OptionTypeDefaultDescription
apiKeystringrequiredYour API key
baseUrlstringhttps://api.expunct.aiAPI base URL
timeoutnumber30000Request timeout in milliseconds
maxRetriesnumber3Max retries with exponential backoff

Resources

The client exposes six resource objects:

client.redact // RedactResource -- text and URI redaction client.jobs // JobsResource -- job management client.batch // BatchResource -- batch operations client.policies // PoliciesResource -- redaction policies client.apiKeys // ApiKeysResource -- API key management client.audit // AuditResource -- audit log access

Convenience Methods

sanitizeText(text: string, options?: SanitizeOptions): Promise<RedactResponse>

Redact PII from a text string. Delegates to client.redact.text().

sanitizeFile(inputUri: string, options?: SanitizeOptions): Promise<JobResponse>

Submit a file for redaction. Delegates to client.redact.uri().

sanitizeUri(inputUri: string, options?: SanitizeOptions): Promise<JobResponse>

Submit a URI for redaction. Delegates to client.redact.uri().

SanitizeOptions

Optional configuration passed to convenience methods:

interface SanitizeOptions { piiTypes?: string[]; confidenceThreshold?: number; language?: string; policyId?: string; outputUri?: string; }

Example

import { Expunct } from '@expunct/sdk'; const client = new Expunct({ apiKey: 'pk_live_...' }); // Inline text redaction const result = await client.sanitizeText( 'John Smith lives at 123 Main St', { piiTypes: ['PERSON', 'ADDRESS'] }, ); console.log(result.redactedText); // File redaction (async job) const job = await client.sanitizeFile('s3://my-bucket/report.pdf'); console.log(`Job ${job.id} status: ${job.status}`);

BaseClient

The Expunct class extends an internal BaseClient that handles HTTP communication, authentication, retry logic, and error mapping. You do not need to interact with BaseClient directly, but it provides the following internal behavior:

  • Authentication: Sends the API key as a Bearer token in the Authorization header
  • Retry logic: Automatically retries on HTTP 429, 500, 502, 503, 504 with exponential backoff and jitter
  • Timeout: Aborts requests that exceed the configured timeout using AbortController
  • Error mapping: Maps HTTP error responses to typed error classes (AuthenticationError, NotFoundError, etc.)

Retry Behavior

The SDK automatically retries requests on transient failures using exponential backoff with jitter. The maxRetries option controls the maximum number of retry attempts.

// Retry up to 5 times with exponential backoff const client = new Expunct({ apiKey: 'pk_live_...', maxRetries: 5, });