API Endpoint Access URL
https://api.pixlab.io/nsfw
Get your API key and test the NSFW API ↗Description
The NSFW Detection API endpoint helps developers and product teams score images or video frames for adult content before that media reaches end users. It is a practical fit for upload moderation, marketplace compliance, community safety rules, and review queues where you need a fast signal to accept, flag, or block content. The returned score can also drive automated workflows with endpoints such as blur, encrypt, and mogrify when you need to censor or transform flagged assets on the fly.
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 explains when to use a POST request instead of a simple GET request.
Allowed Content-Types:
multipart/form-dataapplication/json
Use multipart/form-data when you want to upload an image directly from your app. Refer to the REST API code samples for a working implementation. If you prefer application/json, upload the asset first with store and then pass the stored image reference to this endpoint.
HTTP Response
application/jsonThis endpoint returns a JSON response. The score field is the main moderation signal, and values closer to 1.0 indicate a higher probability of adult content. Response structure:
| Fields | Type | Description |
|---|---|---|
status |
Integer | HTTP status code. A value of 200 indicates success. |
score |
Float | NSFW probability score in the 0.0 to 1.0 range. |
error |
String | Error details returned 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 image")
return
# Censor NSFW content
print("Censoring NSFW image...")
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 was detected in this image");
} else {
console.log("Censoring NSFW image...");
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 was detected in this image";
} else {
echo "Censoring NSFW image...";
$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 was detected in this image"
else
# Highly NSFW image
puts "Censoring NSFW image..."
# 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
text-watermark-remove, image-text-translate, ocr, bg-remove, facedetect, mogrify, blur, faceverify ↗, DOCSCAN, screencapture, image-embed, query, describe