All Products
Search
Document Center

Content Moderation:Initialization

Last Updated:Jul 31, 2023

Before you use Content Moderation SDK for Python to initiate an API request, you must create a client instance and modify the client configurations as needed.

Background information

When you create a client instance, you must specify the region as well as the AccessKey ID and AccessKey secret of your Alibaba Cloud account.

  • For more information about the supported regions, see Endpoints.

  • For more information about how to obtain the AccessKey ID and AccessKey secret of an Alibaba Cloud account, see Obtain an AccessKey pair.

Create a client instance to moderate images, audio, videos, and text

Use the following code to create a client instance to moderate images, audio, videos, and text:

from aliyunsdkcore import client
# Common ways to obtain environment variables:
# Obtain the AccessKey ID of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Obtain the AccessKey secret of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("We recommend that you obtain the AccessKey ID of your RAM user from environment variables", "We recommend that you obtain the AccessKey secret of your RAM user from environment variables", "cn-shanghai")

Create a client instance to manage custom image libraries, term libraries, and text pattern libraries

Use the following code to create a client instance to manage custom image libraries, term libraries, and text pattern libraries:

from aliyunsdkcore import client
# Common ways to obtain environment variables:
# Obtain the AccessKey ID of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Obtain the AccessKey secret of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("We recommend that you obtain the AccessKey ID of your RAM user from environment variables", "We recommend that you obtain the AccessKey secret of your RAM user from environment variables", "cn-shanghai")