General Image Recognition (Enhanced)

Updated at:

This topic describes how to call the General Image Recognition (Enhanced) API to recognize content in images.

Overview

The General Image Recognition (Enhanced) API leverages large models to identify various elements in an image and provides corresponding tags for the identified elements.

Service

Description

Service name: General Image Recognition

service: generalRecognition

  • Leverages large models to identify various elements in an image.

  • Returns labels and confidence scores for identified elements.

Billing

General Image Recognition (Enhanced) supports two billing methods: pay-as-you-go and resource plans.

Pay-as-you-go

After you activate the Content Moderation (Enhanced) service, the default billing method is pay-as-you-go. You are charged daily based on your actual usage. You are not charged if you do not call the service.

Moderation type

Supported services

Unit price

Image Recognition Advanced (image_advanced)

  • General Image Recognition: generalRecognition

CNY 30.00 per 10,000 calls

Note

Each call to any service in the left column is counted as one billable item. You are charged based on the actual number of calls. For example, 100 calls to the General Image Recognition service cost CNY 0.30.

Note

The metering and billing frequency for the pay-as-you-go Content Moderation Enhanced Edition is once per hour. In the billing details, moderationType corresponds to the moderation type field. You can view the Billing Details.

Resource plans

If you have a large or consistent volume of recognition tasks, we recommend purchasing a resource plan in advance. The larger the resource plan, the greater the discount. You can purchase and use multiple plans. For more information, see Purchase resource plans for Content Moderation (Enhanced).

This resource plan applies to the Content Moderation (Enhanced) service and cannot be shared with resource plans for Content Moderation V1.0. The deduction factors are as follows:

Moderation type

Supported services

Deduction factor

Image Recognition Advanced (image_advanced)

  • General Image Recognition: generalRecognition

4: Each successful API call consumes 4 calls from your resource plan.

For example, if your resource plan has a capacity of 10 calls, one successful API call consumes 4 calls, leaving you with 6 calls.

After you purchase a resource plan, API calls are first deducted from the plan. If the plan's balance is insufficient, billing automatically switches to pay-as-you-go. We recommend that you monitor your resource plan balance and pay-as-you-go bills. You can set up low-balance alerts in the Resource Plan system within the Alibaba Cloud Billing Management console.

Integration

  1. Create an Alibaba Cloud account: Sign up now, and follow the on-screen instructions to complete the registration.

  2. Activate pay-as-you-go for Content Moderation: Ensure that you have activated the service. Activation is free. After you start making API calls, you are automatically billed for your usage. For more information, see Billing. You can also purchase resource plans. Resource plans offer tiered discounts and are ideal if you have a predictable or high usage volume.

  3. Create an AccessKey pair: Ensure that you have created an AccessKey pair in RAM. If you are using a sub-account, the primary account must grant the AliyunYundunGreenWebFullAccess permission to the sub-account. For detailed instructions, see Grant permissions by using RAM.

  4. Integrate the API: We recommend using an SDK to make API calls. For details, see the SDKs and integration guide for Image Moderation V2.0 (Enhanced).

API reference

Usage

You can call this API operation to create an image moderation task. For information on how to construct an HTTP request, see the Integration guide. You can also use pre-configured HTTP requests. For more information, see the SDK Reference.

  • Business interface: ImageModeration

  • Supported regions and endpoints:

Region

Public endpoint

Private endpoint

Supported services

China (Shanghai)

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

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

generalRecognition

China (Shenzhen)

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

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

  • Billing: This is a billable API operation. You are charged only for requests that return an HTTP status code of 200. Requests that result in errors are not charged. For more information about billing methods, see Billing.

  • Image requirements:

  • Images in the following formats are supported: PNG, JPG, JPEG, BMP, WEBP, TIFF, SVG, HEIC (the longest side must be less than 8,192 px), GIF (only the first frame is processed), and ICO (only the last image is processed).

  • The image size cannot exceed 20 MB. The height or width cannot exceed 16,384 pixels, and the total number of pixels cannot exceed 167 million. For best results, we recommend that the image resolution be at least 200 x 200 pixels. Low resolution may affect the accuracy of the recognition algorithm.

  • The image must be downloaded within 3 seconds. If the download times out, an error is returned.

QPS limit

The QPS limit for a single user for this API operation is 10 calls per second. If you exceed this limit, the system throttles your calls, which may impact your business. If your business requires a higher QPS limit, contact your business manager.

Debugging

Before integration, you can use OpenAPI Explorer to debug the Image Moderation (Enhanced) API online. This tool provides API call examples and SDK dependency information to help you quickly understand the API operations and parameters.

Important

API calls made in OpenAPI Explorer use your currently logged-in account. Therefore, these calls are included in your billable usage.

Request parameters

For information about the common request parameters that must be included in a request, see SDKs and integration guide for Image Moderation V2.0 (Enhanced).

The request body is a JSON object that contains the following parameters:

Parameter

Type

Required

Example

Description

Service

String

Yes

generalRecognition

The detection service for Image Moderation (Enhanced). Set the value to:

  • generalRecognition: General Image Recognition

ServiceParameters

JSONString

Yes

The parameter set for the content to be moderated. This is a JSON string. For a description of each parameter, see ServiceParameters.

Table 1. ServiceParameters

Parameter

Type

Required

Example

Description

imageUrl

String

Yes. Image Moderation (Enhanced) supports three methods to provide an image. Choose one of the following methods:

  • Use an image URL. Specify the imageUrl parameter.

  • Use an authorized OSS object. You must specify the ossBucketName, ossObjectName, and ossRegionId parameters.

  • Use a local image. When you upload a local image for moderation, it does not occupy your OSS storage space and is stored for only 30 minutes. The SDKs have integrated the local image upload feature. For code examples, see SDKs and integration guide for Image Moderation V2.0 (Enhanced).

https://img.alicdn.com/tfs/TB1U4r9AeH2gK0jSZJnXXaT1FXa-2880-480.png

The URL of the image to be moderated. The URL must be publicly accessible and cannot exceed 2,048 characters in length.

Note

The URL cannot contain Chinese characters. You can specify only one URL per request.

ossBucketName

String

bucket_01

The name of the authorized OSS bucket.

Note

To use a private endpoint for an OSS object, you must first use your primary account to grant permissions on the Cloud Resource Access Authorization page.

ossObjectName

String

2022023/04/24/test.jpg

The name of the file in the authorized OSS bucket.

ossRegionId

String

cn-beijing

The region where the OSS bucket is located.

dataId

String

No

img123****

The data ID of the object to be moderated.

The ID can be up to 64 characters in length and can contain letters, digits, underscores (_), hyphens (-), and periods (.). This ID helps you uniquely identify your business data.

referer

String

No

www.aliyun.com

The Referer request header, used for scenarios such as hotlink protection. The value can be up to 256 characters in length.

Response parameters

Parameter

Type

Example

Description

RequestId

String

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

The unique ID generated by Alibaba Cloud for the request. You can use this ID to troubleshoot issues.

Data

Object

The image moderation results. For more information, see Data.

Code

Integer

200

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

Msg

String

OK

The message returned for the request.

Table 2. Data

Parameter

Type

Example

Description

Ext

Object

The results of the General Image Recognition. For more information, see Ext.

DataId

String

img123******

The data ID of the moderated object.

Note

If you specified dataId in the request, the same value is returned here.

Result

Array

The results of the image moderation, including risk labels and confidence scores. For more information, see Result.

Note

For General Image Recognition, you can ignore this parameter.

Table 3. Ext

Parameter

Type

Example

Description

Recognition

Array

The results of the General Image Recognition. For more information, see Recognition.

Table 4. Recognition

Parameter

Type

Example

Description

Classification

String

Office building

The category identified by General Image Recognition.

Confidence

Float

81.22

The confidence score, which ranges from 0 to 100. The value is accurate to two decimal places. No confidence score is returned for a nonLabel result.

Table 5. Result

Parameter

Type

Example

Description

Label

String

nonLabel

The label returned by the operation. For General Image Recognition, the default value is nonLabel, which can be ignored.

Confidence

Float

99.99

The confidence score, which ranges from 0 to 100. The value is accurate to two decimal places. No confidence score is returned for a nonLabel result.

Examples

Request example

{
    "Service": "generalRecognition",
    "ServiceParameters": {
        "imageUrl": "https://img.alicdn.com/tfs/TB1U4r9AeH2gK0jSZJnXXaT1FXa-2880-480.png",
        "dataId": "img123****"
    }
}

Response example

{
    "Msg": "OK",
    "Code": 200,
    "Data": {
        "DataId": "img123****",
        "Ext": {
            "Recognition": [
                {
                    "Classification": "Building",
                    "Confidence": 92.73
                },
                {
                    "Classification": "Art",
                    "Confidence": 88.95
                },
                {
                    "Classification": "Illustration",
                    "Confidence": 82.22
                },
                {
                    "Classification": "Pencil",
                    "Confidence": 81.78
                },
                {
                    "Classification": "Sky",
                    "Confidence": 77.95
                },
                {
                    "Classification": "Office Building",
                    "Confidence": 66.94
                }
            ]
        },
        "Result": [
            {
                "Label": "nonLabel"
            }
        ]
    },
    "RequestId": "ABCD1234-1234-1234-1234-1234XYZ"
}
Note

The request and response examples in this document are formatted for readability. The actual responses are not indented or formatted with line breaks.

Status codes

The following table describes the status codes returned by the API. You are charged only for requests that return a status code of 200. No fees are incurred for other status codes.

Code

Description

200

The request was successful.

400

A request parameter is empty.

401

A request parameter is invalid.

402

The length of a request parameter exceeds the limit. Check the parameter and try again.

403

The request exceeds the QPS limit. Check your concurrency and try again.

404

An error occurred while downloading the image. Check the image and try again.

405

The image download timed out, which can happen if the image is inaccessible. Check the image and try again.

406

The image is too large. Resize the image and try again.

407

The image format is not supported. Use a supported format and try again.

408

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

500

A server-side error occurred.