A fully‑typed TypeScript SDK for the SightEngine content‑moderation API, with streaming support, URL/file inputs, threshold presets, and helper utilities.🧬
- ✅ Fully‑typed (TypeScript)
- 📡 Stream image moderation
- 🌐 URL image inputs
- ⚙️ Threshold presets + custom thresholds
- 🛠️ Helper utilities:
isNSFW(),listFlaggedCategories()
npm install sightengine-js
# or
yarn add sightengine-jsimport { SightEngineClient, isNSFW, listFlaggedCategories } from "sightengine-js";
const sightengine = new SightEngineClient({
apiSecret: "<your api secret>",
apiUser: "<your api user>",
});
const imageModerationResult = await sightengine.moderateImage(
"<path to your image>",
[
"nudity-2.1",
"gore-2.0",
"offensive-2.0",
],
);
// URL-based
const urlImageModerationResult = await sightengine.moderateImageByUrl(
"<image URL>",
[
"nudity-2.1",
"gore-2.0",
"offensive-2.0",
],
);
console.log(listFlaggedCategories(imageModerationResult));
console.log(isNSFW(imageModerationResult));| Property | Type | Description |
|---|---|---|
apiUser |
string |
Your SightEngine API user. |
apiSecret |
string |
Your SightEngine API secret. |
path– Local file system path to the image.models– Array of model identifiers (default:["nudity-2.1"]).
Returns a promise that resolves to ImageModerationResponse.
url– Direct URL to the image.models– Same as above.
Returns a promise that resolves to ImageModerationResponse.
ImageModerationResponse– Raw response from SightEngine (seesrc/types.ts).NormalizedImageModerationResponse– Internal normalized shape used by helpers.
import { DEFAULT_THRESHOLDS, PRESET_THRESHOLDS } from "sightengine-js";
// Example: use the strict preset
const thresholds = PRESET_THRESHOLDS.strict;| Model | Default |
|---|---|
nudity |
0.85 |
offensive |
0.5 |
gore |
0.5 |
violence |
0.5 |
self-harm |
0.5 |
isNSFW(response, threshold?)– Returnstrueif any of the important categories (nudity,gore,violence,self-harm,sexual) exceed the given threshold.listFlaggedCategories(response, thresholds?)– Returns an array of categories (and sub‑scores) that exceed the supplied thresholds.
Both functions accept the raw ImageModerationResponse from the client.
- Fork the repo
- Create a feature branch (
git checkout -b feat/...) - Commit with Commitizen (
npm run commit) - Push & open a PR against
develop - Tests must pass, coverage ≥ 90%
MIT © Ali Nazari
Built with ❤️ by Ali Nazari, for developers. Happy encoding! 🎬