Asynchronous URL risk detection API

更新时间:
复制 MD 格式

Content Moderation provides a URL risk detection service to identify potentially harmful links, such as those related to fraud, pornography, or gambling. This helps you protect your platform's content ecosystem. This topic describes how to use the asynchronous API for URL risk detection.

Get started

  1. Register an Alibaba Cloud account. For more information, see Register Now.

  2. Enable pay-as-you-go for Content Moderation: Make sure that you have enabled the service. No fees are charged for enabling the service. After you integrate and use the API, you are automatically billed based on your usage. For more information, see Billing details. You can also purchase a resource plan. Resource plans offer tiered discounts compared to the pay-as-you-go method and are suitable for users with predictable and high usage.

  3. Create an AccessKey: Ensure that you have created an AccessKey by using RAM. If you use the AccessKey of a RAM user, you must use your Alibaba Cloud account to grant the AliyunYundunGreenWebFullAccess permission to the RAM user. For more information, see RAM authorization.

  4. Develop your application. We recommend using an SDK to call the API. For more information, see the URL Risk Detection Developer Guide.

  5. The asynchronous URL risk detection service includes two API operations:

    • UrlAsyncModeration: Submits a URL risk detection task.

    • DescribeUrlModerationResult: Queries the results of a URL risk detection task.

Submit a moderation task

Usage notes

  • API operation: UrlAsyncModeration

  • Supported regions and endpoints:

Region

Public endpoint

Internal endpoint

Supported service

China (Shanghai)

https://green-cip.cn-shanghai.aliyuncs.com

https://green-cip-vpc.cn-shanghai.aliyuncs.com

url_detection_pro

China (Hangzhou)

https://green-cip.cn-hangzhou.aliyuncs.com

https://green-cip-vpc.cn-hangzhou.aliyuncs.com

  • Billing:

    This is a paid API operation. You are charged only for successful requests (HTTP 200). Requests that result in errors are not billed. For more information about billing, see Introduction and billing of URL risk detection.

  • Retrieving results: The asynchronous moderation task does not return detection results in real time. You can retrieve the results through a callback or by polling. The results are stored for a maximum of 3 days.

    • Callback: When you submit an asynchronous detection task, include the callback parameter in the request to receive detection results automatically.

    • Polling: When you submit an asynchronous detection task, do not include the callback parameter. After submitting the task, call the result query operation to get the detection results. Asynchronous detections are queued for processing, and results are returned within 24 hours.

  • Supported URL formats:

    The URL risk detection service supports URLs in the following format: http(s)://{IP or domain name}{:port}{/path}

    Note
    1. The URL can be specified with or without the http:// or https:// prefix.

    2. The domain name must consist of letters and digits, separated by periods (.). The top-level domain must contain 2 to 6 letters.

    3. The port must consist of 1 to 4 digits.

    4. The path can contain letters, digits, and common characters such as _!~*'().;?:@&=+$,%#-), but cannot contain Chinese characters.

    If an input URL does not match this format, the API returns a 400 error.

QPS limits

The queries per second (QPS) limit for a single user is 100 calls per second. If you exceed this limit, API calls are throttled. To avoid service disruption, we recommend implementing a reasonable call frequency. If your business requires a higher QPS limit or urgent scaling, contact your account manager.

Debugging

Before you integrate the API, you can use the Alibaba Cloud OpenAPI Explorer to debug the Submit a URL risk detection task operation online. The explorer provides sample code and SDK dependency information to help you understand the API usage and parameters.

Important

API debugging uses your logged-in account to call Content Moderation APIs. Therefore, API calls are billed and counted toward your usage quota.

Request parameters

Parameter

Type

Required

Example

Description

Service

String

Yes

url_detection_pro

The detection service. Valid value:

  • url_detection_pro: URL risk detection

ServiceParameters

JSONString

Yes

A JSON string containing parameters for the content to be moderated. For more information, see Table 1. ServiceParameters.

Table 1. ServiceParameters

Parameter

Type

Required

Example

Description

url

String

Yes

https://help.aliyun.com/

The URL to be detected. Note Ensure that the URL is in a valid format and that you submit only one URL per request.

dataId

String

No

url123****

A data ID that corresponds to the content. The ID can contain uppercase and lowercase letters, digits, underscores (_), hyphens (-), and periods (.). The ID can be up to 64 characters in length and serves to uniquely identify your business data.

callback

String

No

http://www.aliyundoc.com

The URL to which Content Moderation sends a callback notification with the detection results. HTTP and HTTPS are supported. If you omit this parameter, you must poll the service periodically to retrieve the results.

The callback endpoint must support POST requests, UTF-8 encoded data, and the form parameters ReqId, Checksum, and Content.

Content Moderation sets the ReqId, Checksum, and Content parameters and calls your callback endpoint to return the detection results based on the following rules and format.

  • ReqId: The request ID that is returned when you submit the asynchronous detection task.

  • Checksum: A signature string generated by using the SHA256 algorithm on a string that concatenates the user UID, seed, and content. The user UID is your Alibaba Cloud account ID, which can be found on the Alibaba Cloud console. To prevent tampering, generate a signature using the same algorithm upon receiving the callback and verify it against the Checksum value. Note You must use the UID of your Alibaba Cloud account, not the UID of a RAM user.

  • Content: A JSON string that contains the detection results.

Note

After your callback endpoint receives the results from Content Moderation, an HTTP status code of 200 indicates success. Any other status code indicates failure. If a notification fails, Content Moderation retries up to 16 times. If all 16 retries fail, the notification is abandoned. We recommend that you check the status of your callback endpoint.

seed

String

No

abc****

A random string for signature verification in callback notifications. The string can be up to 64 characters in length and can contain letters, digits, and underscores (_). You can customize this value to verify that the callback notification is initiated by Content Moderation.

Note

This parameter is required when you use a callback.

cryptType

String

No

SHA256

The encryption algorithm for the callback notification content. Content Moderation encrypts the result string (concatenated from user UID + seed + content) by using the specified algorithm before sending it to your callback URL. Valid values: ● SHA256 (Default): Uses the SHA256 encryption algorithm. ● SM3: Uses the Chinese cryptographic SM algorithm (HMAC-SM3). A hexadecimal string of lowercase letters and digits is returned.

Response parameters

Parameter

Type

Example

Description

Code

Integer

200

The status code. For more information, see Status codes.

Msg

String

OK

The response message.

RequestId

String

ABCD1234-1234-1234-1234-123****

The request ID.

Data

Object

The detection result.

ReqId

String

ABCD1234-1234-1234-1234-123****

The request ID.

DataId

String

img123******

The data ID that corresponds to the content.

Examples

Request example

{
    "Service": "url_detection_pro",
    "ServiceParameters": {
        "url": "https://help.aliyun.com/",
        "dataId": "url123******"
    }
}

Response example

{
    "Msg": "OK",
    "Code": 200,
    "RequestId": "ABCD1234-1234-1234-1234-1234XYZ",
    "Data": {
        "ReqId": "ABCD1234-1234-1234-1234-1234XYZ",
        "DataId": "url123******"
    }
}

Query moderation task results

Usage notes

  • API operation: DescribeUrlModerationResult.

  • Billing: This API operation is free of charge.

  • Query timeout: We recommend that you set the query interval to 5 minutes, which means you should query the results 5 minutes after you submit the asynchronous detection task. Results are automatically deleted after 3 days.

QPS limits

The QPS limit for a single user is 100 calls per second. If you exceed this limit, API calls are throttled, which may affect your business. We recommend that you make calls at a reasonable rate.

Debugging

Before you integrate the API, you can use the Alibaba Cloud OpenAPI Explorer to debug the Query the results of a URL risk detection task operation online. The explorer provides sample code and SDK dependency information to help you understand the API usage and parameters.

Request parameters

Parameter

Type

Required

Example

Description

reqId

String

Yes

70ED13B0-BC22-576D-9CCF-1CC12FEAC477

The request ID, which is the RequestId returned when you submit a moderation task.

Response parameters

Parameter

Type

Example

Description

RequestId

String

ABCD1234-1234-1234-1234-123****

A unique identifier for the request, generated by Alibaba Cloud. Use this ID for troubleshooting.

Data

Object

The URL risk detection results. For more information, see Table 2. Data.

Code

Integer

200

The status code. For more information, see Status codes.

Msg

String

OK

The response message.

Table 2. Data

Parameter

Type

Example

Description

Results

Array

The URL detection results, which include the risk label and confidence score. For more information, see Table 3. Result.

DataId

String

img123******

The data ID that corresponds to the content.

Note

If a dataId was passed in the request parameters, the same dataId is returned here.

ExtraInfo

Object

Additional reference information. For more information, see Table 4. ExtraInfo.

Table 3. Result

Parameter

Type

Example

Description

Label

String

sexual_url

The detection label assigned to the URL. A single URL may be assigned multiple labels and scores. The following labels are supported:

  • sexual_url: Suspected pornographic website

  • gambling_url: Suspected gambling website

  • phishing_url: Suspected phishing website

  • other_risk_url: Suspected fraud and other risks

  • safe_url: No risks detected

  • nonLabel: Risk status cannot be determined

Confidence

Float

81.22

The confidence score, which ranges from 0 to 100. The value is accurate to two decimal places.

Table 4. ExtraInfo

Parameter

Type

Example

Description

IcpType

String

Enterprise

The ICP filing type.

IcpNo

String

ICP file 123456789

The ICP filing number.

Examples

Request example

{
    "ReqId": "ABCD1234-1234-1234-1234-123****"
}

Response example

{
    "Msg": "OK",
    "Code": 200,
    "Data": {
        "DataId": "img123****",
        "Result": [
            {
                "Label": "sexual_url",
                "Confidence": 81.18
            }
        ],
        "ExtraInfo": {
            "IcpType": "Enterprise",
            "IcpNo": "ICP file 123456789"
        }
    },
    "RequestId": "ABCD1234-1234-1234-1234-123****"
}

Status codes

The following table describes the status codes returned by the API. You are charged only for successful requests (Code 200); other requests do not incur charges.

Code

Description

200

The request is successful.

280

The task is being moderated.

400

The request parameters are empty.

401

The request parameters are invalid.

402

The length of a request parameter does not meet the requirements. Check and modify the parameter.

403

The request exceeds the QPS limit. Check and adjust the concurrency.

405

The asynchronous detection timed out. We recommend that you try again.

408

The account is not authorized to call this API operation. This may be because the service is not activated, the account has an overdue payment, or the account is not granted the required permissions.

500

A system error occurred.