TypeScript & Python SDK

FR-APIaaS provides official SDKs for TypeScript, Python, and Flutter. Each SDK offers typed request models, consistent error handling, and first-class support for multipart image uploads.

Installation

npm install fr-apiaas-sdk
# or
pnpm add fr-apiaas-sdk

Initialize the Client

import { FRClient } from 'fr-apiaas-sdk'

const client = new FRClient({
  apiKey: process.env.FR_API_KEY!,
  baseUrl: 'https://api.example.com/api/v1', // optional
  timeout: 30_000,                           // optional, ms
})

Enroll a Face

import { readFileSync } from 'fs'

const face = await client.faces.register(collectionId, {
  image:       readFileSync('./alice.jpg'), // Buffer, Blob, or file path
  external_id: 'employee-001',
  metadata:    { department: 'engineering' },
})
console.log(face.id)           // UUID of the enrolled face
console.log(face.external_id)  // 'employee-001'

1:1 Verification

const result = await client.faces.verify(collectionId, {
  image:     readFileSync('./query.jpg'),
  face_id:   'known-face-uuid',
  threshold: 0.70,
})
console.log(result.match)          // true | false
console.log(result.confidence)     // 0.0 – 1.0
console.log(result.thresholdUsed)  // effective threshold applied

1:N Identification

const result = await client.faces.identify(collectionId, {
  image:     readFileSync('./query.jpg'),
  top_k:     3,
  threshold: 0.60,
})
result.matches.forEach(m => {
  console.log(m.externalId, m.confidence) // e.g. 'employee-001', 0.92
})

Liveness Detection

const liveness = await client.faces.liveness(collectionId, {
  image: readFileSync('./selfie.jpg'),
})
console.log(liveness.isLive)        // true | false
console.log(liveness.livenessScore) // 0.0 – 1.0

Batch Enrollment

const result = await client.faces.batchRegister(collectionId, [
  { external_id: 'emp-001', image: readFileSync('./alice.jpg') },
  { external_id: 'emp-002', image: readFileSync('./bob.jpg'),
    metadata: { department: 'sales' } },
])
console.log(`${result.succeeded}/${result.succeeded + result.failed} enrolled`)

Error Handling

import { FRApiError, FRNetworkError } from 'fr-apiaas-sdk'

try {
  await client.faces.identify(collectionId, { image, top_k: 3 })
} catch (err) {
  if (err instanceof FRApiError) {
    console.error(err.code, err.message) // e.g. NO_FACE_DETECTED
  } else if (err instanceof FRNetworkError) {
    console.error('Network failure:', err.message)
  }
}

Configuration reference

OptionDefaultDescription
apiKey / api_keyRequired. Your API key from the dashboard.
baseUrl / base_urlproduction URLOverride to point at a self-hosted instance.
timeout30 sRequest timeout. Increase for large batch uploads.