TypeScript SDK
Veriafy SDK for Node.js and browser environments
Installation
npm install @veriafy/sdkOr with yarn:
yarn add @veriafy/sdkQuick Start
import { Veriafy } from '@veriafy/sdk';
// Initialize client
const veriafy = new Veriafy({
apiKey: process.env.VERIAFY_API_KEY, // optional for local mode
});
// Classify a file
const result = await veriafy.classify({
file: './document.pdf',
model: 'veriafy/fraud-detection',
});
console.log(result.vectorId); // Unique hash identifier
console.log(result.categories); // { fraud: 0.92, legitimate: 0.08 }
console.log(result.confidence); // 0.92
console.log(result.action); // 'flag'API Reference
classify(options: ClassifyOptions)
Classify a single file.
interface ClassifyOptions {
file: string | Buffer | ReadableStream;
model: string;
threshold?: number; // default: 0.5
}
interface ClassificationResult {
vectorId: string;
fileType: string;
categories: Record<string, number>;
confidence: number;
action: 'allow' | 'flag' | 'block';
processingTimeMs: number;
}classifyBatch(options: BatchOptions)
Classify multiple files efficiently.
interface BatchOptions {
files: string[];
model: string;
batchSize?: number; // default: 32
onProgress?: (progress: number) => void;
}
const results = await veriafy.classifyBatch({
files: ['doc1.pdf', 'doc2.pdf', 'doc3.pdf'],
model: 'veriafy/fraud-detection',
onProgress: (p) => console.log(`${p}% complete`),
});extractVector(file: string | Buffer)
Extract Veriafy Vector without classification.
const vector = await veriafy.extractVector('./image.jpg');
console.log(vector.id);
console.log(vector.fileType);
console.log(vector.components.perceptualHash);
console.log(vector.components.semanticEmbedding);Browser Usage
The SDK works in browser environments for client-side extraction:
import { Veriafy } from '@veriafy/sdk/browser';
const veriafy = new Veriafy({ apiKey: 'sk-xxxxx' });
// Handle file input
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
const file = e.target.files[0];
// Extract vector client-side (file never uploaded)
const vector = await veriafy.extractVector(file);
// Send only the vector to your backend
await fetch('/api/classify', {
method: 'POST',
body: JSON.stringify({ vector }),
});
});Privacy Benefit
Client-side extraction means the user's file never leaves their browser. Only the Veriafy Vector is transmitted — perfect for privacy-sensitive applications.
Express.js Example
import express from 'express';
import multer from 'multer';
import { Veriafy } from '@veriafy/sdk';
const app = express();
const upload = multer({ storage: multer.memoryStorage() });
const veriafy = new Veriafy();
app.post('/api/moderate', upload.single('file'), async (req, res) => {
try {
const result = await veriafy.classify({
file: req.file.buffer,
model: 'veriafy/nsfw-classifier',
});
if (result.action === 'block') {
return res.status(400).json({
error: 'Content not allowed',
reason: result.categories,
});
}
// Store the vector ID for future reference
await db.files.create({
vectorId: result.vectorId,
action: result.action,
});
res.json({ success: true, vectorId: result.vectorId });
} catch (error) {
res.status(500).json({ error: error.message });
}
});