omni-moderation-latest 内容审核
- 判断一段文本或图片是否属于敏感内容
- 按类别分别给出评分,便于自行设阈值
- 可以作为生成前的守门员,也可以独立使用
认证
All endpoints authenticate with a Bearer token.
Get an API key: open the console and create one.
Add it to the request header:
Authorization: Bearer YOUR_OAIRoute_KEY请求参数
固定填 omni-moderation-latest。
待审核内容。可以是单个字符串,也可以是字符串数组,或包含图片的多模态内容块数组。
传多模态内容时必填。取值 text 或 image_url。
图片地址,支持 HTTP(S) 与 Base64 data URI。
Always omni-moderation-latest.
The content to moderate. Can be a single string, an array of strings, or an array of multimodal content blocks including images.
Required when passing multimodal content. Either text or image_url.
The image URL; supports HTTP(S) and Base64 data URIs.
响应
本次审核请求的唯一标识。
实际使用的审核模型。
审核结果数组,与输入顺序一一对应。
是否被判定为违规。这是 categories 中任一项为 true 的汇总结果。
按类别给出的布尔判定。键名与评分项同名,例如 hate、harassment、violence、self-harm、sexual。
按类别给出的 0 到 1 评分。数值越高越接近该类内容。
A unique identifier for this moderation request.
The moderation model actually used.
The array of moderation results, in the same order as the input.
Whether the content was found to violate policy. This is the aggregate of any categories entry being true.
Boolean verdicts by category, keyed the same as the score items — e.g. hate, harassment, violence, self-harm, sexual.
Scores from 0 to 1 by category. Higher means closer to that kind of content.
怎么用评分
flagged 是官方给的汇总判定,但实际业务里往往需要自己调阈值:
| 用途 | 建议 |
|---|---|
| 严格拦截 | 任一评分超过 0.3 就拦 |
| 常规过滤 | 用 flagged 的默认结果 |
| 只做提醒 | 评分超过 0.7 才提示,不阻断 |
category_scores 不是概率,不要按百分比理解。不同类别之间的数值不可横向比较,只在同一类别内纵向比较。
flagged is the official aggregate verdict, but real applications usually need to tune thresholds themselves:
| Use | Recommendation |
|---|---|
| Strict blocking | Block if any score exceeds 0.3 |
| Normal filtering | Use the default flagged result |
| Warning only | Prompt above 0.7 without blocking |
category_scores aren't probabilities; don't read them as percentages. Values aren't comparable across categories, only within one.
作为生成前置检查
在调用图像生成前先跑一遍审核,能避免任务建了又失败、还占用额度:
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"]Running moderation before calling image generation avoids creating tasks that fail and consume balance:
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"]错误码
For error response formats, status codes, and retry guidance see Error codes and rate limits; for troubleshooting steps on common errors see the FAQ.
使用示例
检查单条文本
input 可以是字符串,返回一个结果对象。flagged 为 true 表示命中任一类别。
批量检查
input 传字符串数组,一次返回多条结果,顺序与输入一致。批量比逐条请求快得多。
检查图片
图片通过内容块传入,与文本消息结构相同。返回的类别里会多出图像相关的判定。
只取最高风险分
实际业务里通常只关心最突出的那一类。取 category_scores 的最大值判断即可。
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)'Check a single piece of text
input can be a string, returning one result object. flagged being true means any category matched.
Batch check
Pass an array of strings to input and get several results back at once, in input order. Batching is much faster than one request per item.
Check an image
Images go in as content blocks, structured like text messages. The returned categories include image-specific verdicts.
Take only the highest risk score
In practice you usually care only about the most prominent category. Take the maximum of category_scores.
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":"Text to moderate"}' \
| jq '.results[0].category_scores | to_entries | max_by(.value)'