Configure notifications

更新时间:
复制 MD 格式

AI Guardrails sends you asynchronous notifications with content detection and self-review results. To use or integrate this data, configure callback notifications. This topic describes how to configure callback notifications for the AI Guardrails API.

Background

Note

Both the AI Guardrails API and OSS content violation detection support callback notifications. For details on using callbacks with OSS content violation detection, see OSS content violation detection callback notification.

The AI Guardrails API supports two types of callback notifications: scan result notifications and review result notifications.

  • Scan result callback notification: After AI Guardrails completes a detection request, the server sends the results in a POST request to the specified webhook address.

  • Review result callback notification: After you modify detection results through self-review or by calling a feedback API, the AI Guardrails server sends the review result in a POST request to the specified webhook address. For more information, see self-review.

Key concepts

Before you configure callback notifications, understand the following concepts.

Parameter

Description

Webhook address

A webhook address is a server endpoint that you configure on the AI Guardrails console, typically a public URL of your business server. The webhook address must meet the following requirements:

  • Must be a publicly accessible URL that uses the HTTP or HTTPS protocol.

  • Must support the POST method.

  • Must support UTF-8 encoding for data transmission.

  • Must support receiving data in the application/x-www-form-urlencoded format.

  • Must support the checksum and content form parameters.

Seed

The seed verifies that requests sent to your webhook address originate from the AI Guardrails server.

Callback attempts

When your server receives a callback notification, it must respond with an HTTP status code of 200 to acknowledge successful receipt. Any other HTTP status code indicates a failure. If a notification fails, the AI Guardrails server retries sending it up to 3 times.

Callback data

Callback data is the payload that the AI Guardrails server sends to your webhook address. For details on the data structure, see Callback notification form data.

Table 1. Callback notification form data

Parameter

Type

Description

checksum

String

A signature used to verify data integrity. It is generated by applying the SHA256 algorithm to the concatenated string: <Alibaba Cloud account ID> + <seed> + <content>. You can find your Alibaba Cloud account ID on the Alibaba Cloud Management Console by hovering over your profile picture in the upper-right corner.

Note

To prevent tampering, you can generate a string by using the algorithm described above and verify it against the checksum when you receive the push result.

content

String

A JSON object serialized as a string. You must parse this string to access the JSON object. For details on the structure of the parsed content object, see The content field.

Note

The parameter structure of the content field differs between the AI Guardrails API and OSS content violation detection.

Scan result callback notification

All asynchronous AI Guardrails API operations support scan result callbacks, such as asynchronous image scan and asynchronous video scan. To receive scan results via callback, you must include the callback (webhook address) and seed (verification string) parameters in your asynchronous API request.

Note

If you do not use scan result callbacks, you must poll periodically to obtain asynchronous detection results.

Procedure

  1. Prepare an HTTP webhook address and a seed parameter to receive scan results.

  2. When you call an asynchronous AI Guardrails API operation, pass the corresponding callback and seed request parameters. For more information about the parameters, see the parameter description in the API reference for the specific operation.

Human review callback notification

Human review API operations do not return detection results in real time. Instead, the system notifies the caller by using callbacks. Human review falls into two categories: machine-assisted human review and pure human review. The callback method differs for each category, as described in the following sections.

  • Machine-assisted human review

    If you use the Alibaba Cloud human review service together with the machine moderation service, you must configure notifications on the console to receive callbacks for the human review module.

    1. Log on to the AI Guardrails console.

    2. In the left-side navigation pane, choose Machine Moderation V1.0 > Settings.

    3. On the Machine Moderation page, click the Notification tab, and then click Create New Notification.

    4. In the Create New Notification dialog box, enter a Title and Callback URL, and select an Encryption algorithm, a Notification type, and a Moderation Result. Then, click OK.

      After you save the configuration, the system automatically generates a seed. The seed verifies that requests to your callback endpoint are from Alibaba Cloud. Save the automatically generated seed.

      Important
      • If you have already configured a callback notification service for machine moderation, you can reuse the existing configuration or create a new one based on your business requirements.

      • You can receive callbacks for all review results, or select specific results based on your business scenarios.

      • For Manual Review Results by AlibabaCloud, select Alibaba Cloud Human Review Result.

      • Encryption algorithms:

        • SHA256: Uses the HMAC-SHA256 encryption algorithm.

        • SM3: Uses the SM3 encryption algorithm. It returns a lowercase hexadecimal string.

          For example, encrypting abc with SM3 returns 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0.

    5. On the BizType Manage tab, find the target business scenario, click Choose Notification Plan in the Actions column, and associate the Callback notification scheme you configured.

  • Pure human review

    If you use the Alibaba Cloud pure human review service, you must include the callback (webhook address) and seed (verification string) parameters in your request to receive human review callbacks.

    1. Prepare an HTTP webhook address and a seed parameter to receive scan results.

    2. When you call an asynchronous AI Guardrails API operation, pass the corresponding callback and seed request parameters.

      For more information about the parameters, see Human review for images, Human review for videos, Human review for text, and Review human review results.

Content field

After you enable callback notifications, AI Guardrails sends notifications that include a content form field. The following table describes the structure of this field.

Table 2. Structure of the content form field

Parameter

Type

Required

Description

scanResult

JSONObject

No

The scan result. The structure varies depending on the object type, such as an image or a video.

  • For images, the structure is the same as the results parameter that is returned for synchronous image scans. For more information, see Synchronous image scan.

  • For videos, the structure is the same as the results parameter that is returned for asynchronous video scans. For more information, see Asynchronous video scan.

auditResult

JSONObject

No

The result of your self-review. This field is returned only when you perform a self-review. For more information, see auditResult.

Note

This field is not returned if only scan results are pushed.

humanAuditResult

JSONObject

No

The Alibaba Cloud human review result. If you use the Alibaba Cloud human review service, this field contains the result. For more information, see humanAuditResult.

Table 3. auditResult

Parameter

Type

Required

Description

suggestion

String

Yes

The self-review result. Valid values:

  • block: The content is marked as a violation during the review.

  • pass: The content is marked as normal during the review.

labels

JSONArray

No

The labels set during self-review. This parameter can contain one or more of the following values:

  • porn: pornography

  • terrorism: terrorism and politically sensitive content

  • ad: advertisements in images or text

  • live: undesirable scenes

Table 4. humanAuditResult

Parameter

Type

Required

Description

suggestion

String

Yes

The Alibaba Cloud human review result. Valid values:

  • block: The content is a violation.

  • pass: The content is normal.

taskId

String

Yes

The ID of the detection task. Use this ID to correlate the review result with the corresponding content.

dataId

String

Yes

The ID of the detected content.

labels

JSONArray

No

The labels from the human review. This parameter may have multiple values.

Note

This parameter is not returned by default. To enable this field, contact your business representative.

Example of the content field

{
    "scanResult": {
        "code": 200,
        "msg": "OK",
        "taskId": "fdd25f95-4892-4d6b-aca9-7939bc6e9baa-1486198766695",
        "url": "http://1.jpg",
        "results": [
            {
                "rate": 100,
                "scene": "porn",
                "suggestion": "block",
                "label": "porn"
            }
        ]
    },
    "auditResult": {
        "suggestion": "block",
        "labels": [
            "porn",
            "ad",
            "terrorism"
        ]
    },
    "humanAuditResult": {
        "suggestion": "pass",
          "dataId": "yyyy",
          "labels": [
              "porn",
              "vulgar"
        ],
        "taskId": "xxxxxx"
    }
}