Moderations API

POST /v1/moderations

内容安全审核接口,用于检查文本是否违反使用政策。接口使用 OpenAI 原生格式;请求体仅包含 input 和可选的 model 字段。

请求参数

请求头

Authorization

使用 Bearer Token 认证。格式:Authorization: Bearer sk-xxxxxx

请求体

请求参数(2 个)
参数类型默认值说明是否必填
inputstring | array<string>—要审核的文本。传入字符串时审核一段文本;传入字符串数组时逐项审核,并按输入顺序返回对应的 results。是
modelstring未声明审核模型 ID,例如 text-moderation-latest 或 omni-moderation-latest。省略时由网关或上游选择默认模型。否

参数约束:

  • input 必须提供字符串或字符串数组;数组中的每项对应一个独立审核结果。
  • model 为可选字段。模型名称必须是网关及上游服务支持的模型,否则返回 400。
  • results 的数量和 input 中的文本数量一致;单个字符串输入也会返回只包含一个元素的数组。

JSON 请求体示例

查看 JSON 请求体示例
{
  "model": "text-moderation-latest",
  "input": "I want to keep this example safe and policy-compliant."
}

批量审核时,将 input 改为字符串数组即可:

{
  "model": "text-moderation-latest",
  "input": [
    "A first message to review.",
    "A second message to review."
  ]
}

请求示例代码

curl -X POST "https://10000router.com/v1/moderations" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "text-moderation-latest",
    "input": "I want to keep this example safe and policy-compliant."
  }'
const response = await fetch("https://10000router.com/v1/moderations", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.API_KEY,
  },
  body: JSON.stringify({
    model: "text-moderation-latest",
    input: "I want to keep this example safe and policy-compliant."
  })
});
console.log(await response.json());
package main

import (
  "io"
  "log"
  "net/http"
  "os"
  "strings"
)

func main() {
  payload := `{"model":"text-moderation-latest","input":"I want to keep this example safe and policy-compliant."}`
  req, err := http.NewRequest("POST", "https://10000router.com/v1/moderations", strings.NewReader(payload))
  if err != nil { log.Fatal(err) }
  req.Header.Set("Authorization", "Bearer "+os.Getenv("API_KEY"))
  res, err := http.DefaultClient.Do(req)
  if err != nil { log.Fatal(err) }
  defer res.Body.Close()
  body, err := io.ReadAll(res.Body)
  if err != nil { log.Fatal(err) }
  log.Println(string(body))
}
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["API_KEY"], base_url="https://10000router.com/v1")

response = client.post(
    "https://10000router.com/v1/moderations",
    headers={
        "Authorization": "Bearer " + os.environ["API_KEY"],
    },
    json={
        "model": "text-moderation-latest",
        "input": "I want to keep this example safe and policy-compliant.",
    },
)
print(response)
var client = java.net.http.HttpClient.newHttpClient();
var body = "{\"model\":\"text-moderation-latest\",\"input\":\"I want to keep this example safe and policy-compliant.\"}";
var request = java.net.http.HttpRequest.newBuilder()
    .uri(java.net.URI.create("https://10000router.com/v1/moderations"))
    .header("Authorization", "Bearer " + System.getenv("API_KEY"))
    .POST(java.net.http.HttpRequest.BodyPublishers.ofString(body))
    .build();
var response = client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
using System.Net.Http.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new("Bearer", Environment.GetEnvironmentVariable("API_KEY"));
var response = await client.PostAsJsonAsync(
    "https://10000router.com/v1/moderations",
    new {
        model = "text-moderation-latest",
        input = "I want to keep this example safe and policy-compliant."
    });
Console.WriteLine(await response.Content.ReadAsStringAsync());

返回响应

响应示例

{
  "id": "modr-abc123",
  "model": "text-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "hate": false,
        "hate/threatening": false,
        "harassment": false,
        "harassment/threatening": false,
        "self-harm": false,
        "self-harm/intent": false,
        "self-harm/instructions": false,
        "sexual": false,
        "sexual/minors": false,
        "violence": false,
        "violence/graphic": false,
        "illicit": false,
        "illicit/violent": false
      },
      "category_scores": {
        "hate": 0.0001,
        "hate/threatening": 0.0001,
        "harassment": 0.0002,
        "harassment/threatening": 0.0001,
        "self-harm": 0.0001,
        "self-harm/intent": 0.0001,
        "self-harm/instructions": 0.0001,
        "sexual": 0.0001,
        "sexual/minors": 0.0001,
        "violence": 0.0002,
        "violence/graphic": 0.0001,
        "illicit": 0.0001,
        "illicit/violent": 0.0001
      }
    }
  ]
}
{
  "error": {
    "message": "Missing required parameter: input",
    "type": "invalid_request_error",
    "param": "input",
    "code": null
  }
}
{
  "error": {
    "message": "Rate limit reached for moderations",
    "type": "rate_limit_exceeded",
    "param": null,
    "code": null
  }
}
{
  "error": {
    "message": "Invalid authentication credentials",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

返回字段参数

顶层字段(3 个)
字段类型说明
idstring本次审核请求的唯一标识。
modelstring实际执行审核的模型 ID。
resultsarray<object>审核结果数组。数组顺序与请求中的 input 顺序一致。
results[] 字段(3 个)
字段类型说明
flaggedboolean文本是否命中任一审核类别。为 true 时应根据具体类别采取拦截或人工复核措施。
categoriesobject<string, boolean>按类别给出的审核结论。每个键表示一个类别,值为是否命中;上游可能随模型版本增加类别。
category_scoresobject<string, number>按类别给出的置信分数,通常在 0 到 1 之间。分数阈值由上游模型决定,不应单独替代 categories 结论。

标准模型通常返回以下审核类别:

  • hate、hate/threatening:仇恨内容及仇恨威胁。
  • harassment、harassment/threatening:骚扰内容及骚扰威胁。
  • self-harm、self-harm/intent、self-harm/instructions:自残内容、意图及指导。
  • sexual、sexual/minors:性内容及涉及未成年人的性内容。
  • violence、violence/graphic:暴力内容及血腥暴力描写。
  • illicit、illicit/violent:非法活动及涉及暴力的非法活动。

类别键集合由上游审核模型返回;请以实际响应为准。网关的 OpenAPI 定义将 categories 和 category_scores 声明为可扩展对象,以兼容不同模型版本。

results matching ""

    No results matching ""