# 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[​](#parameters "Direct link to Parameters")

See plugin [common configurations](https://docs.api7.ai/apisix/reference/plugin-common-configurations.md) for configuration options available to all plugins.

* access\_key\_id

  string

  required

  ***

  Aliyun access key ID.

* access\_key\_secret

  string

  required

  ***

  Aliyun secret access key. The value is encrypted before being stored.

* region\_id

  string

  required

  ***

  Aliyun region ID.

* endpoint

  string

  required

  ***

  Aliyun endpoint.

* check\_request

  boolean

  default: `true`

  ***

  If true, moderate the request content.

* check\_response

  boolean

  default: `false`

  ***

  If true, moderate LLM response text. Non-streaming responses are checked before being returned to the client; `stream_check_mode` only controls streaming responses. Upstream responses with an HTTP status of 400 or higher are not moderated.

* request\_check\_service

  string

  default: `llm_query_moderation`

  ***

  Aliyun service used to moderate request text. Keep `request_check_length_limit` within the selected service's character limit.

* request\_check\_length\_limit

  integer

  default: `2000`

  ***

  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_limit` is set to `100`, then the content will be sent in 3 requests to Aliyun.

* response\_check\_service

  string

  default: `llm_response_moderation`

  ***

  Aliyun service used to moderate response text. Keep `response_check_length_limit` within the selected service's character limit.

* response\_check\_length\_limit

  integer

  default: `5000`

  ***

  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_limit` is set to `100`, then the content will be sent in 3 requests to Aliyun.

* risk\_level\_bar

  string

  default: `high`

  valid value:

  `none`, `low`, `medium`, `high`, or `max`

  ***

  The minimum risk level that triggers a refusal. Levels are ordered `none`, `low`, `medium`, `high`, and `max`. Content with a lower risk level passes.

  Setting `none` rejects every non-empty text batch that receives a recognized risk level, including a `none` result. It does not disable moderation or make service failures fail closed.

  In `final_packet` streaming mode, the result is reported after delivery instead of blocking the content.

* deny\_code

  integer

  default: `200`

  valid value:

  between 200 and 599 inclusive

  ***

  HTTP status returned when content is denied before response headers are sent. The default `200` returns a provider-compatible refusal; set a `4xx` value to expose moderation as an HTTP error. After streaming starts, the status cannot be changed.

* deny\_message

  string

  ***

  Message returned when request or response content is denied. If unset, the plugin uses Aliyun's moderation advice.

* timeout

  integer

  default: `10000`

  valid value:

  greater than or equal to 1

  ***

  Timeout in milliseconds.

* stream\_check\_mode

  string

  default: `final_packet`

  valid value:

  `realtime` or `final_packet`

  ***

  Streaming check mode, which specifies how to handle content moderation for streaming (SSE) responses.

  `realtime` checks batches while the response streams. A detected violation replaces the remaining stream with a denial message; content already delivered cannot be retracted.

  `final_packet` evaluates the complete response after the LLM finishes and adds `risk_level` and `deny_message` to 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](https://docs.api7.ai/hub/ai-aliyun-content-moderation.md#behavior-by-request-format).

* stream\_check\_cache\_size

  integer

  default: `128`

  valid value:

  greater than or equal to 1

  ***

  Buffered UTF-8 text size in bytes that triggers a check in `realtime` mode. This is a trigger, not a maximum batch size; an incoming chunk can cross it. A check also runs when `stream_check_interval` has elapsed at a chunk boundary or the stream ends.

* stream\_check\_interval

  number

  default: `3`

  valid value:

  greater than or equal to 0.1

  ***

  Time threshold in seconds for a batch check in `realtime` mode. It is evaluated when a response chunk is processed, not by an independent timer.

* keepalive

  boolean

  default: `true`

  ***

  If true, enable HTTP keepalive to Aliyun.

* keepalive\_pool

  integer

  default: `30`

  valid value:

  greater than or equal to 1

  ***

  Maximum number of connections in the keepalive pool.

* keepalive\_timeout

  integer

  default: `60000`

  valid value:

  greater than or equal to 1000

  ***

  Keepalive timeout in milliseconds.

* ssl\_verify

  boolean

  default: `true`

  ***

  If true, enable SSL verification.

* fail\_mode

  string

  default: `skip`

  valid value:

  `skip`, `warn`, or `error`

  ***

  Behavior 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. With `warn`, it passes unchecked and a warning is logged. With `error`, 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

  string

  default: `last`

  valid value:

  `last` or `all`

  ***

  Which turn messages in the request to moderate for roles selected by `request_check_roles`. With `last`, only the latest consecutive block of selected `user` and `tool` messages is moderated. With `all`, every selected `user` and `tool` message is moderated. The `system` role 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_roles` was introduced in 3.10.3.

* request\_check\_roles

  array\[string]

  default: `["user"]`

  valid value:

  `user`, `tool`, or `system`

  ***

  Message roles to moderate on the request side. `user` and `tool` follow `request_check_mode`; `system` is checked on every request because system content can be affected by malicious tool-call arguments.

  In APISIX, selecting `system` also covers `developer` messages, which is the role OpenAI uses in place of `system` on newer models and on the Responses API. There is no separate `developer` entry. API7 Enterprise 3.9.18 and 3.10.5 use the same behavior; earlier API7 Enterprise versions did not moderate `developer` messages.

  Tool-result moderation applies to OpenAI-compatible formats where tool output is represented as a distinct `tool` role or item.

  Introduced in API7 Enterprise 3.9.16 and 3.10.3, and APISIX 3.18.0.
