Sdks
TypeScript SDK
@sfwapi/sdk for Node 18+, Bun, Deno and edge runtimes.
npm install @sfwapi/sdkimport { SfwApi, SfwApiError, evaluatePolicy } from '@sfwapi/sdk';
const api = new SfwApi({ apiKey: process.env.SFWAPI_KEY! });
try {
const r = await api.analyzeUrl('https://example.com/photo.jpg', { policy: { block_level: 2, block_sex_objects: true, art: 'same_as_photos' } });
console.log(r.nudity.level, r.policy?.blocked);
} catch (e) {
if (e instanceof SfwApiError) console.error(e.status, e.code, e.message, e.requestId);
}
// uploads
const bytes = await fs.promises.readFile('clip.gif');
const g = await api.analyzeFile(bytes, { maxFrames: 5, includeFrames: true });Methods: analyzeUrl, analyzeFile, analyzeBase64, me, usage. Options: maxFrames, includeFrames, policy, signal. 429/503/504 are retried twice honouring Retry-After (not uploads); set maxRetries: 0 to disable. The exported evaluatePolicy(frames, policy) is the same evaluator the API uses, for client-side what-if logic.