OpenAI 创建内容审核

2026-11-11 09:54 更新

创建内容审核

post /moderations

判断文本和/或图像输入是否可能有害。详情参阅 内容审核指南。

请求体参数

内容类型为 application/json。

  • input: string or array of string or array of ImageURL { image_url, type } or Text { text, type }

待分类的输入。可以是单个字符串、字符串数组,或与其他模型使用的结构类似的 多模态输入对象数组。

  • string

要进行内容审核的文本字符串。

  • array of string

要进行内容审核的字符串数组。

  • array of ImageURL { image_url, type } or Text { text, type }

提供给审核模型的多模态输入数组。

  • ImageURL object { image_url, type }

描述待分类图像的对象。

  • image_url: object { url }

包含图像 URL,或包含 Base64 编码图像的 data URL。

  • url: string

图像的 URL 或 Base64 编码的图像数据。

format: uri

  • type: "image_url"

固定为 image_url。

  • "image_url"

  • Text object { text, type }

描述待分类文本的对象。

  • text: string

待分类的文本字符串。

  • type: "text"

固定为 text。

  • "text"

  • model: optional string or ModerationModel (default: "omni-moderation-latest")

要使用的内容审核模型。详情参阅 内容审核指南, 其中也列出了可用模型。

  • string

  • ModerationModel = "omni-moderation-latest" or "omni-moderation-2024-09-26" or "text-moderation-latest" or "text-moderation-stable"

  • "omni-moderation-latest"

  • "omni-moderation-2024-09-26"

  • "text-moderation-latest"

  • "text-moderation-stable"

返回值

  • id: string

内容审核请求的唯一标识。

  • model: string

用于生成审核结果的模型。

  • results: array of Moderation

审核结果对象列表。

  • categories: object { harassment, "harassment/threatening", hate, 10 more }

各个审核类别及其是否被标记的结果。

  • harassment: boolean

表达、煽动或宣扬针对任何对象的骚扰性言论的内容。

  • "harassment/threatening": boolean

包含针对任何对象的暴力或严重伤害的骚扰内容。

  • hate: boolean

基于种族、性别、族裔、宗教、国籍、性取向、残障状况或种姓表达、煽动或宣扬仇恨的内容。针对非受保护群体(例如国际象棋玩家)的仇恨内容归入骚扰类别。

  • "hate/threatening": boolean

基于种族、性别、族裔、宗教、国籍、性取向、残障状况或种姓,包含对目标群体施加暴力或严重伤害的仇恨内容。

  • illicit: boolean or null

包含帮助策划或实施不法行为的指导或建议,或说明如何实施违法行为的内容。例如,指导“如何在商店行窃”属于此类。

  • "illicit/violent": boolean or null

包含帮助策划或实施伴随暴力的不法行为的指导或建议,或提供获取任何武器的指导或建议的内容。

  • "self-harm": boolean

宣扬、鼓励或描绘自伤行为的内容,例如自杀、自残和进食障碍。

  • "self-harm/instructions": boolean

鼓励实施自伤行为(例如自杀、自残和进食障碍),或提供实施此类行为的指导或建议的内容。

  • "self-harm/intent": boolean

说话者表达自己正在或打算实施自伤行为的内容,例如自杀、自残和进食障碍。

  • sexual: boolean

旨在引起性兴奋的内容,例如性行为描写,或推广性服务的内容(性教育和性健康内容除外)。

  • "sexual/minors": boolean

涉及未满 18 岁者的色情内容。

  • violence: boolean

描绘死亡、暴力或身体伤害的内容。

  • "violence/graphic": boolean

以血腥或露骨细节描绘死亡、暴力或身体伤害的内容。

  • category_applied_input_types: object { harassment, "harassment/threatening", hate, 10 more }

各类别及其评分所适用的输入类型列表。

  • harassment: array of "text"

“骚扰”类别评分适用的输入类型。

  • "text"

  • "harassment/threatening": array of "text"

“威胁性骚扰”类别评分适用的输入类型。

  • "text"

  • hate: array of "text"

“仇恨”类别评分适用的输入类型。

  • "text"

  • "hate/threatening": array of "text"

“威胁性仇恨”类别评分适用的输入类型。

  • "text"

  • illicit: array of "text"

“不法行为”类别评分适用的输入类型。

  • "text"

  • "illicit/violent": array of "text"

“暴力不法行为”类别评分适用的输入类型。

  • "text"

  • "self-harm": array of "text" or "image"

“自伤”类别评分适用的输入类型。

  • "text"

  • "image"

  • "self-harm/instructions": array of "text" or "image"

“自伤指导”类别评分适用的输入类型。

  • "text"

  • "image"

  • "self-harm/intent": array of "text" or "image"

“自伤意图”类别评分适用的输入类型。

  • "text"

  • "image"

  • sexual: array of "text" or "image"

“色情”类别评分适用的输入类型。

  • "text"

  • "image"

  • "sexual/minors": array of "text"

“涉及未成年人的色情”类别评分适用的输入类型。

  • "text"

  • violence: array of "text" or "image"

“暴力”类别评分适用的输入类型。

  • "text"

  • "image"

  • "violence/graphic": array of "text" or "image"

“血腥暴力”类别评分适用的输入类型。

  • "text"

  • "image"

  • category_scores: object { harassment, "harassment/threatening", hate, 10 more }

各类别及模型预测分数的列表。

  • harassment: number

“骚扰”类别的评分。

  • "harassment/threatening": number

“威胁性骚扰”类别的评分。

  • hate: number

“仇恨”类别的评分。

  • "hate/threatening": number

“威胁性仇恨”类别的评分。

  • illicit: number

“不法行为”类别的评分。

  • "illicit/violent": number

“暴力不法行为”类别的评分。

  • "self-harm": number

“自伤”类别的评分。

  • "self-harm/instructions": number

“自伤指导”类别的评分。

  • "self-harm/intent": number

“自伤意图”类别的评分。

  • sexual: number

“色情”类别的评分。

  • "sexual/minors": number

“涉及未成年人的色情”类别的评分。

  • violence: number

“暴力”类别的评分。

  • "violence/graphic": number

“血腥暴力”类别的评分。

  • flagged: boolean

以下类别中是否有任何类别被标记。

请求示例

## 先设置 OPENAI_API_KEY,并替换文件路径或资源 ID 后再运行。
curl https://api.openai.com/v1/moderations \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
          "input": "在此填写待审核文本",
          "model": "omni-moderation-2024-09-26"
        }'

200 响应示例

{
  "id": "id",
  "model": "model",
  "results": [
    {
      "categories": {
        "harassment": true,
        "harassment/threatening": true,
        "hate": true,
        "hate/threatening": true,
        "illicit": true,
        "illicit/violent": true,
        "self-harm": true,
        "self-harm/instructions": true,
        "self-harm/intent": true,
        "sexual": true,
        "sexual/minors": true,
        "violence": true,
        "violence/graphic": true
      },
      "category_applied_input_types": {
        "harassment": [
          "text"
        ],
        "harassment/threatening": [
          "text"
        ],
        "hate": [
          "text"
        ],
        "hate/threatening": [
          "text"
        ],
        "illicit": [
          "text"
        ],
        "illicit/violent": [
          "text"
        ],
        "self-harm": [
          "text"
        ],
        "self-harm/instructions": [
          "text"
        ],
        "self-harm/intent": [
          "text"
        ],
        "sexual": [
          "text"
        ],
        "sexual/minors": [
          "text"
        ],
        "violence": [
          "text"
        ],
        "violence/graphic": [
          "text"
        ]
      },
      "category_scores": {
        "harassment": 0,
        "harassment/threatening": 0,
        "hate": 0,
        "hate/threatening": 0,
        "illicit": 0,
        "illicit/violent": 0,
        "self-harm": 0,
        "self-harm/instructions": 0,
        "self-harm/intent": 0,
        "sexual": 0,
        "sexual/minors": 0,
        "violence": 0,
        "violence/graphic": 0
      },
      "flagged": true
    }
  ]
}

图像与文本示例

## 先设置 OPENAI_API_KEY,并替换文件路径或资源 ID 后再运行。
curl https://api.openai.com/v1/moderations \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": [
      { "type": "text", "text": "在此填写待审核文本" },
      {
        "type": "image_url",
        "image_url": {
          "url": "https://example.com/image.png"
        }
      }
    ]
  }'

响应示例

{
  "id": "modr-0d9740456c391e43c445bf0f010940c7",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": true,
      "categories": {
        "harassment": true,
        "harassment/threatening": true,
        "sexual": false,
        "hate": false,
        "hate/threatening": false,
        "illicit": false,
        "illicit/violent": false,
        "self-harm/intent": false,
        "self-harm/instructions": false,
        "self-harm": false,
        "sexual/minors": false,
        "violence": true,
        "violence/graphic": true
      },
      "category_scores": {
        "harassment": 0.8189693396524255,
        "harassment/threatening": 0.804985420696006,
        "sexual": 1.573112165348997e-6,
        "hate": 0.007562942636942845,
        "hate/threatening": 0.004208854591835476,
        "illicit": 0.030535955153511665,
        "illicit/violent": 0.008925306722380033,
        "self-harm/intent": 0.00023023930975076432,
        "self-harm/instructions": 0.0002293869201073356,
        "self-harm": 0.012598046106750154,
        "sexual/minors": 2.212566909570261e-8,
        "violence": 0.9999992735124786,
        "violence/graphic": 0.843064871157054
      },
      "category_applied_input_types": {
        "harassment": [
          "text"
        ],
        "harassment/threatening": [
          "text"
        ],
        "sexual": [
          "text",
          "image"
        ],
        "hate": [
          "text"
        ],
        "hate/threatening": [
          "text"
        ],
        "illicit": [
          "text"
        ],
        "illicit/violent": [
          "text"
        ],
        "self-harm/intent": [
          "text",
          "image"
        ],
        "self-harm/instructions": [
          "text",
          "image"
        ],
        "self-harm": [
          "text",
          "image"
        ],
        "sexual/minors": [
          "text"
        ],
        "violence": [
          "text",
          "image"
        ],
        "violence/graphic": [
          "text",
          "image"
        ]
      }
    }
  ]
}

单个字符串示例

## 先设置 OPENAI_API_KEY,并替换文件路径或资源 ID 后再运行。
curl https://api.openai.com/v1/moderations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": "在此填写待审核文本"
  }'
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号