# omni-moderation-latest 内容审核
> 判断一段文本或图片是否属于敏感内容
> 按类别分别给出评分，便于自行设阈值
> 可以作为生成前的守门员，也可以独立使用
`POST /v1/moderations`
## 认证
- `Authorization` (string / 必填) — 所有接口均使用 Bearer Token 进行认证。 获取 API Key：[访问控制台](https://api.oairoute.com/keys) 创建。 请求时在请求头中添加： ```http Authorization: Bearer YOUR_OAIRoute_KEY ```
## 请求参数
- `model` (string / 必填) — 固定填 `omni-moderation-latest`。
- `input` (string / array) — 待审核内容。可以是单个字符串，也可以是字符串数组，或包含图片的多模态内容块数组。
- `input[].type` (string / 可选) — 传多模态内容时必填。取值 `text` 或 `image_url`。
- `input[].image_url.url` (string / 可选) — 图片地址，支持 HTTP(S) 与 Base64 data URI。
## 响应
- `id` (string) — 本次审核请求的唯一标识。
- `model` (string) — 实际使用的审核模型。
- `results` (array) — 审核结果数组，与输入顺序一一对应。
- `results[].flagged` (boolean) — 是否被判定为违规。这是 `categories` 中任一项为 `true` 的汇总结果。
- `results[].categories` (object) — 按类别给出的布尔判定。键名与评分项同名，例如 `hate`、`harassment`、`violence`、`self-harm`、`sexual`。
- `results[].category_scores` (object) — 按类别给出的 0 到 1 评分。数值越高越接近该类内容。
## 怎么用评分
`flagged` 是官方给的汇总判定，但实际业务里往往需要自己调阈值：
| 用途 | 建议 |
|---|---|
| 严格拦截 | 任一评分超过 0.3 就拦 |
| 常规过滤 | 用 `flagged` 的默认结果 |
| 只做提醒 | 评分超过 0.7 才提示，不阻断 |
> **Note:** 
> `category_scores` 不是概率，不要按百分比理解。不同类别之间的数值不可横向比较，只在同一类别内纵向比较。
## 作为生成前置检查
在调用图像生成前先跑一遍审核，能避免任务建了又失败、还占用额度：
```python
def safe_to_generate(prompt: str) -> bool:
    r = requests.post(
        "https://api.oairoute.com/v1/moderations",
        headers={"Authorization": "Bearer YOUR_OAIRoute_KEY"},
        json={"model": "omni-moderation-latest", "input": prompt},
    )
    return not r.json()["results"][0]["flagged"]
```
## 错误码
错误响应的格式、状态码与重试建议见[错误码与限流](../support/errors.html)，常见报错的排查步骤见[常见问题](../support/faq.html)。
## 使用示例
### 检查单条文本
`input` 可以是字符串，返回一个结果对象。`flagged` 为 `true` 表示命中任一类别。
### 批量检查
`input` 传字符串数组，一次返回多条结果，顺序与输入一致。批量比逐条请求快得多。
### 检查图片
图片通过内容块传入，与文本消息结构相同。返回的类别里会多出图像相关的判定。
### 只取最高风险分
实际业务里通常只关心最突出的那一类。取 `category_scores` 的最大值判断即可。
```bash
curl --request POST https://api.oairoute.com/v1/moderations \
  -H "Authorization: Bearer YOUR_OAIRoute_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"omni-moderation-latest","input":"待审核文本"}' \
  | jq '.results[0].category_scores | to_entries | max_by(.value)'
```
**omni-moderation-latest 内容审核{omni-moderation-latest moderation}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/moderations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "omni-moderation-latest",
    "input": "这里放待审核的文本"
  }'
```
**omni-moderation-latest 内容审核{omni-moderation-latest moderation}::Python**
```
import requests
res = requests.post(
    "https://api.oairoute.com/v1/moderations",
    headers={
        "Authorization": "Bearer YOUR_OAIRoute_KEY",
        "Content-Type": "application/json",
    },
    json={
        "model": "omni-moderation-latest",
        "input": "这里放待审核的文本",
    },
)
for item in res.json()["results"]:
    print(item["flagged"], item["category_scores"])
```
**omni-moderation-latest 内容审核{omni-moderation-latest moderation}::JavaScript**
```
const url = "https://api.oairoute.com/v1/moderations";
const options = {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "omni-moderation-latest",
    "input": "这里放待审核的文本"
  }),
};
fetch(url, options)
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch((err) => console.error(err));
```
**200 omni-moderation-latest 内容审核{omni-moderation-latest moderation}**
```
{
  "id": "modr-01KA040M0HP1GJWBJYZMKX1XS1",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "harassment": false,
        "violence": false,
        "self-harm": false,
        "sexual": false
      },
      "category_scores": {
        "hate": 0.0002,
        "harassment": 0.0011,
        "violence": 0.0004,
        "self-harm": 0.0001,
        "sexual": 0.0003
      }
    }
  ]
}
```
**多模态输入{Multimodal input}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/moderations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "omni-moderation-latest",
  "input": [
    { "type": "text", "text": "这张图里有什么" },
    {
      "type": "image_url",
      "image_url": { "url": "https://example.com/photo.jpg" }
    }
  ]
}'
```
**多模态输入{Multimodal input}::Python**
```
import requests
url = "https://api.oairoute.com/v1/moderations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
      "model": "omni-moderation-latest",
      "input": [
        { "type": "text", "text": "这张图里有什么" },
        {
          "type": "image_url",
          "image_url": { "url": "https://example.com/photo.jpg" }
        }
      ]
    }
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**多模态输入{Multimodal input}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/moderations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "omni-moderation-latest",
    "input": [
      { "type": "text", "text": "这张图里有什么" },
      {
        "type": "image_url",
        "image_url": { "url": "https://example.com/photo.jpg" }
      }
    ]
  }),
});
console.log(await res.json());
```
**200 多模态输入{Multimodal input}**
```
{
  "id": "modr-01KA040M0HP1GJWBJYZMKX1XT2",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "harassment": false,
        "violence": false,
        "self-harm": false,
        "sexual": false
      },
      "category_scores": {
        "hate": 0.0001,
        "harassment": 0.0003,
        "violence": 0.0012,
        "self-harm": 0.0001,
        "sexual": 0.0021
      }
    }
  ]
}
```
**检查单条文本{Check single text}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/moderations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "omni-moderation-latest",
    "input": "用户提交的待审核文本"
  }'
```
**检查单条文本{Check single text}::Python**
```
import requests
url = "https://api.oairoute.com/v1/moderations"
headers = {"Authorization": "Bearer YOUR_OAIRoute_KEY"}
payload = {
    "model": "omni-moderation-latest",
    "input": "用户提交的待审核文本"
  }
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**检查单条文本{Check single text}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/moderations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "omni-moderation-latest",
    "input": "用户提交的待审核文本"
  }),
});
console.log(await res.json());
```
**批量检查{Batch check}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/moderations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "omni-moderation-latest",
    "input": ["第一条待审核文本", "第二条待审核文本", "第三条待审核文本"]
  }'
```
**批量检查{Batch check}::Python**
```
import requests
url = "https://api.oairoute.com/v1/moderations"
headers = {"Authorization": "Bearer YOUR_OAIRoute_KEY"}
payload = {
    "model": "omni-moderation-latest",
    "input": ["第一条待审核文本", "第二条待审核文本", "第三条待审核文本"]
  }
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**批量检查{Batch check}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/moderations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "omni-moderation-latest",
    "input": ["第一条待审核文本", "第二条待审核文本", "第三条待审核文本"]
  }),
});
console.log(await res.json());
```
**检查图片{Check image}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/moderations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "omni-moderation-latest",
    "input": [{
      "type": "image_url",
      "image_url": { "url": "https://example.com/photo.jpg" }
    }]
  }'
```
**检查图片{Check image}::Python**
```
import requests
url = "https://api.oairoute.com/v1/moderations"
headers = {"Authorization": "Bearer YOUR_OAIRoute_KEY"}
payload = {
    "model": "omni-moderation-latest",
    "input": [{
      "type": "image_url",
      "image_url": { "url": "https://example.com/photo.jpg" }
    }]
  }
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**检查图片{Check image}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/moderations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "omni-moderation-latest",
    "input": [{
      "type": "image_url",
      "image_url": { "url": "https://example.com/photo.jpg" }
    }]
  }),
});
console.log(await res.json());
```
**200 检查单条文本{Check single text}**
```
{
  "id": "modr-01KA040M0HP1GJWBJYZMKX1XT3",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "harassment": false,
        "violence": false,
        "self-harm": false,
        "sexual": false
      },
      "category_scores": {
        "hate": 0.0004,
        "harassment": 0.0018,
        "violence": 0.0002,
        "self-harm": 0.0001,
        "sexual": 0.0002
      }
    }
  ]
}
```
**200 批量检查{Batch check}**
```
{
  "id": "modr-01KA040M0HP1GJWBJYZMKX1XT4",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "harassment": false,
        "violence": false,
        "self-harm": false,
        "sexual": false
      },
      "category_scores": {
        "hate": 0.0002,
        "harassment": 0.0007,
        "violence": 0.0003,
        "self-harm": 0.0001,
        "sexual": 0.0002
      }
    },
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "harassment": false,
        "violence": false,
        "self-harm": false,
        "sexual": false
      },
      "category_scores": {
        "hate": 0.0003,
        "harassment": 0.0012,
        "violence": 0.0005,
        "self-harm": 0.0001,
        "sexual": 0.0004
      }
    },
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "harassment": false,
        "violence": false,
        "self-harm": false,
        "sexual": false
      },
      "category_scores": {
        "hate": 0.0001,
        "harassment": 0.0006,
        "violence": 0.0002,
        "self-harm": 0.0001,
        "sexual": 0.0001
      }
    }
  ]
}
```
**200 检查图片{Check image}**
```
{
  "id": "modr-01KA040M0HP1GJWBJYZMKX1XT5",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "harassment": false,
        "violence": false,
        "self-harm": false,
        "sexual": false
      },
      "category_scores": {
        "hate": 0.0001,
        "harassment": 0.0002,
        "violence": 0.0009,
        "self-harm": 0.0001,
        "sexual": 0.0017
      }
    }
  ]
}
```
