This API processes images and detects sexual content in them, marking the images as Safe For Work (SFW) or Not Safe For Work (NSFW).
It also gives the confidence percentage for each of the two classes.
NSFW can detect inappropriate content of various kinds.
NSFW tag is responsible for such content as porn, hentai or more mild but explicit content that can be unsuitable for work and other public places.
This API is created by API4AI. We build our APIs on a completely cloud technology stack which provides full operability, scalability and stable uptime. Our sole goal is to create out-of-the-box self-contained AI solutions that can easily be integrated into any application with just a few simple steps.
METHOD | URL | DESCRIPTION |
---|---|---|
GET | https://nsfw3.p.rapidapi.com/v1/version |
Get a service version. |
POST | https://nsfw3.p.rapidapi.com/v1/results |
Perform image analysis and get results. |
Returns an actual version of the service in format vX.Y.Z
where X is the version of API.
PROPERTY | DESCRIPTION |
---|---|
Endpoint | https://nsfw3.p.rapidapi.com/v1/version |
Method | GET |
Query parameters | โ |
POST parameters | โ |
Example
curl -X 'GET' 'https://nsfw3.p.rapidapi.com/v1/version' \
-H 'X-RapidAPI-Key: ...'
v1.3.0
Performs actual image analysis and responds with results.
PROPERTY | DESCRIPTION |
---|---|
Endpoint | https://nsfw3.p.rapidapi.com/v1/results |
Method | POST |
Query parameters | strictness |
POST parameters | image , url |
Passing image
Image can be passed by posting regular โmultipart form dataโ in two alternative ways:
image
fieldurl
fieldImage must be a regular JPEG or PNG image (with or without transparency) or PDF file.
Usually such images have extensions: .jpg
, .jpeg
, .png
, .pdf
. In case of PDF
each page will be converted to PNG image and processed separately (note: you will be charged for each page!).
The service checks input file by MIME type and accepts the following types:
image/jpeg
image/png
application/pdf
The size of the image file must be less than 16Mb
.
The maximum allowed resolution is 4096x4096
.
Response schema
For responses with 200
HTTP code the type of response is JSON object with the following schema:
{
"results": [
{
"status": {
"code": ...,
"message": ...
},
"name": ...,
"md5": ...,
"page": ...,
"width": ...,
"height": ...,
"entities": [
{
"kind": "classes",
"name": "nsfw-classes",
"classes": {
"nsfw": ...,
"sfw": ...
}
}
]
}
]
}
Primary fields:
Name | Type | Description |
---|---|---|
results[].status.code |
string |
Status code of image processing: ok or failure . |
results[].status.message |
string |
Human readable explanation for the status of image processing. |
results[].name |
string |
Original image name passed in request (e.g. my_image.jpg ). |
results[].md5 |
string |
MD5 sum of original image passed in request. |
results[].page |
int |
Optional page number (presented for multipage inputs only). |
results[].width |
int |
Optional image width (presented for valid inputs only). |
results[].height |
int |
Optional image height (presented for valid inputs only). |
results[].entities[].classes.nsfw |
float |
Confidence for nsfw class (in range from 0.0 to 1.0 ). |
results[].entities[].classes.sfw |
float |
Confidence for sfw class (in range from 0.0 to 1.0 ). |
Other fields that are not described above always have the same values.
Strictness
Term NSFW is not well defined. The same appearance may be appropriate or not depending on context. E.g. photo of woman in bikini may considered both as SFW and NSFW. In order to satisfy needs in various scenarios we introduces strictness
query parameter in order to control how strict algorithm should be. By default algorithms is as strict as possible (equals to strictness=1.0
) and even photo of woman in bikin is considered as NSFW. But you may reduces strictness if it suites better your needs (up to 0.0
value).
curl -X 'POST' 'https://nsfw3.p.rapidapi.com/v1/results' \
-H 'X-RapidAPI-Key: ...' \
-F 'image=@dog.jpg'
{
"results": [
{
"status": {
"code": "ok",
"message": "Success"
},
"name": "dog.jpg",
"md5": "4b5a61dda723621b0dfcf95ab3c4a41e",
"width": 1500,
"height": 1000,
"entities": [
{
"kind": "classes",
"name": "nsfw-classes",
"classes": {
"nsfw": 0.00027880111237088556,
"sfw": 0.9997211146293115
}
}
]
}
]
}
When a client sends an image that can not be processed for some reason(s), the service responds with 200
code and returns a JSON object in the same format as the format for successful analysis. In this case, the results[].status.code
will have failure
value and results[].status.message
will contain relevant explanation.
Example of possible reasons for the issue:
Example response for image with unsupported MIME type:
{
"results": [
{
"status": {
"code": "failure",
"message": "Can not load image."
},
"name": "file.txt",
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"entities": []
}
]
}
Request size is limited by approximately 32Mb
.
When a client sends a request that exceeds this limit, the service responds with 413
code.
The typical reason for exceeding this limit is an overly large image.
Taking into account additional HTTP overhead, we strongly recommend not passing image files of size more than 16Mb
.
Example response for overly big image:
Error: Request Entity Too Large
Your client issued a request that was too large.
When a client sends a request without an image, the service responds with 422
code and returns a JSON object.
Example response for request with missing image:
{"detail":"Missing image or url field."}
Post a file content as a โmultipart form dataโ field named image
.
curl -X 'POST' 'https://nsfw3.p.rapidapi.com/v1/results' \
-H 'X-RapidAPI-Key: ...' \
-F 'image=@dog.jpg'
Post a URL to file as a โmultipart form dataโ field named url
.
curl -X 'POST' 'https://nsfw3.p.rapidapi.com/v1/results' \
-H 'X-RapidAPI-Key: ...' \
-F 'url=https://storage.googleapis.com/api4ai-static/rapidapi/nsfw/dog.jpg'
Explicitly pass strictness
query with float value in range from 0.0
to 1.0
(default and strict).
curl -X 'POST' 'https://nsfw3.p.rapidapi.com/v1/results?strictness=0.0' \
-H 'X-RapidAPI-Key: ...' \
-F 'url=https://storage.googleapis.com/api4ai-static/rapidapi/nsfw/bikini.jpg'
Code examples in Python, C#, JavaScript, Swift and other popular programming languages: https://gitlab.com/api4ai/examples/nsfw
Feel free to contact API4AI team if you have any questions.