NSFW

FREEMIUM
Verified
โœ“
By API 4 AI | Updated 8 days ago | Visual Recognition
Popularity

9.6 / 10

Latency

1,692ms

Service Level

100%

Health Check

100%

Followers: 17
Resources:
Product Website
API Creator:
Rapid account: API 4 AI
API 4 AI
api4ai
Log In to Rate API
Rating: 3.7 - Votes: 6

README

โญ๏ธ NSFW

Examples API4AI Telegram

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.

๐Ÿ‘‰ Features

  • โœ… Recognizes NSFW images such as porn, hentai or other explicit content.
  • โœ… Allows to adjust strictness depending on purposes.
  • โœ… Supports two alternative ways to pass images: as a binary file or via url to a public resource.
  • โœ… Supports multipage PDF files also.

๐Ÿ‘‰ Demos


๐Ÿ‘‰ Contacts




๐Ÿ›  Endpoints

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.

๐Ÿ‘‰ Get version

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: ...'
Click here to view the response
v1.3.0



๐Ÿ‘‰ Analyze image and return results

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:

  • as binary file in image field
  • as URL to some public resource in url field

Image 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).




๐Ÿ“Œ Examples


๐Ÿ‘‰ Check image

curl -X 'POST' 'https://nsfw3.p.rapidapi.com/v1/results' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@dog.jpg'
Click here to view the response
{
  "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
          }
        }
      ]
    }
  ]
}




โ—๏ธ Possible errors


๐Ÿ‘‰ The service can not process an image

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:

  • Unsupported MIME type
  • Image resolution exceeds limits
  • Corrupted image

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 too big

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.

๐Ÿ‘‰ Missing image

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."}




โ“ F.A.Q.


๐Ÿ‘‰ How to pass an image as binary file?

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'

๐Ÿ‘‰ How to pass an image as URL?

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'

๐Ÿ‘‰ Algorithm is too strict! What can we do with that?

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'

๐Ÿ‘‰ Where to find code examples?

Code examples in Python, C#, JavaScript, Swift and other popular programming languages: https://gitlab.com/api4ai/examples/nsfw


๐Ÿ‘‰ Where to try live demo?


๐Ÿ‘‰ I need support

Feel free to contact API4AI team if you have any questions.