Before you start
You need a Nosmai license key for your app. It looks like NOSMAI-XXXX and is tied to your app's package name or bundle identifier and to the platform. On web, the key is tied to your site's domain instead. Get one from the Nosmai dashboard.
The first launch verifies the key online, so make sure the device has connectivity the first time you run your app.
1. Install
Pick your platform.
Flutter
dependencies: nosmai_moderation_sdk: ^1.0.0
iOS
pod 'NosmaiModerationSDK', '~> 1.0'
Android (download nosmai-detection.aar from the releases page, put it in app/libs/, then reference it):
dependencies {
implementation(files("libs/nosmai-detection.aar"))
}
React Native
npm install @nosmai/moderation-react-native
The native SDK comes with it: run pod install on iOS; on Android add the nosmai-detection.aar as described above.
Web
npm install @nosmai/moderation-web
Host the model files (provided with your license) as static files your site serves, e.g. under /models/.
2. Initialize
Initialize once at startup with your license key. Initialization does a network check and loads the models, so run it off the main thread.
Flutter
final res = await NosmaiModeration.initialize('NOSMAI-XXXX');
if (!res.success) debugPrint('init failed: ${res.error}');
iOS
DispatchQueue.global(qos: .userInitiated).async {
let ok = NosmaiSDK.initialize(licenseKey: "NOSMAI-XXXX")
}
Android
Executors.newSingleThreadExecutor().execute {
val ok = NosmaiSDK.init(context, "NOSMAI-XXXX")
}
React Native
const init = await NosmaiModeration.initialize('NOSMAI-XXXX', ['objectDetection', 'nsfw']);
if (!init.success) console.warn('init failed:', init.error);
Web
const res = await NosmaiModeration.initialize('NOSMAI-XXXX');
await NosmaiModeration.initializeNsfw({ modelUrl: '/models/nsm_nsfw.onnx' });
await NosmaiModeration.initializeDetector({ modelUrl: '/models/nsm_detector.onnx' });
3. Run your first check
Moderate an image and read the verdict.
Flutter
final r = await NosmaiModeration.analyzeImage(file.path); print(r.isUnsafe ? 'UNSAFE' : 'SAFE');
iOS
if let r = NosmaiSDK.analyzeImage(uiImage) {
print(r.isUnsafe ? "UNSAFE" : "SAFE")
}
Android
val r = NosmaiSDK.analyzeImage(bitmap)
Log.d("Mod", if (r.isUnsafe) "UNSAFE" else "SAFE")
React Native
const r = await NosmaiModeration.analyzeImage(filePath); console.log(r.isUnsafe ? 'UNSAFE' : 'SAFE');
Web
const r = await NosmaiModeration.analyzeImage(imageElement); console.log(r.isUnsafe ? 'UNSAFE' : 'SAFE');
Next steps
- How moderation works: surfaces, detection types, results and thresholds.
- Platform guides: iOS, Android, Flutter, React Native, Web.
- Authentication: how license keys and offline validation work.