AI Aliyun Content Moderation Configuration
The ai-aliyun-content-moderation plugin uses Aliyun to evaluate selected request roles and LLM responses, including streaming responses, against a risk threshold. Configuration covers plugin parameters.
Parameters
See plugin common configurations for configuration options available to all plugins.
access_key_id
Aliyun access key ID.
access_key_secret
Aliyun secret access key. The value is encrypted before being stored.
region_id
Aliyun region ID.
endpoint
Aliyun endpoint.
check_request
If true, moderate the request content.
check_response
If true, moderate LLM response text. Non-streaming responses are checked before being returned to the client;
stream_check_modeonly controls streaming responses. Upstream responses with an HTTP status of 400 or higher are not moderated.request_check_service
Aliyun service used to moderate request text. Keep
request_check_length_limitwithin the selected service's character limit.request_check_length_limit
Request content length limit, in character count. If exceeded, the content will be sent in chunks.
For instance, if the request content has 250 characters and the
request_check_length_limitis set to100, then the content will be sent in 3 requests to Aliyun.response_check_service
Aliyun service used to moderate response text. Keep
response_check_length_limitwithin the selected service's character limit.response_check_length_limit
Response content length limit, in character count. If exceeded, the content will be sent in chunks.
For instance, if the response content has 250 characters and the
response_check_length_limitis set to100, then the content will be sent in 3 requests to Aliyun.risk_level_bar
valid value:
none,low,medium,high, ormaxThe minimum risk level that triggers a refusal. Levels are ordered
none,low,medium,high, andmax. Content with a lower risk level passes.Setting
nonerejects every non-empty text batch that receives a recognized risk level, including anoneresult. It does not disable moderation or make service failures fail closed.In
final_packetstreaming mode, the result is reported after delivery instead of blocking the content.deny_code
valid value:
between 200 and 599 inclusiveHTTP status returned when content is denied before response headers are sent. The default
200returns a provider-compatible refusal; set a4xxvalue to expose moderation as an HTTP error. After streaming starts, the status cannot be changed.deny_message
Message returned when request or response content is denied. If unset, the plugin uses Aliyun's moderation advice.
timeout
valid value:
greater than or equal to 1Timeout in milliseconds.
stream_check_mode
valid value:
realtimeorfinal_packetStreaming check mode, which specifies how to handle content moderation for streaming (SSE) responses.
realtimechecks batches while the response streams. A detected violation replaces the remaining stream with a denial message; content already delivered cannot be retracted.final_packetevaluates the complete response after the LLM finishes and addsrisk_levelanddeny_messageto the final moderation data. It does not block the delivered content.In API7 Enterprise 3.9.21 and 3.10.8, and in APISIX 3.19.0, final-packet results can reach clients when supported SSE streams contain no usage event.
Aborted streams do not receive a synthetic final result. API7 Enterprise 3.9.21 and 3.10.8, and APISIX 3.19.0, also suppress the result after a protocol failure event. See response moderation behavior.
stream_check_cache_size
valid value:
greater than or equal to 1Buffered UTF-8 text size in bytes that triggers a check in
realtimemode. This is a trigger, not a maximum batch size; an incoming chunk can cross it. A check also runs whenstream_check_intervalhas elapsed at a chunk boundary or the stream ends.stream_check_interval
valid value:
greater than or equal to 0.1Time threshold in seconds for a batch check in
realtimemode. It is evaluated when a response chunk is processed, not by an independent timer.keepalive
If true, enable HTTP keepalive to Aliyun.
keepalive_pool
valid value:
greater than or equal to 1Maximum number of connections in the keepalive pool.
keepalive_timeout
valid value:
greater than or equal to 1000Keepalive timeout in milliseconds.
ssl_verify
If true, enable SSL verification.
fail_mode
valid value:
skip,warn, orerrorBehavior when the plugin receives a request it cannot moderate, such as non-AI traffic on a Consumer binding or a request that did not pass through AI Proxy. With
skip, the request passes unchecked. Withwarn, it passes unchecked and a warning is logged. Witherror, the plugin rejects it with the applicable HTTP 400 or 500 response. None of these outcomes means moderation succeeded.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and in APISIX 3.18.0.
request_check_mode
valid value:
lastorallWhich turn messages in the request to moderate for roles selected by
request_check_roles. Withlast, only the latest consecutive block of selecteduserandtoolmessages is moderated. Withall, every selecteduserandtoolmessage is moderated. Thesystemrole is always checked on every request when selected.Introduced in API7 Enterprise 3.9.16 and 3.10.2, and in APISIX 3.18.0. API7 Enterprise 3.10.2 selects only user messages;
request_check_roleswas introduced in 3.10.3.request_check_roles
valid value:
user,tool, orsystemMessage roles to moderate on the request side.
userandtoolfollowrequest_check_mode;systemis checked on every request because system content can be affected by malicious tool-call arguments.In APISIX, selecting
systemalso coversdevelopermessages, which is the role OpenAI uses in place ofsystemon newer models and on the Responses API. There is no separatedeveloperentry. API7 Enterprise 3.9.18 and 3.10.5 use the same behavior; earlier API7 Enterprise versions did not moderatedevelopermessages.Tool-result moderation applies to OpenAI-compatible formats where tool output is represented as a distinct
toolrole or item.Introduced in API7 Enterprise 3.9.16 and 3.10.3, and APISIX 3.18.0.