Skip to main content
The Documents API provides endpoints for managing documents in the vault, including upload, processing, tagging, and retrieval.

Query Endpoints

get

Retrieve a paginated list of documents.
q
string
Search query for document name or content
tag
string
Filter by tag name
start
string
Start date filter (ISO 8601)
end
string
End date filter (ISO 8601)
sort
array
Array of sort objects
limit
number
Number of results per page
import { trpc } from '@/lib/trpc';

const { data, meta } = await trpc.documents.get.query({
  tag: 'receipts',
  start: '2024-01-01',
  end: '2024-12-31',
});

getById

Retrieve a specific document by ID or file path.
id
string
Document UUID
filePath
array
Array of path tokens (alternative to id)
document
object
const document = await trpc.documents.getById.query({
  id: 'document-uuid',
});

// Or by file path
const document = await trpc.documents.getById.query({
  filePath: ['vault', 'team-id', 'receipt.pdf'],
});

getRelatedDocuments

Get documents related to a specific document (based on tags, date, etc.).
id
string
required
Document UUID
pageSize
number
Number of results to return
documents
array
Array of related document objects
const related = await trpc.documents.getRelatedDocuments.query({
  id: 'document-uuid',
  pageSize: 5,
});

checkAttachments

Check if a document is attached to any transactions or invoices.
id
string
required
Document UUID
data
object
const { hasAttachments, transactionCount } = await trpc.documents.checkAttachments.query({
  id: 'document-uuid',
});

if (hasAttachments) {
  console.log(`Document is attached to ${transactionCount} transactions`);
}

Mutation Endpoints

delete

Delete a document from the vault.
id
string
required
Document UUID
document
object
The deleted document object
await trpc.documents.delete.mutate({
  id: 'document-uuid',
});
Deleting a document also removes it from storage. This action cannot be undone.

processDocument

Trigger processing for uploaded documents (OCR, text extraction).
documents
array
required
Array of document objects to process
type DocumentToProcess = {
  filePath: string[];  // Path tokens in storage
  mimetype: string;    // MIME type (e.g., 'application/pdf')
};
data
object
const result = await trpc.documents.processDocument.mutate([
  {
    filePath: ['vault', 'team-id', 'invoice-001.pdf'],
    mimetype: 'application/pdf',
  },
  {
    filePath: ['vault', 'team-id', 'receipt-002.jpg'],
    mimetype: 'image/jpeg',
  },
]);

console.log('Processing jobs:', result.jobs);
Supported file types for processing: PDF, images (JPEG, PNG), and text files. Other file types will be marked as completed without processing.

reprocessDocument

Reprocess a document that failed or needs updating.
id
string
required
Document UUID
data
object
const result = await trpc.documents.reprocessDocument.mutate({
  id: 'document-uuid',
});

if (result.success) {
  console.log('Reprocessing job ID:', result.jobId);
}

Signed URLs

signedUrl

Generate a temporary signed URL for downloading a document.
filePath
array
required
Array of path tokens
expireIn
number
Expiration time in seconds (default: 60)
signedUrl
string
Temporary URL for downloading the file
const { signedUrl } = await trpc.documents.signedUrl.mutate({
  filePath: ['vault', 'team-id', 'receipt.pdf'],
  expireIn: 300, // 5 minutes
});

// Use the signed URL to download or display the file
window.open(signedUrl);

signedUrls

Generate multiple signed URLs at once.
filePaths
array
required
Array of file path arrays
urls
array
Array of signed URLs (same order as input)
const urls = await trpc.documents.signedUrls.mutate([
  ['vault', 'team-id', 'file1.pdf'],
  ['vault', 'team-id', 'file2.jpg'],
  ['vault', 'team-id', 'file3.png'],
]);

// urls is an array of signed URL strings
urls.forEach((url, index) => {
  console.log(`File ${index + 1}: ${url}`);
});

Document Processing

The document processing system automatically extracts text and metadata from uploaded files.

Processing Flow

  1. Upload - Files are uploaded to Supabase storage
  2. Queue - Call processDocument to queue processing jobs
  3. Process - Background workers extract text using OCR/parsers
  4. Complete - Document status changes to “completed”

Supported File Types

  • PDF - Text extraction and OCR for scanned PDFs
  • Images - JPEG, PNG (OCR applied)
  • Text - Plain text files

Example: Upload and Process

// 1. Upload file to storage
const filePath = await uploadToStorage(file);

// 2. Queue processing
const result = await trpc.documents.processDocument.mutate([{
  filePath,
  mimetype: file.type,
}]);

// 3. Monitor status
const document = await trpc.documents.getById.query({ filePath });
console.log('Processing status:', document.processingStatus);

Tagging

Documents can be organized using tags through the tRPC API’s documentTags and documentTagAssignments routers.

Build docs developers (and LLMs) love