Deploy NSFW API
Self-hosted image moderation API: nudity, weapons, gore and drugs.
nsfw-api
Just deployed
Deploy and Host NSFW API on Railway
NSFW API is a self-hosted image moderation API. Send an image to POST /classify and get back whether it is safe: nudity scores from nsfwjs's MobileNetV2, plus weapons, gore and drugs detection with Apple's MobileCLIP-S0. Both models run on CPU with ONNX Runtime: no GPU, no third-party service.
About Hosting NSFW API
The service builds from the repository's Dockerfile into a small distroless image (~122 MB compressed) with both models inside, so nothing is downloaded at boot. The models load in under a second and the healthcheck only turns green once they are ready. On 1 vCPU it answers in ~75 ms per image with ~125 MB of RAM at rest. An API key is generated for you, and a playground at /playground lets you try it from a browser. Turn on App Sleeping to pay almost nothing while it is idle.
Common Use Cases
- Moderate user uploads (avatars, posts, listings) before they are published
- Flag nudity, weapons, gore or drugs in an image pipeline or an image CDN such as Openinary
- Keep images private: they only live in memory for the length of the request, nothing is stored
Dependencies for NSFW API Hosting
- None at runtime: a single service, no database and no volume
- The models are fetched from Hugging Face at pinned revisions during the build
Implementation Details
curl -H "Authorization: Bearer $API_KEY" -F image=@photo.jpg https:///classify
The response contains safe, flags (for example ["nsfw"] or ["weapon"]), the nudity predictions and a score per category. Send ~512 px thumbnails rather than originals: the models only look at 224–256 px, and a 4000×3000 WebP takes ~414 ms against ~69 ms for its thumbnail.
The MobileCLIP-S0 weights come from a copy published under Apple's 2024 sample code license; Apple has since moved MobileCLIP to a research-only license. Read the license note in the README before commercial use.
Why Deploy NSFW API on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying NSFW API on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
nsfw-api
openinary/nsfw-api