API Endpoint Access URL
https://api.pixlab.io/sfw
Get Your API Key & Try SFW Now ↗Description
Detect whether a given image is suitable for work (does not contain adult content). This the opposite of what the nsfw endpoint does.
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input image URL. If uploading directly from your app, submit a multipart/form-data POST request. Only JPEG & PNG formats supported. Convert other formats using the convert endpoint. |
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
(direct file upload)application/json
(pre-uploaded images)
For JSON requests, images must be publicly accessible. Upload images first via the store endpoint if needed.
HTTP Response
Fields | Type | Description |
---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
score |
Float | SFW score value between 0 .. 1. Values closer to 1 indicate safer content with no adult material. |
error |
String | Error message if status != 200. |
application/json
The API returns a JSON response. The score field is the primary indicator - values approaching 1.0 signify safer content. Response structure:
Code Samples
import requests
def check_image_safety(image_url: str, api_key: str) -> None:
"""Check if an image contains adult content using PixLab API."""
try:
response = requests.get(
'https://api.pixlab.io/sfw',
params={'img': image_url, 'key': api_key},
timeout=10
)
response.raise_for_status()
data = response.json()
if data['status'] != 200:
print(f"Error: {data.get('error', 'Unknown error')}")
elif data.get('score', 0) > 0.5:
print("This image is pretty safe & does not appear to have any adult content!")
else:
print("This picture is highly NSFW & may contain adult content, perhaps censor it?")
# Consider calling api.pixlab.io/blur or api.pixlab.io/encrypt
# to create a censored version of the picture
except requests.exceptions.RequestException as e:
print(f"API request failed: {e}")
except (KeyError, ValueError) as e:
print(f"Error processing API response: {e}")
if __name__ == "__main__":
check_image_safety(
image_url='https://i.redd.it/oetdn9wc13by.jpg',
api_key='PIXLAB_API_KEY'
)
fetch('https://api.pixlab.io/sfw?img=https://i.redd.it/oetdn9wc13by.jpg&key=PIXLAB_API_KEY')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else if (reply.score > 0.5) {
console.log("This image is pretty safe & does not appear to have any adult content!");
} else {
console.log("This picture is highly NSFW & may contain adult content, perhaps censure it?");
// call api.pixlab.io/blur, api.pixlab.io/encrypt to make a censured version of the picture
}
})
.catch(error => console.error('Error:', error));
<?php
function checkImageSafety($imageUrl, $apiKey) {
$endpoint = 'https://api.pixlab.io/sfw';
$params = [
'img' => $imageUrl,
'key' => $apiKey
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
throw new Exception('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$reply = json_decode($response, true);
if ($httpCode != 200 || $reply['status'] != 200) {
throw new Exception($reply['error'] ?? 'API request failed');
}
if ($reply['score'] > 0.5) {
echo "This image is pretty safe & does not appear to have any adult content!";
} else {
echo "This picture is highly NSFW & may contain adult content, perhaps censure it?";
// Call api.pixlab.io/blur or api.pixlab.io/encrypt to make a censured version
}
}
// Example usage:
try {
checkImageSafety('https://i.redd.it/oetdn9wc13by.jpg', 'PIXLAB_API_KEY');
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://api.pixlab.io/sfw')
params = { 'img' => 'https://i.redd.it/oetdn9wc13by.jpg', 'key' => 'PIXLAB_API_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 "This image is pretty safe & does not appear to have any adult content!"
else
puts "This picture is highly NSFW & may contain adult content, perhaps censure it?"
# call api.pixlab.io/blur, api.pixlab.io/encrypt to make a censured version of the picture
end