Skip to content

JavaScript/TypeScript SDK

Full-featured SDK with TypeScript support for Node.js and browsers.


Installation

npm install @archivus/sdk

Quick Start

import { ArchivusClient } from '@archivus/sdk';

const client = new ArchivusClient({
  apiKey: process.env.ARCHIVUS_API_KEY,
  tenant: 'your-tenant'
});

// Upload document
const document = await client.documents.upload({
  file: fileInput.files[0],
  enableAI: true
});

// Search
const results = await client.search.query('contract terms');

// Chat
const session = await client.chat.createSession({ documentId: document.id });
const answer = await client.chat.ask(session.id, 'What are the key terms?');

API Reference

Client Configuration

const client = new ArchivusClient({
  apiKey: 'your-api-key',        // API key or JWT token
  tenant: 'your-tenant',         // Your tenant subdomain
  baseURL: 'https://api.archivus.app/api/v1',  // Optional
  maxRetries: 3,                 // Optional
  timeout: 30000,                // Optional (ms)
});

Documents

// List documents
const documents = await client.documents.list({
  page: 1,
  limit: 20,
  folderId: 'folder_abc123'
});

// Get document
const document = await client.documents.get('doc_abc123');

// Upload document
const document = await client.documents.upload({
  file: file,                    // File or Blob
  folderId: 'folder_abc123',
  enableAI: true,
  tags: ['contract', 'legal']
});

// Update document
const updated = await client.documents.update('doc_abc123', {
  filename: 'new-name.pdf',
  tags: ['updated']
});

// Delete document
await client.documents.delete('doc_abc123');

// Download document
const blob = await client.documents.download('doc_abc123');

// Get content
const content = await client.documents.getContent('doc_abc123');
// Basic search
const results = await client.search.query('contract terms', {
  mode: 'semantic',
  limit: 10,
  folderId: 'folder_abc123'
});

// Enhanced search (Pro+)
const results = await client.search.enhanced({
  query: 'Find contracts expiring in Q4',
  filters: {
    tags: ['contract'],
    dateRange: {
      start: '2026-10-01',
      end: '2026-12-31'
    }
  }
});

Chat

// Create session
const session = await client.chat.createSession({
  documentId: 'doc_abc123',
  name: 'Analysis'
});

// Ask question
const answer = await client.chat.ask(session.id, 'What are the key terms?');

// RAG query (Pro+)
const answer = await client.chat.askRAG(session.id, 'Find all contracts');

// Get messages
const messages = await client.chat.getMessages(session.id);

// List sessions
const sessions = await client.chat.listSessions();

// Delete session
await client.chat.deleteSession(session.id);

Webhooks

// Create webhook
const webhook = await client.webhooks.create({
  url: 'https://yourapp.com/webhooks',
  events: ['document.processed', 'document.failed'],
  secret: 'your-secret'
});

// List webhooks
const webhooks = await client.webhooks.list();

// Update webhook
await client.webhooks.update('webhook_abc123', {
  events: ['document.processed']
});

// Delete webhook
await client.webhooks.delete('webhook_abc123');

TypeScript Support

The SDK is fully typed:

import { ArchivusClient, Document, SearchResult, ChatSession } from '@archivus/sdk';

const client = new ArchivusClient({
  apiKey: process.env.ARCHIVUS_API_KEY!,
  tenant: 'your-tenant'
});

const document: Document = await client.documents.get('doc_abc123');
const results: SearchResult[] = await client.search.query('query');
const session: ChatSession = await client.chat.createSession({
  documentId: document.id
});

Error Handling

import { ArchivusError, RateLimitError, NotFoundError } from '@archivus/sdk';

try {
  const document = await client.documents.get('doc_abc123');
} catch (error) {
  if (error instanceof NotFoundError) {
    console.error('Document not found');
  } else if (error instanceof RateLimitError) {
    console.error('Rate limit exceeded, retry after:', error.retryAfter);
  } else if (error instanceof ArchivusError) {
    console.error('API error:', error.code, error.message);
  }
}

Webhook Verification

import express from 'express';
import { verifyWebhookSignature } from '@archivus/sdk';

const app = express();

app.post('/webhooks/archivus',
  express.raw({ type: 'application/json' }),
  (req, res) => {
    const signature = req.headers['x-archivus-signature'];
    const isValid = verifyWebhookSignature(
      req.body.toString(),
      signature,
      process.env.WEBHOOK_SECRET
    );

    if (!isValid) {
      return res.status(401).send('Invalid signature');
    }

    const event = JSON.parse(req.body.toString());
    handleEvent(event);

    res.json({ status: 'ok' });
  }
);

Browser Usage

<!DOCTYPE html>
<html>
<head>
  <script type="module">
    import { ArchivusClient } from 'https://cdn.skypack.dev/@archivus/sdk';

    const client = new ArchivusClient({
      apiKey: 'YOUR_API_KEY',
      tenant: 'your-tenant'
    });

    async function uploadFile() {
      const fileInput = document.getElementById('file');
      const file = fileInput.files[0];

      const document = await client.documents.upload({
        file,
        enableAI: true
      });

      console.log('Uploaded:', document);
    }
  </script>
</head>
<body>
  <input type="file" id="file" />
  <button onclick="uploadFile()">Upload</button>
</body>
</html>

Next Steps