Products

SIGN UPLOG IN

Image Moderation / Workflows

Image Moderation Workflows

Introduction

Image Moderation Workflows make it easy to create your own custom rules and actions, directly from your online dashboard.

You decide how each image is analyzed, and what rules should lead to an image being either accepted or rejected.

Get API access credentials

The Sightengine API uses a key pair that consists of an API user id and an API secret for authentication. To get your own API credentials, create an account and go the the API key page to retrieve them.

Create a Workflow

To create a new workflow, navigate to the Workflow page on your dashboard. You will be able to select the rules that should be applied, and what actions should be taken based on those rules: ACCEPT or REJECT.

For more information on the different detection models you can use, head to our Model reference.

Define your custom moderation rules directly from your dashboard

You might want to create multiple workflows if you handle different types of images with different rules. For instance, let's say you have a dating site and your users can upload both profile pictures and album photos. You could create a workflow for Profile pictures, where you reject photos containing children and force users to submit photos with only one face visible, and another workflow for album photos with less restrictive rules.

Once your workflow has been created, you will get a workflow id that you can use to submit images for moderation.

Submitting images

Once you have created and saved a workflow, you can retrieve the workflow id and use it to query the API.

You can submit an image either by sending the raw bytes or by sending a public URL pointing to the image.

Moderate image by submitting the raw bytes


curl -X POST 'https://api.sightengine.com/1.0/check-workflow.json' \
  -F 'media=@/local/path/to/image' \
  -F 'workflow={workflow_id}' \
  -F 'api_user={api_user}' \
  -F 'api_secret={api_secret}'


# this example uses requests
import requests
import json

params = {
  'workflow': '{workflow_id}',
  'api_user': '{api_user}',
  'api_secret': '{api_secret}'
}
files = {'media': open('/local/path/to/image', 'rb')}
r = requests.post('https://api.sightengine.com/1.0/check-workflow.json', files=files, data=params)

output = json.loads(r.text)

if output['status'] == 'failure':
  # handle failure
  print(output['error'])

if output['summary']['action'] == 'reject':
  # handle image rejection
  # the rejection probability is provided in output['summary']['reject_prob']
  # and user readable reasons for the rejection are in the array output['summary']['reject_reason']
  pass


$params = array(
  'media' => new CurlFile('/local/path/to/image'),
  'workflow' => '{workflow_id}',
  'api_user' => '{api_user}',
  'api_secret' => '{api_secret}',
);

// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/check-workflow.json');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);

$output = json_decode($response, true);

if($output['summary']['action']=='reject') {
  // handle image rejection
  // the rejection probability is provided in $output['summary']['reject_prob']
  // and user readable reasons for the rejection are in the array $output['summary']['reject_reason']
}


// this example uses axios and form-data
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

data = new FormData();
data.append('media', fs.createReadStream('/local/path/to/image'));
data.append('workflow', '{workflow_id}');
data.append('api_user', '{api_user}');
data.append('api_secret', '{api_secret}');

axios({
  method: 'post',
  url:'https://api.sightengine.com/1.0/check-workflow.json',
  data: data,
  headers: data.getHeaders()
})
.then(function (response) {
  // on success: handle response
  console.log(response.data);
})
.catch(function (error) {
  // handle error
  if (error.response) console.log(error.response.data);
  else console.log(error.message);
});

The response JSON will contain a summary object with the moderation decision taken, along with reasons for rejection if the image has to be rejected


{
    "status": "success",
    "request": {
        "id": "req_81pP7cRqEvbdZ457WNQ2O",
        "timestamp": 1597952947.216626,
        "operations": 1
    },
    "summary": {
        "action": "reject",
        "reject_prob": 0.82,
        "reject_reason": [
            {
                "text": "Alcohol"
            }
        ]
    },
    "weapon": 0.0055,
    "alcohol": 0.819,
    "drugs": 0.001,
    "workflow": {
        "id": "wfl_81jOFDxdI8un4sm38y4Kw"
    }
}

Moderate image URL


curl -X GET -G 'https://api.sightengine.com/1.0/check-workflow.json' \
    -d 'workflow={workflow_id}' \
    -d 'api_user={api_user}&api_secret={api_secret}' \
    --data-urlencode 'url=https://sightengine.com/assets/img/examples/example7.jpg'


# this example uses requests
import requests
import json

params = {
  'url': 'https://sightengine.com/assets/img/examples/example7.jpg',
  'workflow': '{workflow_id}',
  'api_user': '{api_user}',
  'api_secret': '{api_secret}'
}
r = requests.get('https://api.sightengine.com/1.0/check-workflow.json', params=params)

output = json.loads(r.text)


if output['status'] == 'failure':
  # handle failure
  print(output['error'])

if output['summary']['action'] == 'reject':
  # handle image rejection
  # the rejection probability is provided in output['summary']['reject_prob']
  # and user readable reasons for the rejection are in the array output['summary']['reject_reason']
  pass


$params = array(
  'url' =>  'https://sightengine.com/assets/img/examples/example7.jpg',
  'workflow' => '{workflow_id}',
  'api_user' => '{api_user}',
  'api_secret' => '{api_secret}',
);

// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/check-workflow.json?'.http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$output = json_decode($response, true);

if($output['summary']['action']=='reject') {
  // handle image rejection
  // the rejection probability is provided in $output['summary']['reject_prob']
  // and user readable reasons for the rejection are in the array $output['summary']['reject_reason']
}


// this example uses axios
const axios = require('axios');

axios.get('https://api.sightengine.com/1.0/check-workflow.json', {
  params: {
    'url': 'https://sightengine.com/assets/img/examples/example7.jpg',
    'workflow': '{workflow_id}',
    'api_user': '{api_user}',
    'api_secret': '{api_secret}',
  }
})
.then(function (response) {
  // on success: handle response
  console.log(response.data);
})
.catch(function (error) {
  // handle error
  if (error.response) console.log(error.response.data);
  else console.log(error.message);
});

The response JSON will contain a summary object with the moderation decision taken, along with reasons for rejection if the image has to be rejected


{
    "status": "success",
    "request": {
        "id": "req_81pP7cRqEvbdZ457WNQ2O",
        "timestamp": 1597952947.216626,
        "operations": 1
    },
    "summary": {
        "action": "reject",
        "reject_prob": 0.82,
        "reject_reason": [
            {
                "text": "Alcohol"
            }
        ]
    },
    "weapon": 0.0055,
    "alcohol": 0.819,
    "drugs": 0.001,
    "workflow": {
        "id": "wfl_81jOFDxdI8un4sm38y4Kw"
    }
}

Was this page helpful?