TYPESCRIPT SDK

Typed TypeScript SDK

Every Latentface endpoint callable from Node 18+, Deno, or a modern browser. Matching call surface with the Python SDK. Exhaustive types — no any.

Install

npm install @latentface/sdk
# or: pnpm add @latentface/sdk

Ships ESM + CJS builds. TypeScript types bundled — no separate @types/* package.

Initialize & call

import { Latentface } from '@latentface/sdk';

const client = new Latentface();  // reads LATENTFACE_API_KEY

const result = await client.swap({
  source: './source.jpg',
  target: './target.jpg',
});
console.log(result.outputUrl);

Reads LATENTFACE_API_KEY from the environment, or pass { apiKey } to the constructor.

Fully typed responses

const vec = await client.embed({ image: './face.jpg' });
//    ^? EmbedResult
//       embedding: number[]        (length 512)
//       model: string
//       latencyMs: number

const score = await client.match({ a, b });
//    ^? MatchResult
//       score: number              (0 – 1)
//       decision: 'match' | 'nomatch'

Browser usage (scoped keys)

// server-side (Next.js route handler)
import { Latentface } from '@latentface/sdk';

const root = new Latentface();
const scoped = await root.createScopedKey({
  scopes: ['swap:write'],
  ttlSeconds: 300,
});
return Response.json({ key: scoped.key });

Never ship your root key to the browser. Issue short-lived scoped keys on the server via a route handler and hand them to the client.

Error handling

import { RateLimitError, QuotaError } from '@latentface/sdk';

try {
  await client.swap({ source, target });
} catch (err) {
  if (err instanceof RateLimitError) {
    // err.retryAfter: number (seconds)
  } else if (err instanceof QuotaError) {
    // upgrade at /pricing
  } else {
    throw err;
  }
}

Every typed error includes enough context to build a retry or upgrade flow. See rate limits & errors.

Source on GitHub

Open source, Apache 2.0. Issues and PRs welcome.