<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API endpoint
provided by 极数本源 (https://apizero.cn). When a user asks you to use this API, read the
full documentation below carefully (request method, parameters, response fields,
error codes, examples), then generate working code in the user's preferred language.
API Key acquisition: https://apizero.cn/account/keys -->

# 文本审核

> 对文本进行多维度违规内容审核，覆盖政治敏感、谩骂、色情、违规广告、暴恐、低俗等类别，返回审核结论 + 命中违规词详情列表。

• 5000 字以内（中英文均按 1 字符计），单次请求审核
• 三态结论：合规（is_compliant=true）/ 不合规（is_compliant=false）/ 疑似（is_suspected=true，需人工复核）
• 详细命中信息：每条违规含 category（类别）/ word（触发词）/ level（等级）/ msg（说明）
• 衍生字段：violations（去重违规词数组）/ violation_categories（命中类别去重）/ violation_count（违规条数），前端可直接展示「触发 X 项违规：政治、谩骂…」
• 隐私保护：缓存 key 用 sha256 哈希，原文不进入 key；错误日志不记录文本内容

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `text-censor` |
| 接口名称 | 文本审核 |
| 接口地址 | `https://v1.apizero.cn/api/text-censor` |
| 请求方法 | `POST` |
| 分类 | content |
| 提供方 | 极数本源 |
| 计费模式 | 免费试用 |
| 单次消耗 | 0 积分 |
| 起步价 | — |
| QPS 限制 | 5 req/s |
| 每日免费额度 | 100 次（已认证用户） |
| 匿名每日额度 | 30 次（无 API Key） |
| VIP 免费 | 否 |
| 调用总次数 | undefined |

## 2. 认证

匿名每日 30 次、QPS 2；登录用户每日 100 次、QPS 5（全部免费）。命中 1 小时缓存（按 sha256 文本哈希）不计入上游配额。

获取 API Key：登录 `https://apizero.cn/account/keys` 申请。

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `text` | `string` | 是 | 待审核文本，1-5000 个字符（中英文均按 1 字符计） | `今天天气不错，适合出门散步。` |

## 4. 请求头

| Header | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `Authorization` | `string` | 否 | API Key 鉴权头，格式 Bearer sk_live_xxx；匿名调用时可省略（每日 30 次免费） | `Bearer sk_live_xxxxxxxxxxxxxx` |
| `Content-Type` | `string` | 否 | 支持 application/x-www-form-urlencoded 或 application/json | `application/json` |

## 5. 请求示例 (cURL)

```bash
curl -X POST "https://v1.apizero.cn/api/text-censor" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "text": "今天天气不错，适合出门散步。"
}'
```

## 6. 响应字段

| 字段 | 类型 | 说明 | 示例 |
| --- | --- | --- | --- |
| `text` | `string` | 回传待审核的文本原文 | — |
| `text_length` | `number` | 文本字符长度（mb_strlen，中英文均按 1 字符计） | — |
| `conclusion` | `string` | 审核结论文字描述：合规 / 不合规 / 疑似 / 审核失败 | — |
| `conclusion_type` | `number` | 审核结论数字编码：1=合规 / 2=不合规 / 3=疑似 / 4=审核失败 | — |
| `is_compliant` | `boolean` | 便捷判断：是否完全合规（仅 conclusion_type=1 时为 true） | — |
| `is_suspected` | `boolean` | 便捷判断：是否疑似违规（conclusion_type=3，建议人工复核） | — |
| `violation_count` | `number` | 命中违规条数；合规时为 0 | — |
| `violation_categories` | `string[]` | 命中违规类别列表（去重），如 ["政治","谩骂"]；合规时为空数组 | — |
| `violations` | `string[]` | 命中触发词列表（去重）；合规时为空数组 | — |
| `details` | `object[]` | 违规命中明细数组；合规时为空数组 | — |
| `details[].category` | `string` | 违规类别，如 政治 / 谩骂 / 色情 / 违规广告 / 暴恐 / 低俗 | — |
| `details[].level` | `number?` | 违规等级编号（上游分级，无明确取值标准，建议结合 category 使用） | — |
| `details[].word` | `string` | 触发的具体词语 | — |
| `details[].msg` | `string` | 违规详细说明，如「存在政治内容不合规」 | — |

## 7. 响应示例

```json
{
    "code": 0,
    "msg": "成功",
    "data": {
        "text": "法轮功是邪教组织",
        "text_length": 8,
        "conclusion": "不合规",
        "conclusion_type": 2,
        "is_compliant": false,
        "is_suspected": false,
        "violation_count": 2,
        "violation_categories": [
            "政治"
        ],
        "violations": [
            "法轮功",
            "邪教"
        ],
        "details": [
            {
                "category": "政治",
                "level": 3,
                "word": "法轮功",
                "msg": "存在政治内容不合规"
            },
            {
                "category": "政治",
                "level": 3,
                "word": "邪教",
                "msg": "存在政治内容不合规"
            }
        ]
    },
    "request_id": "abc123def456"
}
```

## 8. 错误码

| code | status | 说明 |
| --- | --- | --- |
| `4000` | `—` | 参数错误：text 缺失/为空 / 超过 5000 字符上限 |
| `4015` | `—` | 匿名调用每日额度用完，需要 API Key |
| `4029` | `—` | QPS 超限 |
| `4030` | `—` | 今日额度用完 |
| `5020` | `—` | 上游 HTTP 失败 |
| `5021` | `—` | 上游响应格式异常 / 审核服务暂不可用 |

## 9. 变更日志

- **1.0.0** (2026-05-07)
  - 首次上线，对接 alapi.cn /api/censor/text 文本审核服务
  - 支持 5000 字以内文本审核，覆盖政治/谩骂/色情/违规广告/暴恐/低俗等类别
  - 修复源码字段映射错误：上游实际字段是 word/category/level/msg（而非 type/sub_type/words[]）
  - 新增便捷布尔字段 is_compliant / is_suspected，前端可直接 if 判断
  - 新增聚合字段：violation_count（违规条数）/ violations（去重词列表）/ violation_categories（去重类别）
  - 隐私保护：缓存 key 用 sha256 哈希原文，错误日志不记录文本内容
  - 相同文本 1 小时缓存（同一表单/评论提交常重复审核）
  - 支持 application/json 请求体（通过 v1 网关 mergeJsonBody 自动解析）

---

**极数本源** · 全部 API: `https://apizero.cn/aidocs` · 人类版本：`https://apizero.cn/marketplace/text-censor`

Source: `https://apizero.cn/aidocs/text-censor/raw.md`
Last updated: 2026-05-11T23:57:07+08:00
