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
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:
|
|
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: 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.
If you do not use scan result callbacks, you must poll periodically to obtain asynchronous detection results.
Procedure
-
Prepare an HTTP webhook address and a seed parameter to receive scan results.
-
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.
-
Log on to the AI Guardrails console.
-
In the left-side navigation pane, choose .
-
On the Machine Moderation page, click the Notification tab, and then click Create New Notification.
-
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.
-
-
-
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.
-
Prepare an HTTP webhook address and a seed parameter to receive scan results.
-
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.
|
|
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:
|
|
labels |
JSONArray |
No |
The labels set during self-review. This parameter can contain one or more of the following values:
|
Table 4. humanAuditResult
|
Parameter |
Type |
Required |
Description |
|
suggestion |
String |
Yes |
The Alibaba Cloud human review result. Valid values:
|
|
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"
}
}