This topic describes how to call an operation to submit text moderation tasks. It intends to help you construct an HTTP call request.

  • For more information about how to construct an HTTP request, see Request structure.
  • You can also select an existing HTTP request. For more information, see SDK reference.

Description

Operation: /green/text/scan

You can call this operation to moderate text for violations.

Parameters scenes and label

Before submitting a moderation task, you must set the scenes parameter to specify the moderation scenario. In the response, the label parameter indicates the category of moderation results in the specified moderation scenario.

The following table lists the mapping between the scenes and label parameters in text anti-spam.
Scenario Description scenes label
Text anti-spam Uses multiple models and moderation methods to moderate text from multiple dimensions based on the text content and behavior rule to avoid risky content, such as pornographic content, ads, spam, terrorist content, and abuse. antispam
  • normal: The text is normal.
  • spam: The text contains junk content.
  • ad: The text contains ads.
  • politics: The text contains political content.
  • terrorism: The text contains terrorist content.
  • abuse: The text contains abuse.
  • porn: The text contains pornographic content.
  • flood: The text contains spam.
  • contraband: The text contains prohibited content.
  • meaningless: The text contains meaningless content.
  • customized: The text contains custom content. For example, the text contains a custom term.

Request parameters

For more information about the common request parameters that must be included in all Content Moderation API requests, see Common request parameters.

The following table describes the parameters in the request body.
Parameter Type Required Description
bizType String No The business scenario. You can customize content moderation policies to apply different moderation standards or algorithm policies to different business scenarios. You can create a business scenario by specifying bizType in the Content Moderation console. Alternatively, you can submit a ticket to ask us to help you create a business scenario.
scenes String array Yes The moderation scenario. Set the value to antispam.
tasks JSON array Yes The list of text moderation tasks. It is a JSON array that contains one or more elements. Each element is a structure. You can add up to 100 elements to the array, which means that you can moderate up to 100 pieces of text at a time. For more information about the structure of each element, see task.
Table 1. task
Parameter Type Required Description
clientInfo JSON structure No The information about the client. For more information, see the common query parameters in Common request parameters.
The server determines whether to use the global clientInfo parameter or the clientInfo parameter described in this table.
Note The clientInfo parameter described in this table takes a higher priority.
dataId String No The ID of the text to be moderated. Make sure that each ID is unique in a request.
content String Yes The content of the text to be moderated. Each piece of text can be up to 10,000 characters in length.

Response parameters

For more information about common response parameters that this operation returns, see Common response parameters.

The data parameter in the response body is a JSON array. The following table describes the parameters that each element of the JSON array contains.
Parameter Type Required Description
code Integer Yes The HTTP status code returned for the moderation task.
msg String Yes The message returned for the moderation task.
dataId String No The ID of the moderated text, which you specify in the dataId parameter of the moderation request.
taskId String Yes The ID of the moderation task.
content String No The content of the moderated text, which you specify in the moderation request.
filteredContent String No The text returned if the original text contains one or more terms in the custom term library, with the terms being replaced with asterisk (*).
results Array No The return results of the moderation task. If the HTTP status code 200 is returned to indicate a successful call, the array in the return results may contain one or more elements. Each element is a structure. For more information about the structure of each element, see result.
Table 2. result
Parameter Type Required Description
scene String Yes The moderation scenario of the moderated text, which you specify in the moderation request.
suggestion String Yes The machine-assisted moderation result of the moderated text. Valid values:
  • pass: The text is normal.
  • review: The text requires human review.
  • block: The text contains violations and can be deleted or blocked.
label String Yes The category of moderation results for the moderated text in the specified moderation scenario. For more information about valid values, see Parameters scenes and label.
rate Floating point Yes The probability that the moderated text falls into the detected category. Valid values: 0.00 to 100.00. A larger value indicates a higher probability that the text falls into this category.
Note The value is only for reference. Pay attention to the label and suggestion parameters.
extras JSON object No The additional information about the moderated text.
details Array No The details of the risky content that the moderated text hits. A piece of text can hit multiple pieces of risky content. For more information about the structure, see detail.
Table 3. detail
Parameter Type Required Description
label String Yes The category of the risky content that the moderated text hits in the specified moderation scenario. For more information about valid values, see Parameters scenes and label.
contexts Array No The context information of the risky content that the moderated text hits. For more information about the structure, see context.
hintWords JSON array No The information about the term that the moderated text hits, which is used to indicate the reason for the violation. Multiple terms that the text hits may be returned. For more information about the structure, see hintWord.
Table 4. context
Parameter Type Required Description
context String Yes The context of the risky content that the moderated text hits. If the text hits a term or text pattern in your custom text library, the term or text pattern is returned.
libName String No The name of the custom text library returned if the moderated text hits a term or text pattern in the library.
libCode String No The code of the custom text library returned if the moderated text hits a term or text pattern in the library.
ruleType String No The type of the behavior rule returned if the moderated text hits the behavior rule. Valid values:
  • user_id
  • ip
  • umid
  • content
  • similar_content
  • imei
  • imsi
Table 5. hintWord
Parameter Type Required Description
context String Yes The term that the moderated text hits.

Examples

Sample requests
{
  "scenes": ["antispam"],
  "tasks": [
    {
      "dataId": "xxxx$rdBjUC1C-1rd9Ah",
      "content": "Obama met with Trump in the White House yesterday."
    }
  ]
}
Sample success responses
{
    "msg":"OK",
    "code":200,
    "data":[
        {
            "msg":"OK",
            "code":200,
            "dataId":"xxxx$rdBjUC1C-1rd9Ah",
            "results":[
                {
                    "rate":50.0,
                    "suggestion":"review",
                    "details":[
                        {
                            "hintWords":[
                                {
                                    "context":"Obama"
                                }
                            ],
                            "contexts":[
                                {
                                    "libCode":"123456",
                                    "libName":"Name of your custom text library",
                                    "context":"Trump"
                                }
                            ],
                            "label":"politics"
                        }
                    ],
                    "label":"politics",
                    "scene":"antispam"
                }
            ],
            "content":"Obama met with Trump in the White House yesterday.",
            "filteredContent":"*** met with Trump in the White House yesterday.",
            "taskId":"xxxxxxyyyyyy-xxxx"
        }
    ],
    "requestId":"yyyyyyyy-862F-4BAE-8B4E-xxxxxxx"
}