Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Image Moderation (V3)

Updated on 2024-11-04 GMT+08:00

Function

This API analyzes and identifies whether the uploaded images contain pornographic elements or terrorism-related content, and returns the result to you.

URI

POST /v3/{project_id}/moderation/image

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token

It is used to obtain the permission to call APIs. For details about how to obtain the token, see Authentication. The value of X-Subject-Token in the response header is the token.

Enterprise-Project-Id

No

String

Enterprise project ID. Moderation allows you to use Enterprise Project Management Service (EPS) to split fees for resources used by different user groups and users. To obtain the enterprise project ID, go to the Enterprise Project Management console, click the enterprise project name, and obtain the enterprise project ID on the enterprise project details page. For how to create an enterprise project, see Content Moderation User Guide.

After an enterprise project is created, parameter transfer involves the following scenarios:

  • If a correct enterprise project ID is carried and Content Moderation can be used properly, the bills will be categorized under the corresponding enterprise project for that ID.
  • If an enterprise project ID that is in the correct format but does not actually exist is carried, and Content Moderation can be used properly, the bills will display the corresponding non-existent enterprise project ID.
  • If no enterprise project ID or an enterprise project ID with incorrect format (such as special characters) is carried, and Content Moderation can be used properly, the bills will be categorized under default.
Table 3 Request body parameters

Parameter

Mandatory

Type

Description

event_type

No

String

Event type. The options are as follows:

  • head_image: avatar
  • album: album
  • dynamic: story
  • article: post
  • comment: comment
  • room_cover: room cover
  • group_message: group chat image
  • message: private chat image
  • product: product image
NOTE:
  • A group chat image contains chat messages of multiple people.
  • The event types are preset business scenarios. (Some scenarios may not be intercepted.)
    1. If you want to enable custom moderation, you can add custom moderation policies on the console.
    2. If you have special moderation requirements, contact us for adjustment by submitting a service ticket.

categories

No

Array of strings

Detection scenario. The following scenarios are supported:

  • terrorism: terrorism-related elements
  • porn: pornographic elements
  • image_text: advertisement in images and text

You can set the parameter to any of the preceding values to check for the corresponding elements.

NOTE:

The number of detection times in each scenario is calculated by category.

url

No

String

Configure either this parameter or image.

Image URL. Internet HTTP and HTTPS URLs are supported.

image

No

String

Configure either this parameter or url.

Base64-encoded string of the image file, which cannot be larger than 10 MB. The image cannot exceed 20 x 20 pixels. JPG, PNG, JPEG, WEBP, GIF, TIFF, TIF, and HEIF formats are supported.

language

No

String

Language of the text in the image, which can be Chinese (zh), English (en), or Arabic (ar). The default value is zh.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

request_id

String

Unique ID of the request, which is used for troubleshooting. You are advised to save the ID.

Minimum length: 2

Maximum length: 64

result

ImageDetectionResult object

Calling result of a successful API call. This parameter is not included when the API fails to be called.

Table 5 ImageDetectionResult

Parameter

Type

Description

suggestion

String

Whether the image passes the check

  • block: The image contains sensitive information and fails to pass the check.
  • pass: The image does not contain sensitive information and passes the check.
  • review: The image needs to be manually reviewed.

category

String

Level-1 label of the detection result. The following categories are supported:

  • terrorism: terrorism-related information
  • porn: pornographic information
  • image_text: image and text

details

Array of ImageDetectionResultDetail objects

Detection details

Table 6 ImageDetectionResultDetail

Parameter

Type

Description

suggestion

String

Whether the image passes the check

  • block: The image contains sensitive information and fails to pass the check.
  • pass: The image does not contain sensitive information and passes the check.
  • review: The image needs to be manually reviewed.

category

String

Level-1 label of the detection result. The following categories are supported:

  • terrorism: terrorism-related information
  • porn: pornographic information
  • image_text: image and text

confidence

Float

Confidence. The value ranges from 0 to 1. A larger value indicates a higher confidence.

face_location

FaceLocationDetail object

Face location. It is an array that has four values, indicating the coordinates of the upper left corner and lower right corner, respectively.

For example, in the value [207,522,340,567], 207 indicates the horizontal coordinate of the upper left corner, 522 indicates the vertical coordinate of the upper left corner, 340 indicates the horizontal coordinate of the lower right corner, and 567 indicates the vertical coordinate of the lower right corner.

label

String

Detected label

Table 7 FaceLocationDetail

Parameter

Type

Description

top_left_x

Integer

Horizontal coordinate of the upper left corner of detected face

top_left_y

Integer

Vertical coordinate of the upper left corner of detected face

bottom_right_x

Integer

Horizontal coordinate of the lower right corner of detected face

bottom_right_y

Integer

Vertical coordinate of the lower right corner of detected face

Table 8 QRLocationDetail

Parameter

Type

Description

top_left_x

Integer

Horizontal coordinate of the upper left corner of the detected QR code

top_left_y

Integer

Vertical coordinate of the upper left corner of the detected QR code

bottom_right_x

Integer

Horizontal coordinate of the lower right corner of the detected QR code

bottom_right_y

Integer

Vertical coordinate of the lower right corner of the detected QR code

Table 9 OCRTextDetail

Parameter

Type

Description

segment

String

Hit risk segment

glossary_name

String

Name of the hit custom word dictionary. This field is returned only when a custom word dictionary is hit.

Status code: 400

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code of a failed API call. For details, see Error Codes.

This parameter is not included when the API is successfully called.

Minimum length: 8

Maximum length: 36

error_msg

String

Error message of a failed API call.

This parameter is not included when the API is successfully called.

Minimum length: 2

Maximum length: 512

Example Request

NOTE:

endpoint is the request URL for calling an API. Endpoints vary depending on services and regions. For details, see Endpoints.

For example, if the service is deployed in the CN North-Beijing4 region, the endpoint is moderation.cn-north-4.myhuaweicloud.com and the request URL is https://moderation.cn-north-4.myhuaweicloud.com/v3/{project_id}/moderation/image. For details about how to obtain the project ID, see Obtaining a Project ID.

  • Use the Base64 code of an image to check whether the image contains sensitive information. Set event_type to head_image and categories to porn and terrorism.
    POST https://{endpoint}/v3/{project_id}/moderation/image
    
    {
      "event_type" : "head_image",
      "image" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA...",
      "categories" : [ "porn", "terrorism" ]
    }
  • Use the URL an image to check whether the image contains sensitive information. Set event_type to head_image and categories to porn and terrorism.
    POST https://{endpoint}/v3/{project_id}/moderation/image
    {
      "event_type" : "head_image",
      "url" : "https://bucketname.obs.myhwclouds.com/ObjectName1",
      "categories" : [ "porn", "terrorism" ]
    }

Example Response

Status code: 200

Example successful response

{
  "request_id" : "53f9719c3730d1169e47403d5c8a9473",
  "result" : {
    "category" : "porn",
    "details" : [ {
      "category" : "porn",
      "confidence" : 0.9934315,
      "label" : "sexy_female",
      "suggestion" : "review"
    }, {
      "category" : "porn",
      "confidence" : 0.99798274,
      "label" : "intimacy",
      "suggestion" : "review"
    } ],
    "suggestion" : "review"
  }
}

Status code: 400

Example failed response

{
  "error_code" : "AIS.0402",
  "error_msg" : "The image format is not supported."
}

Status Codes

Status Code

Description

200

Example of a successful response

400

Example of a failed response

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback