API Endpoint Access URL
https://api.pixlab.io/nsfw
Get Your API Key & Try NSFW Now ↗Description
Detect and censor not suitable for work (NSFW) content in images and videos using the NSFW API endpoint. Automate media processing with blur, encrypt, or mogrify to filter user uploads based on NSFW scores. Detect not suitable for work (i.e. nudity & adult) content in a given image or video frame. NSFW is of particular interest, if mixed with some media processing API endpoints like blur, encrypt or mogrify to censor images on the fly according to their nsfw score. This can help the developer automate things such as filtering user's uploads. See the example section for a concrete usage.
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input image URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request. |
key |
String | Your PixLab API Key ↗. |
POST Request Body
This section details the requirements for using a POST request instead of a simple GET request.
Allowed Content-Types:
multipart/form-data
application/json
To facilitate direct image uploads, utilize multipart/form-data
. Please consult the REST API code samples for a functional implementation. For JSON submissions, the image must be pre-uploaded. Call store to upload images before invoking this endpoint.
HTTP Response
application/json
This endpoint returns a JSON response. The score field is the key metric - values closer to 1 indicate higher NSFW probability. Response structure:
Fields | Type | Description |
---|---|---|
status |
Integer | HTTP status code (200 indicates success) |
score |
Float | NSFW probability score (0.0 - 1.0 range) |
error |
String | Error description when status ≠ 200 |
Code Samples
import requests
from typing import Dict, Any
def censor_nsfw_image(image_url: str, api_key: str) -> None:
"""Check and censor NSFW content from an image using PixLab API."""
# NSFW detection endpoint
nsfw_params = {
'img': image_url,
'key': api_key
}
try:
# Check for NSFW content
response = requests.get(
'https://api.pixlab.io/nsfw',
params=nsfw_params,
timeout=10
)
response.raise_for_status()
nsfw_data: Dict[str, Any] = response.json()
if nsfw_data['status'] != 200:
print(f"Error: {nsfw_data.get('error', 'Unknown error')}")
return
if nsfw_data['score'] < 0.5:
print("No adult content detected in this picture")
return
# Censor NSFW content
print("Censoring NSFW picture...")
blur_params = {
'img': image_url,
'key': api_key,
'rad': 50,
'sig': 30
}
blur_response = requests.get(
'https://api.pixlab.io/blur',
params=blur_params,
timeout=10
)
blur_response.raise_for_status()
blur_data: Dict[str, Any] = blur_response.json()
if blur_data['status'] != 200:
print(f"Error: {blur_data.get('error', 'Unknown error')}")
else:
print(f"Censored image: {blur_data['link']}")
except requests.exceptions.RequestException as e:
print(f"API request failed: {e}")
if __name__ == "__main__":
# Configuration
TARGET_IMAGE = 'https://i.redd.it/oetdn9wc13by.jpg'
API_KEY = 'PIXLAB_API_KEY' # Replace with your actual API key
censor_nsfw_image(TARGET_IMAGE, API_KEY)
const img = 'https://i.redd.it/oetdn9wc13by.jpg';
const key = 'PIXLAB_API_KEY';
fetch(`https://api.pixlab.io/nsfw?img=${encodeURIComponent(img)}&key=${encodeURIComponent(key)}`)
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else if (reply.score < 0.5) {
console.log("No adult content were detected on this picture");
} else {
console.log("Censoring NSFW picture...");
fetch(`https://api.pixlab.io/blur?img=${encodeURIComponent(img)}&key=${encodeURIComponent(key)}&rad=50&sig=30`)
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Censored image: " + reply.link);
}
})
.catch(error => console.error('Error:', error));
}
})
.catch(error => console.error('Error:', error));
<?php
$img = 'https://i.redd.it/oetdn9wc13by.jpg';
$key = 'PIXLAB_API_KEY';
function pixlabApiRequest($endpoint, $params) {
$url = 'https://api.pixlab.io/' . $endpoint . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$nsfwResponse = pixlabApiRequest('nsfw', ['img' => $img, 'key' => $key]);
if ($nsfwResponse['status'] != 200) {
echo $nsfwResponse['error'];
} elseif ($nsfwResponse['score'] < 0.5) {
echo "No adult content were detected on this picture";
} else {
echo "Censoring NSFW picture...";
$blurResponse = pixlabApiRequest('blur', [
'img' => $img,
'key' => $key,
'rad' => 50,
'sig' => 30
]);
if ($blurResponse['status'] != 200) {
echo $blurResponse['error'];
} else {
echo "Censored image: " . $blurResponse['link'];
}
}
require 'net/http'
require 'uri'
require 'json'
# Target Image: Change to any link you want (Possibly adult) or switch to POST if you want to upload your image directly, refer to the REST API code samples for more info.
img = 'https://i.redd.it/oetdn9wc13by.jpg'
# Your PixLab key
key = 'PIXLAB_API_KEY'
# Censor an image according to its NSFW score
uri = URI.parse('https://api.pixlab.io/nsfw')
params = { img: img, key: key }
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
elsif reply['score'] < 0.5
puts "No adult content were detected on this picture"
else
# Highly NSFW picture
puts "Censoring NSFW picture..."
# Call blur with the highest possible radius and sigma
uri = URI.parse('https://api.pixlab.io/blur')
params = { img: img, key: key, rad: 50, sig: 30 }
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
puts "Censored image: #{reply['link']}"
end
end
Similar API Endpoints
sfw, ocr, bg-remove, facedetect, mogrify, blur, faceverify ↗, DOCSCAN, screencapture