All Products
Search
Document Center

AI Guardrails:CreateKeywordLib

Last Updated:Mar 31, 2026

Creates a keyword library for use in text anti-spam, ad violation detection, and audio anti-spam moderation.

Operation description

A keyword library stores terms that Content Moderation matches against submitted content. You can create libraries for three moderation scenarios:

  • Text anti-spam: matches terms against submitted text or detects similar text patterns.

  • Ad violation detection: matches terms extracted from images.

  • Audio anti-spam: matches terms converted from audio.

For more information about how to construct an HTTP request, see Request structure. You can also use an existing HTTP client. For more information, see SDK overview.

To create a keyword library in the Alibaba Cloud AI Guardrails console instead of calling this operation, see Manage custom text libraries.

Billing: This operation is free of charge.

QPS limits

This operation is limited to 10 calls per second per account. Exceeding this limit triggers throttling, which may affect your service.

Request parameters

For common request parameters required in all AI Guardrails API requests, see Common parameters.

The following table describes the parameters in the request body.

ParameterTypeRequiredExampleDescription
ServiceModuleStringYesopen_apiThe service module name. Set this parameter to open_api.
NameStringYestest1sdkdkThe name of the keyword library.
ResourceTypeStringYesTEXTThe moderation scenario for the keyword library. Valid values: <br>- TEXT: text anti-spam <br>- IMAGE: ad violation detection <br>- VOICE: audio anti-spam
BizTypesStringArrayNo["bizTypeA","bizTypeB"]The business scenarios to associate with the keyword library. To get business scenario names, call the CreateBizType operation.
CategoryStringYesBLACKThe category of the keyword library. Valid values: <br>- BLACK: a blacklist <br>- WHITE: a whitelist <br>- REVIEW: a review list
LibTypeStringYestextKeywordThe library type within the moderation scenario. Valid values: <br>Text anti-spam (`ResourceType`: `TEXT`): <br>- textKeyword: matches individual terms in submitted text <br>- similarText: matches text patterns in submitted text <br>Ad violation detection (`ResourceType`: `IMAGE`): <br>- textKeyword: matches terms extracted from images <br>Audio anti-spam (`ResourceType`: `VOICE`): <br>- voiceText: matches terms converted from audio
MatchModeStringNofuzzyThe matching method. Valid values: <br>- fuzzy: fuzzy match <br>- precise: exact match
EnableBooleanNotrueSpecifies whether to enable the keyword library immediately after creation. Valid values: <br>- true: enable the library. This is the default value. <br>- false: disable the library.

Response parameters

For common response parameters returned by all AI Guardrails API operations, see Common response parameters.

ParameterTypeExampleDescription
codeInteger200The HTTP status code. For a list of status codes, see Common error codes.
msgStringOKThe message returned for the request.
requestIdString795D8871-4889-4C0F-A8B1-C7D2B990FF61The request ID. Use this ID to troubleshoot issues.
idString123The ID of the created keyword library. Use this ID to manage the library in subsequent operations.

Examples

Sample request

http(s)://green.cn-shanghai.aliyuncs.com/?Action=CreateKeywordLib&ServiceModule=open_api
&<Common request parameters>

Request body:

{
  "Name": "test1sdkdk",
  "BizTypes": [],
  "Category": "BLACK",
  "ServiceModule": "open_api",
  "ResourceType": "TEXT",
  "LibType": "textKeyword"
}

Sample success response

{
  "RequestId": "795D8871-4889-4C0F-A8B1-C7D2B990FF61",
  "code": 200,
  "Id": "123"
}