Skip to content

Moderations

检查文本(或多模态内容)是否违反使用政策,兼容 OpenAI Moderations API。

POST https://api.wrouter.io/v1/moderations

请求体

参数类型必填说明
inputstring | array单条文本,或多条文本/多模态对象的数组
modelstringomni-moderation-latesttext-moderation-stable;缺省时使用网关默认

响应

json
{
  "id": "modr-xxx",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": true,
      "categories": {
        "hate": false,
        "harassment": true,
        "self-harm": false,
        "sexual": false,
        "violence": false,
        "...": false
      },
      "category_scores": {
        "harassment": 0.87,
        "...": 0.01
      }
    }
  ]
}

resultsinput 数组一一对应。

示例

bash
curl https://api.wrouter.io/v1/moderations \
  -H "Authorization: Bearer $WROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input": "这是一条待审核文本"}'
python
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://api.wrouter.io/v1")
r = client.moderations.create(input="这是一条待审核文本")
if r.results[0].flagged:
    print("违反政策:", r.results[0].categories)

应用场景

  • 用户输入预审:在调用 Chat Completions 前过滤违规 prompt
  • 模型输出后审:流式输出收完后做一次审核
  • 批量内容合规:UGC 平台用作内容审核辅助工具

该接口仅返回风险分类与得分,不会自动拒绝调用。是否拦截由你自己决定。