Skip to main content

Moderation plugin

The Otoroshi LLM extension provides the Cloud APIM - Text moderation backend plugin to expose moderation models on an Otoroshi route. The API is compatible with the OpenAI moderations API.

Plugin configuration

Add the plugin to your route:

{
"enabled": true,
"plugin": "cp:otoroshi_plugins.com.cloud.apim.otoroshi.extensions.aigateway.plugins.OpenAICompatModeration",
"config": {
"refs": ["moderation-model-entity-id"]
}
}
ParameterTypeDefaultDescription
refsarray[]List of Moderation Model entity IDs

Usage

curl --request POST \
--url http://myroute.oto.tools:8080/v1/moderations \
--header 'content-type: application/json' \
--data '{
"input": "I love programming!",
"model": "omni-moderation-latest"
}'

Response

{
"results": [
{
"flagged": false,
"categories": {
"hate": false,
"violence": false,
"sexual": false,
"self-harm": false
},
"category_scores": {
"hate": 0.00001,
"violence": 0.00002,
"sexual": 0.00001,
"self-harm": 0.000005
}
}
],
"model": "omni-moderation-latest",
"usage": {
"total_tokens": 4,
"input_tokens": 4,
"output_tokens": 0
}
}

Model routing

When multiple moderation model providers are configured in refs, you can target a specific provider using the model field:

{
"input": "Text to moderate",
"model": "providerName/modelName"
}

The provider can be referenced by:

  • Entity name (slug): my-openai-moderation/omni-moderation-latest
  • Entity ID: moderation-model-id###omni-moderation-latest

If no provider prefix is specified, the first configured ref is used.

Route example

A complete route configuration exposing a moderation endpoint:

{
"frontend": {
"domains": ["moderation.my-domain.com"]
},
"backend": {
"targets": [
{
"hostname": "request.otoroshi.io",
"port": 443,
"tls": true
}
]
},
"plugins": [
{
"enabled": true,
"plugin": "cp:otoroshi.next.plugins.OverrideHost",
"config": {}
},
{
"enabled": true,
"plugin": "cp:otoroshi_plugins.com.cloud.apim.otoroshi.extensions.aigateway.plugins.OpenAICompatModeration",
"config": {
"refs": ["moderation-model-entity-id"]
}
}
]
}