SFW API vs NSFW.js
Last updated 2026-11-17
NSFW.js is an open-source TensorFlow.js model that classifies an image into five classes, in the browser or in Node. The SFW API is a hosted endpoint that returns a level from 0 to 3, three scores, art and adult-object flags and a policy verdict. Facts below are from the NSFW.js README and npm page in November 2026 (version 4.4.0).
| SFW API | NSFW.js | |
|---|---|---|
| Runs | hosted API (Germany) | in the browser (WebGL, WebGPU, WASM) or Node with @tensorflow/tfjs-node |
| Price | 500 free credits/month, then $10 for 10,000 ($1.00/1k), down to $0.50/1k | free (MIT); you host the model files |
| Output | level 0–3, three scores, art and sex_object flags, policy verdict | probabilities for Drawing, Hentai, Neutral, Porn and Sexy |
| Models | one versioned model | MobileNetV2 (about 2.8 MB), MobileNetV2Mid (about 4.4 MB), InceptionV3 (about 23 MB) |
| Stated accuracy | per level with confidence intervals on Accuracy | "~90% with small and ~93% with midsized model", without a published test set |
| GIF/video | frame by frame on the same endpoint (video on paid accounts) | single images or video frames you pass in; classifyGif was removed in 2024 |
| Adult objects | sex_object flag | no equivalent class |
| Enforcement | on your server, the client cannot skip it | in the browser it runs on the user's device, so a check there can be bypassed; run it in Node to enforce |
NSFW.js is enough for a client-side hint, such as blurring a preview before upload, or for a hobby project where a five-class guess is fine and no image may leave the device. Choose the SFW API for the check you enforce: on the server, with a grade between swimwear and implied nudity, GIF and video support, and no model files to host and update.
Mapping NSFW.js classes to levels
| NSFW.js | SFW API |
|---|---|
Porn | level 3 Explicit |
Hentai | art flag with level 3 |
Sexy | level 1 Revealing or level 2 Implied Nudity: one class covers both |
Drawing | art flag with level 0 or 1 |
Neutral | level 0 Everyday |
Sexy is where most moderation decisions are made, and it puts lingerie, swimwear and covered nudity in one bucket. The SFW API splits that bucket into levels 1 and 2 so you can choose which one blocks.
The same check in both
// NSFW.js in Node
import * as tf from '@tensorflow/tfjs-node';
import * as nsfwjs from 'nsfwjs';
const model = await nsfwjs.load();
const image = tf.node.decodeImage(bytes, 3) as tf.Tensor3D;
const top = (await model.classify(image))[0];
image.dispose();
const blocked = top.className === 'Porn' || top.className === 'Hentai';
// SFW API (npm install @sfwapi/sdk)
const r = await api.analyzeFile(bytes, { policy: { block_level: 2 } });
const blocked = r.policy?.blocked;Related
- Moderate image uploads in Next.js before they are stored
- TypeScript SDK
- vs NudeNet
- Pricing
- Accuracy and methodology
- Quickstart
Next steps
Read the quickstart for a first request, see pricing for the free tier and prepaid packs, or get a free API key and start with your own images.