> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Moderation API：用 omni-moderation-latest 审核文本

> 用 omni-moderation-latest 审核文本：老张API /v1/moderations 的 cURL 与 Python 示例、响应示例，以及读取 flagged 和 categories 的方法。

Moderation API 用 `omni-moderation-latest` 判断文本是否违规，请求与响应格式与 OpenAI Moderation API 相同。

| 项目 | 内容 |
| - | - |
| 端点 | `POST https://api.laozhang.ai/v1/moderations` |
| 请求字段 | `model` 和 `input` |
| 是否违规 | `results[0].flagged` |
| 命中类别 | `results[0].categories` 列出每个类别是否命中 |
| 价格 | 2026 年 9 月 24 日公开价格配置：`omni-moderation-latest` 与 `omni-moderation-2024-09-26` 的输入价格为 \$0.2 / 1M tokens，以[模型与价格总表](/models)为准 |

## 发送审核请求

在[令牌管理](https://api.laozhang.ai/token)创建 API Key，写入环境变量；使用 Python 示例时，先执行 `python -m pip install openai`。

```bash theme={null}
export LAOZHANG_API_KEY="替换为你的老张API密钥"
```

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl --fail-with-body --max-time 60 \
      "https://api.laozhang.ai/v1/moderations" \
      -H "Authorization: Bearer $LAOZHANG_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "omni-moderation-latest",
        "input": "今天天气不错，我们去公园散步吧。"
      }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import os
    from openai import OpenAI

    client = OpenAI(
        api_key=os.environ["LAOZHANG_API_KEY"],
        base_url="https://api.laozhang.ai/v1",
        timeout=60.0,
        max_retries=0,
    )
    response = client.moderations.create(
        model="omni-moderation-latest",
        input="今天天气不错，我们去公园散步吧。",
    )
    result = response.results[0]
    hits = [name for name, hit in result.categories.to_dict().items() if hit]
    print("是否违规：", result.flagged)
    print("命中类别：", "、".join(hits) if hits else "无")
    ```
  </Tab>
</Tabs>

## 读取审核结果

上面的普通文本会得到类似下面的响应（省略了 `id` 等字段）：

```json theme={null}
{
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "sexual": false,
        "sexual/minors": false,
        "harassment": false,
        "harassment/threatening": false,
        "hate": false,
        "hate/threatening": false,
        "illicit": false,
        "illicit/violent": false,
        "self-harm": false,
        "self-harm/intent": false,
        "self-harm/instructions": false,
        "violence": false,
        "violence/graphic": false
      }
    }
  ]
}
```

* `results[0].flagged`：`true` 表示至少命中一个类别，`false` 表示没有命中。
* `results[0].categories`：每个类别对应一个布尔值，值为 `true` 的键就是命中的类别，例如 `violence`。

Python 示例把 `categories` 中值为 `true` 的键收集到 `hits`，可以据此决定拦截、转人工或放行。各类别的含义见 [OpenAI 审核指南](https://developers.openai.com/api/docs/guides/moderation)。

审核结果是风险信号，模型可能误报或漏报；封禁账号、删除内容等重要处理，请保留人工复核。

## 相关文档

* [OpenAI Moderations 接口参考](https://developers.openai.com/api/reference/resources/moderations/methods/create)
* [内容安全、禁止用途与用户责任](/faq/content-safety)
* [数据与日志边界](/faq/data-security)
* [老张API数据政策](https://www.laozhang.ai/zh-cn/data-policy)
* [模型与价格总表](/models)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.