All Products
Document Center


Last Updated: Jun 06, 2019

Interface description

SDK interfaces

  1. ImageAsyncScanRequest


Asynchronous image moderation: Identifies risky scenes in images, such as adult content.It must work with ImageAsyncScanResultsRequest to query results in a polling fashion.


  1. ap-southeast-1


Image moderation involves a variety of scenes, and each scene corresponds to a specific label. The relationship between scenes and labels is as follows:

Scene Label Remarks
porn normal Normal image without adult content
porn sexy Sexual image
porn porn Pornographic image

For example, if you want to identify pornographic images in your business, set the “scenes” parameter in the ImageAsyncScanRequest interface to porn. Similarly, you can set “scenes” to other values to suit different identification purposes.

Image requirements

  1. The image link protocol can be either HTTP or HTTPS.
  2. The image format can be PNG, JPG, JPEG, BMP, or GIF.
  3. The maximum image size for synchronous calls is 5 MB and that for asynchronous calls is 20 MB. The download time-out period is 3 seconds.
  4. The recommended image pixel is not smaller than 256 x 256. If the pixel is excessively small, the identification performance may be adversely affected.
  5. The response period of the Image Moderation API is determined by the image download period. Make sure that the storage service of the images is stable. It is recommended to store the images in OSS or cache them in CDN.

Call methods

Asynchronous image moderation – interface call example

  1. #coding=utf-8
  2. from aliyunsdkcore import client
  3. from aliyunsdkcore.profile import region_provider
  4. from aliyunsdkgreen.request.v20170112 import ImageAsyncScanRequest
  5. import json
  6. import uuid
  7. import datetime
  8. # Please update aliyun.ak.conf to replace with your accessKeyId and accessKeySecret
  9. clt = client.AcsClient("your accessKeyId", "your accessKeySecret",'ap-southeast-1')
  10. region_provider.modify_point('Green', 'ap-southeast-1', '')
  11. request = ImageAsyncScanRequest.ImageAsyncScanRequest()
  12. request.set_accept_format('JSON')
  13. # Multiple images allowed in async requests. At most 50 images to build 50 tasks.
  14. task1 = {"dataId": str(uuid.uuid1()),
  15. "url":"http://xxx.jpg",
  16. "time"
  17. }
  18. request.set_content(bytearray(json.dumps({"tasks": [task1], "scenes": ["porn"]}), "utf-8"))
  19. response = clt.do_action(request)
  20. print response
  21. result = json.loads(response)
  22. if 200 == result["code"]:
  23. taskResults = result["data"]
  24. for taskResult in taskResults:
  25. if(200 == taskResult["code"]):
  26. taskId = taskResult["taskId"]
  27. print taskId
  28. #Save taskId for querying results later, refer to ImageAsyncScanResultsRequest