TypeScript SDK
TypeScript SDK
Section titled “TypeScript SDK”The official TypeScript SDK for integrating with the LMIF API.
Installation
Section titled “Installation”npm install @lookmaimfamous/lmifyarn add @lookmaimfamous/lmifpnpm add @lookmaimfamous/lmifQuick Start
Section titled “Quick Start”import { LMIFClient } from '@lookmaimfamous/lmif';
const lmif = new LMIFClient({ apiKey: process.env.LMIF_API_KEY,});
// Check if an identity is protectedconst result = await lmif.identity.check({ name: 'Taylor Swift', imageUrl: 'https://example.com/avatar.jpg',});
if (result.isBoxed) { console.log('Identity is protected:', result.policy);}Configuration
Section titled “Configuration”const lmif = new LMIFClient({ // Required: Your API key apiKey: 'lmif_live_xxx',
// Optional: Override environment detection environment: 'production', // or 'sandbox'
// Optional: Custom timeout (default: 30000ms) timeout: 60000,
// Optional: Custom retry configuration retry: { maxRetries: 3, retryDelay: 1000, },});Identity Check
Section titled “Identity Check”The core method for checking if an identity is protected.
Single Check
Section titled “Single Check”const result = await lmif.identity.check({ name: 'Celebrity Name', imageUrl: 'https://example.com/avatar.jpg', description: 'AI companion avatar', // Optional context: 'avatar_creation', // Optional});
// Result typeinterface IdentityCheckResult { isBoxed: boolean; isClaimed: boolean; confidence: number; matchedIdentity?: { claimId: string; boxId: string; name: string; entityType: EntityType; verificationTier: VerificationTier; }; policy?: PolicyType; policyDetails?: PolicyDetails; action: RecommendedAction;}Batch Check
Section titled “Batch Check”const results = await lmif.identity.checkBatch([ { id: 'avatar_1', name: 'Celebrity A', imageUrl: 'https://...' }, { id: 'avatar_2', name: 'Celebrity B', imageUrl: 'https://...' }, { id: 'avatar_3', name: 'Celebrity C', imageUrl: 'https://...' },]);
// Returns array of results with your IDsresults.forEach((result) => { console.log(`${result.id}: ${result.action}`);});Claims
Section titled “Claims”Manage identity claims.
// List claimsconst claims = await lmif.claims.list({ status: 'verified', limit: 20,});
// Get a claimconst claim = await lmif.claims.get('claim_xyz789');
// Create a claimconst newClaim = await lmif.claims.create({ name: 'John Smith', variations: ['J. Smith'], entityType: 'INDIVIDUAL', referenceImages: [ { url: 'https://example.com/photo.jpg', isPrimary: true }, ],});
// Update a claimawait lmif.claims.update('claim_xyz789', { variations: ['J. Smith', 'Johnny Smith'],});
// Delete a claimawait lmif.claims.delete('claim_xyz789');Manage protection boxes.
// List boxesconst boxes = await lmif.boxes.list({ policy: 'MONETIZE',});
// Get a boxconst box = await lmif.boxes.get('box_abc123');
// Create a boxconst newBox = await lmif.boxes.create({ claimId: 'claim_xyz789', policy: 'MONETIZE', enforcement: 'MODERATE', policyConfig: { royaltyRate: 0.10, revenueTypes: ['subscription', 'per_message', 'tips'], },});
// Update a boxawait lmif.boxes.update('box_abc123', { policy: 'BLOCK_ALL',});
// Delete a boxawait lmif.boxes.delete('box_abc123');
// Get statisticsconst stats = await lmif.boxes.getStats('box_abc123');Licenses
Section titled “Licenses”Manage licenses for protected identities.
// List licensesconst licenses = await lmif.licenses.list({ status: 'active',});
// Request a licenseconst request = await lmif.licenses.request({ boxId: 'box_abc123', tier: 'commercial', useCase: 'AI companion platform', estimatedUsers: 10000, acceptGuidelines: true,});
// Check request statusconst status = await lmif.licenses.getRequestStatus(request.id);
// Get a licenseconst license = await lmif.licenses.get('lic_xyz789');
// Renew a licenseawait lmif.licenses.renew('lic_xyz789', { term: 12,});
// Cancel a licenseawait lmif.licenses.cancel('lic_xyz789', { reason: 'no_longer_needed',});
// Report usageawait lmif.licenses.reportUsage('lic_xyz789', { period: '2024-01', metrics: { subscribers: 5000, messages: 250000, }, revenue: { subscriptions: 25000, messages: 5000, },});Violations
Section titled “Violations”Track and manage violations.
// List violationsconst violations = await lmif.violations.list({ status: 'pending',});
// Get a violationconst violation = await lmif.violations.get('viol_abc123');
// Resolve a violationawait lmif.violations.resolve('viol_abc123', { resolution: 'removed', avatarId: 'avatar_123',});
// Appeal a violationawait lmif.violations.appeal('viol_abc123', { reason: 'parody', explanation: 'This is clearly satirical content',});Grace Periods
Section titled “Grace Periods”Manage compliance windows.
// List active grace periodsconst gracePeriods = await lmif.gracePeriods.list({ status: 'active', expiringWithin: 7, // Days});
// Get a grace periodconst gp = await lmif.gracePeriods.get('gp_abc123');
// Resolve a grace periodawait lmif.gracePeriods.resolve('gp_abc123', { resolution: 'licensed', licenseId: 'lic_xyz789', avatarId: 'avatar_123',});Webhooks
Section titled “Webhooks”Manage webhook endpoints.
// List webhooksconst webhooks = await lmif.webhooks.list();
// Create a webhookconst webhook = await lmif.webhooks.create({ url: 'https://yoursite.com/webhooks/lmif', events: ['box.created', 'grace_period.started'],});
// Verify a webhook signatureconst isValid = lmif.webhooks.verify( rawPayload, // Buffer or string signature, // From X-LMIF-Signature header secret // Your webhook secret);
// Send a test eventawait lmif.webhooks.test({ eventType: 'box.created', endpoint: 'https://yoursite.com/webhooks/lmif',});
// Rotate secretconst newSecret = await lmif.webhooks.rotateSecret('wh_xyz789');
// Delete webhookawait lmif.webhooks.delete('wh_xyz789');Error Handling
Section titled “Error Handling”import { LMIFClient, LMIFError } from '@lookmaimfamous/lmif';
try { const result = await lmif.identity.check({ name, imageUrl });} catch (error) { if (error instanceof LMIFError) { console.error('LMIF Error:', error.code, error.message);
switch (error.code) { case 'RATE_LIMITED': // Wait and retry await sleep(error.retryAfter * 1000); break; case 'UNAUTHORIZED': // Check API key break; case 'VALIDATION_ERROR': // Check request parameters console.error('Validation errors:', error.details); break; } }}TypeScript Types
Section titled “TypeScript Types”The SDK exports all types for use in your application:
import type { // Enums EntityType, PolicyType, EnforcementLevel, VerificationTier, RecommendedAction,
// Request types IdentityCheckRequest, ClaimCreateRequest, BoxCreateRequest, LicenseRequestRequest,
// Response types IdentityCheckResult, Claim, Box, License, Violation, GracePeriod,
// Webhook types WebhookEvent, BoxCreatedEvent, GracePeriodStartedEvent,} from '@lookmaimfamous/lmif';Middleware Examples
Section titled “Middleware Examples”Express Middleware
Section titled “Express Middleware”import { LMIFClient } from '@lookmaimfamous/lmif';
const lmif = new LMIFClient({ apiKey: process.env.LMIF_API_KEY });
// Middleware to check identity before avatar creationexport async function checkIdentityMiddleware(req, res, next) { const { name, imageUrl } = req.body;
try { const result = await lmif.identity.check({ name, imageUrl });
if (result.action === 'BLOCK') { return res.status(403).json({ error: 'Identity is protected', policy: result.policy, }); }
// Attach result to request for downstream use req.identityCheck = result; next(); } catch (error) { next(error); }}
// Usageapp.post('/avatars', checkIdentityMiddleware, createAvatarHandler);Rate Limiting
Section titled “Rate Limiting”The SDK automatically handles rate limits:
const lmif = new LMIFClient({ apiKey: process.env.LMIF_API_KEY, retry: { maxRetries: 3, retryDelay: 1000, // Base delay in ms },});
// The SDK will automatically retry rate-limited requests// with exponential backoff