Skip to content

参考

基于 OpenAI Moderation / Google Perspective / Azure Content Safety / AWS Comprehend 官方文档(2026 年)编写

OpenAI Moderation

端点

POST https://api.openai.com/v1/moderations

请求

json
{
  "model": "omni-moderation-latest",
  "input": "待审核文本"  // 或数组,或图文混合数组
}

模型

模型输入类别数
omni-moderation-latest文本 + 图像13(文本)+ 6(图像)
text-moderation-latest仅文本11(旧版)

13 个文本类别

类别含义
harassment骚扰
harassment/threatening含威胁的骚扰
hate仇恨言论
hate/threatening含威胁的仇恨
illicit鼓励非法活动(omni 新增)
illicit/violent含暴力的非法活动(omni 新增)
self-harm自残
self-harm/intent自残意图
self-harm/instructions自残方法说明
sexual性内容
sexual/minors涉未成年人
violence暴力
violence/graphic血腥暴力

6 个图像类别

omni-moderation-latest 图像支持的子集(具体见官方 model card)。

响应

json
{
  "id": "modr-...",
  "model": "omni-moderation-latest",
  "results": [{
    "flagged": true,
    "categories": {
      "hate": true,
      "harassment": false,
      ...
    },
    "category_scores": {
      "hate": 0.93,
      "harassment": 0.12,
      ...
    }
  }]
}

限制

  • 单次请求最多 32,768 字符
  • Batch:input 数组最多 32 条
  • Rate limit:与 OpenAI 账号 tier 相关
  • 免费:不消耗 token 费用

Google Perspective API

端点

POST https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key=API_KEY

请求

json
{
  "comment": {"text": "评论内容"},
  "requestedAttributes": {
    "TOXICITY": {},
    "INSULT": {}
  },
  "languages": ["en"],
  "doNotStore": false,
  "spanAnnotations": false
}

属性

Attribute含义多语言
TOXICITY总体毒性✅ 多语种
SEVERE_TOXICITY极端攻击✅ 多语种
IDENTITY_ATTACK身份攻击
INSULT侮辱
PROFANITY脏话
THREAT威胁
SEXUALLY_EXPLICIT性露骨
FLIRTATION调情部分语言
SPAM垃圾仅英文
INCOHERENT不连贯仅英文
UNSUBSTANTIAL空洞仅英文
OBSCENE猥亵实验
INFLAMMATORY煽动实验

响应

json
{
  "attributeScores": {
    "TOXICITY": {
      "spanScores": [{"begin": 0, "end": 12, "score": {"value": 0.82}}],
      "summaryScore": {"value": 0.82, "type": "PROBABILITY"}
    }
  },
  "detectedLanguages": ["zh"],
  "languages": ["zh"]
}

限制

  • 输入 ≤3000 字节(UTF-8)
  • 默认配额:1000 QPS(按 attribute 计),实际常 100-1000 QPS
  • 免费

Azure AI Content Safety

端点

POST {endpoint}/contentsafety/text:analyze?api-version=2024-09-01
POST {endpoint}/contentsafety/image:analyze?api-version=2024-09-01

文本审核

python
from azure.ai.contentsafety.models import AnalyzeTextOptions

result = client.analyze_text(AnalyzeTextOptions(
    text="内容",
    categories=[Hate, Sexual, Violence, SelfHarm],  # 可选,默认全部
    blocklist_names=["my_blocklist"],
    halt_on_blocklist_hit=False,
    output_type="FourSeverityLevels",  # 或 SeverityLevels
))

类别 + 严重度

Category0246
Hate轻微偏见明显仇恨严重/煽动
Sexual暗示明显露骨
Violence描述描绘鼓励/血腥
SelfHarm提及描述行为鼓励/教唆

图像审核

python
result = client.analyze_image(AnalyzeImageOptions(
    image=ImageData(content=bytes)
))

限制:≤4MB,50x50 ~ 7200x7200,JPEG/PNG/GIF/BMP/TIFF/WEBP。

Blocklists

python
# 创建
client.create_or_update_text_blocklist(name="my_list", resource=...)

# 加项
client.add_or_update_text_blocklist_items(name, body={
    "block_items": [
        {"text": "敏感词"},
        {"pattern": "v[i1]agra", "is_regex": True},
    ]
})

# 审核时引用
result = client.analyze_text(AnalyzeTextOptions(text=..., blocklist_names=["my_list"]))
print(result.blocklists_match)

Prompt Shields

python
result = client.analyze_text(AnalyzeTextOptions(
    text=user_input,
    prompt_shield_analysis=TextPromptShieldAnalysisConfig(enable=True),
    documents=[TextDocument(text=retrieved_doc)]
))
# result.prompt_analysis.user_prompt_analysis.attack_detected
# result.prompt_analysis.documents_analysis[].attack_detected

限制:prompt ≤10K 字符;最多 5 个文档,总 10K 字符。

Groundedness Detection

python
result = client.detect_groundingness(DetectGroundednessOptions(
    domain="medical",
    task="QnA",  # 或 "Summarization"
    qna={"query": "Q", "answer": "A"},
    grounding_source={"text": "..."}
))

限制:源 ≤55K 字符;query + answer ≤7500 字符;query ≥3 词。

Protected Material Detection

python
client.detect_text_protected_material(AnalyzeTextOptions(text=llm_output))
# 或检测代码:
client.detect_code_protected_material(...)

限制:≥110 字符(针对 LLM 输出)。

Custom Categories

  • Rapid:规则式,立即可用,文本+图像
  • Standard:训练式,需提交训练任务(ARN)

版本弃用

  • Public Preview:新版本后旧 90 天 deprecated
  • GA:新 GA 后旧 90 天 deprecated(保持兼容前提下)

限制速查

Feature限制
Text10K 字符
Image4MB / 50x50~7200x7200
Multimodal文本 1K + 图 4MB
Prompt Shields10K 字符 + 5 doc
Groundedness源 55K / q+a 7500
Custom Categories Standard1K 字符
Task Adherence100K 字符

Rate Limits

TierModerationPrompt ShieldsGroundednessCustom Standard
F05 RPS5 RPSN/A5 RPS
S01000 RP10S1000 RP10S50 RPS5 RPS

语言支持

英文 only:Protected Material / Groundedness / Custom Categories Standard 多语言(中英法德西意日葡):文本 / 图像 / Prompt Shields / Custom Categories Rapid

AWS Comprehend

Toxicity Detection

python
result = comprehend.detect_toxic_content(
    TextSegments=[{"Text": "..."}],
    LanguageCode='en'
)

7 标签:PROFANITY / SEVERE_PROFANITY / DEROGATORY / HATE_SPEECH / INSULT / GRAPHIC / HARASSMENT_OR_ABUSE

PII 检测

python
result = comprehend.detect_pii_entities(Text="...", LanguageCode='en')
# 实体:NAME / EMAIL / PHONE / ADDRESS / SSN / CREDIT_DEBIT_NUMBER / BANK_ACCOUNT ...

自定义分类

需要训练数据 → 异步训练 → 用 endpoint 推理。

价格

  • 按字符 / 文档计费
  • 50K-100K 字符免费 tier

开源自部署

模型 / 工具用途
Llama GuardLLM-as-judge,分类有害内容
Llama Prompt Guard越狱检测
Guardrails AIPython 框架,组合多规则
NeMo GuardrailsNVIDIA 流程编排
Lassomoderation商用,组合多 API

价格速查

服务价格
OpenAI Moderation免费
Google Perspective免费
Azure Content Safety F0免费 tier
Azure Content Safety S0按 API 调用计费
AWS Comprehend按字符计费,有免费 tier

资源链接