codecamp

OpenAI API 审核

使用 OpenAI 审核模型检测文本与图像中的有害内容。既可通过审核端点单独分类输入,也可在生成响应时一并请求审核分数。根据结果执行应用自身的政策,例如过滤内容、送交人工审查,或对提交被标记内容的账户采取干预措施。

omni-moderation-latest 接受文本和图像输入,不分类音频。审核端点免费使用,图像文件最大 20 MB。

儿童安全:不要向 Moderation API 发送已知或疑似儿童性虐待材料(CSAM)。该 API 不用于 CSAM 检测或处置,也不能替代专门的儿童安全保护措施。防范、检测、响应和报告方法见 CSAM 指南。

选择审核工作流

工作流 适用场景
审核生成内容 应用通过 Responses API 或 Chat Completions API 生成文本,同时需要审核信号。
单独分类输入 应用需要分类文本或图像,而不生成模型响应。
理解审核结果 应用需要解释标记、类别、分数或适用的输入类型。
查看支持的类别 应用需要知道各有害内容类别支持文本、图像还是两者。

审核生成内容

需要同时生成文本并获得审核分数时,在生成请求中传入顶层 moderation 对象。API 会返回模型输入和生成输出的审核分数,不必另发审核请求。

模型仍会正常生成内容。在向用户展示输出或执行下游操作前,应先检查审核结果。创建响应时设置 moderation.model:

来源示例 1(javascript):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import OpenAI from "openai";

const client = new OpenAI();

const response = await client.responses.create({
  model: "gpt-6-astra",
  input: [
    {
      role: "user",
      content:
        "A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative.",
    },
  ],
  moderation: { model: "omni-moderation-latest" },
});

const inputModeration = response.moderation.input;
const outputModeration = response.moderation.output;
if (inputModeration.type === "error") {
  throw new Error(inputModeration.message);
}
if (outputModeration.type === "error") {
  throw new Error(outputModeration.message);
}

console.log(inputModeration.flagged);
console.log(outputModeration.flagged);

来源示例 2(python):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-6-astra",
    input=[
        {
            "role": "user",
            "content": (
                "A user asks for instructions to make a harmful weapon. "
                "Draft a brief refusal and offer a safer alternative."
            ),
        }
    ],
    moderation={"model": "omni-moderation-latest"},
)

input_moderation = response.moderation.input
output_moderation = response.moderation.output
if input_moderation.type == "error":
    raise RuntimeError(input_moderation.message)
if output_moderation.type == "error":
    raise RuntimeError(output_moderation.message)

print(input_moderation.flagged)
print(output_moderation.flagged)

来源示例 3(go):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
package main

import (
    "context"
    "errors"
    "fmt"

    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/responses"
)

func main() {
    client := openai.NewClient()

    response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
        Model: "gpt-6-astra",
        Input: responses.ResponseNewParamsInputUnion{
            OfString: openai.String("A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative."),
        },
        Moderation: responses.ResponseNewParamsModeration{
            Model: "omni-moderation-latest",
        },
    })
    if err != nil {
        panic(err)
    }

    switch inputModeration := response.Moderation.Input.AsAny().(type) {
    case responses.ResponseModerationInputModerationResult:
        fmt.Println(inputModeration.Flagged)
    case responses.ResponseModerationInputError:
        panic(errors.New(inputModeration.Message))
    default:
        panic("unexpected input moderation result")
    }
    switch outputModeration := response.Moderation.Output.AsAny().(type) {
    case responses.ResponseModerationOutputModerationResult:
        fmt.Println(outputModeration.Flagged)
    case responses.ResponseModerationOutputError:
        panic(errors.New(outputModeration.Message))
    default:
        panic("unexpected output moderation result")
    }
}

来源示例 4(java):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.responses.ResponseCreateParams;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

ResponseCreateParams params =
    ResponseCreateParams.builder()
        .model("gpt-6-astra")
        .input(
            "A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative.")
        .putAdditionalBodyProperty(
            "moderation", JsonValue.from(Map.of("model", "omni-moderation-latest")))
        .build();

var response = client.responses().create(params);
var moderation =
    response
        .moderation()
        .orElseThrow(
            () -> new IllegalStateException("The response did not include moderation results"));
List<Boolean> flags = new ArrayList<>();

var input = moderation.input();
if (input.isError()) {
  throw new IllegalStateException(input.asError().message());
}
if (!input.isModerationResult()) {
  throw new IllegalStateException("Missing input moderation flag");
}
flags.add(input.asModerationResult().flagged());

var output = moderation.output();
if (output.isError()) {
  throw new IllegalStateException(output.asError().message());
}
if (!output.isModerationResult()) {
  throw new IllegalStateException("Missing output moderation flag");
}
flags.add(output.asModerationResult().flagged());

flags.forEach(System.out::println);

来源示例 5(ruby):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
require "openai"

client = OpenAI::Client.new

response = client.responses.create(
  model: "gpt-6-astra",
  input: "A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative.",
  moderation: { model: "omni-moderation-latest" }
)

puts(response.moderation)

Responses API 的输入 moderation_result 位于 response.moderation.input,输出结果位于 response.moderation.output。

同页 Chat Completions 版本:

来源示例 21(javascript):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import OpenAI from "openai";

const client = new OpenAI();

const completion = await client.chat.completions.create({
  model: "gpt-6-astra",
  messages: [
    {
      role: "user",
      content:
        "A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative.",
    },
  ],
  moderation: { model: "omni-moderation-latest" },
});

const inputResult = completion.moderation.input;
const outputResult = completion.moderation.output;
if (inputResult.type === "error") throw new Error(inputResult.message);
if (outputResult.type === "error") throw new Error(outputResult.message);

const inputModeration = inputResult.results[0];
const outputModeration = outputResult.results[0];

console.log(inputModeration.flagged);
console.log(outputModeration.flagged);

来源示例 22(python):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
from openai import OpenAI

client = OpenAI()

completion = client.chat.completions.create(
    model="gpt-6-astra",
    messages=[
        {
            "role": "user",
            "content": (
                "A user asks for instructions to make a harmful weapon. "
                "Draft a brief refusal and offer a safer alternative."
            ),
        }
    ],
    moderation={"model": "omni-moderation-latest"},
)

input_result = completion.moderation.input
output_result = completion.moderation.output
if input_result.type == "error":
    raise RuntimeError(input_result.message)
if output_result.type == "error":
    raise RuntimeError(output_result.message)

input_moderation = input_result.results[0]
output_moderation = output_result.results[0]

print(input_moderation.flagged)
print(output_moderation.flagged)

来源示例 23(go):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
package main

import (
    "context"
    "errors"
    "fmt"

    "github.com/openai/openai-go/v3"
)

func main() {
    client := openai.NewClient()

    completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
        Model: "gpt-6-astra",
        Messages: []openai.ChatCompletionMessageParamUnion{
            openai.UserMessage("A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative."),
        },
        Moderation: openai.ChatCompletionNewParamsModeration{
            Model: "omni-moderation-latest",
        },
    })
    if err != nil {
        panic(err)
    }

    switch inputResult := completion.Moderation.Input.AsAny().(type) {
    case openai.ChatCompletionModerationInputModerationResults:
        if len(inputResult.Results) == 0 {
            panic("missing input moderation result")
        }
        fmt.Println(inputResult.Results[0].Flagged)
    case openai.ChatCompletionModerationInputError:
        panic(errors.New(inputResult.Message))
    default:
        panic("unexpected input moderation result")
    }
    switch outputResult := completion.Moderation.Output.AsAny().(type) {
    case openai.ChatCompletionModerationOutputModerationResults:
        if len(outputResult.Results) == 0 {
            panic("missing output moderation result")
        }
        fmt.Println(outputResult.Results[0].Flagged)
    case openai.ChatCompletionModerationOutputError:
        panic(errors.New(outputResult.Message))
    default:
        panic("unexpected output moderation result")
    }
}

来源示例 24(java):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

ChatCompletionCreateParams params =
    ChatCompletionCreateParams.builder()
        .model("gpt-6-astra")
        .addUserMessage(
            "A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative.")
        .putAdditionalBodyProperty(
            "moderation", JsonValue.from(Map.of("model", "omni-moderation-latest")))
        .build();

var completion = client.chat().completions().create(params);
var moderation =
    completion
        .moderation()
        .orElseThrow(
            () ->
                new IllegalStateException("The completion did not include moderation results"));
List<Boolean> flags = new ArrayList<>();

var input = moderation.input();
if (input.isError()) {
  throw new IllegalStateException(input.asError().message());
}
if (!input.isModerationResults() || input.asModerationResults().results().isEmpty()) {
  throw new IllegalStateException("Missing input moderation flag");
}
flags.add(input.asModerationResults().results().get(0).flagged());

var output = moderation.output();
if (output.isError()) {
  throw new IllegalStateException(output.asError().message());
}
if (!output.isModerationResults() || output.asModerationResults().results().isEmpty()) {
  throw new IllegalStateException("Missing output moderation flag");
}
flags.add(output.asModerationResults().results().get(0).flagged());

flags.forEach(System.out::println);

来源示例 25(ruby):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
require "openai"

client = OpenAI::Client.new

completion = client.chat.completions.create(
  model: "gpt-6-astra",
  messages: [
    {
      role: :user,
      content: "A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative."
    }
  ],
  moderation: { model: "omni-moderation-latest" }
)

puts(completion.moderation)

Chat Completions 在 completion.moderation.input 和 completion.moderation.output 中返回审核结果容器。只生成一个候选时,分别读取输入和输出容器的 results[0];生成多个候选时,completion.moderation.output.results[i] 与 completion.choices[i] 一一对应。

内联审核与独立审核使用相同的类别字段。可先用 flagged 做初步判断,再检查 categories、category_scores,用于日志、路由、审计记录和人工审查队列。拒绝回答等具有安全意识的响应,如果讨论了有害内容,也可能被标记。因此分数是应用政策的判断信号,不应直接等同于自动封禁决定。

需要处理审核失败时,读取分数前先检查结果类型。审核未能完成时,相应的输入或输出字段可能包含错误,而非分数。

工具调用请求中,作为对话内容出现的工具调用参数与工具输出会被审核;工具名称、说明、工具 schema 和响应格式 schema 不在其覆盖范围内。

流式生成时,只有完整生成输出可用后才会返回审核分数,部分输出增量不包含审核分数。

单独分类输入

通过审核端点分类文本或图像,无须生成模型响应。下面展示 OpenAI 客户端库与 omni-moderation-latest 的用法。

获取文本输入的分类信息:

来源示例 6(javascript):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import OpenAI from "openai";
const openai = new OpenAI();

const moderation = await openai.moderations.create({
  model: "omni-moderation-latest",
  input: "...text to classify goes here...",
});

console.log(moderation);

来源示例 7(python):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
from openai import OpenAI

client = OpenAI()

response = client.moderations.create(
    model="omni-moderation-latest",
    input="...text to classify goes here...",
)

print(response)

来源示例 8(go):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go/v3"
)

func main() {
    client := openai.NewClient()

    moderation, err := client.Moderations.New(context.Background(), openai.ModerationNewParams{
        Model: openai.ModerationModelOmniModerationLatest,
        Input: openai.ModerationNewParamsInputUnion{
            OfString: openai.String("Text to classify goes here."),
        },
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(moderation.Results[0].Flagged)
}

来源示例 9(java):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.moderations.ModerationCreateParams;

var moderation =
    client
        .moderations()
        .create(
            ModerationCreateParams.builder()
                .model("omni-moderation-latest")
                .input("Text to classify goes here.")
                .build());

System.out.println(moderation.results().get(0).flagged());

来源示例 10(csharp):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
using OpenAI.Moderations;

string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "omni-moderation-latest";
ModerationClient client = new(model, key);

ModerationResult result = await client.ClassifyTextAsync(
    "Text to classify goes here."
);

Console.WriteLine($"Flagged: {result.Flagged}");
Console.WriteLine(
    $"Violence: {result.Violence.Flagged}; score: {result.Violence.Score:F3}"
);

来源示例 11(ruby):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
require "openai"

client = OpenAI::Client.new

moderation = client.moderations.create(
  model: OpenAI::Models::ModerationModel::OMNI_MODERATION_LATEST,
  input: "Text to classify goes here."
)

puts(moderation.results.fetch(0).flagged)

来源示例 12(bash):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
curl https://api.openai.com/v1/moderations \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": "...text to classify goes here..."
  }'

获取图像和文本输入的分类信息:

来源示例 13(javascript):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import OpenAI from "openai";
const openai = new OpenAI();

const moderation = await openai.moderations.create({
  model: "omni-moderation-latest",
  input: [
    { type: "text", text: "...text to classify goes here..." },
    {
      type: "image_url",
      image_url: {
        url: "https://example.com/image.png",
        // You can also use a Base64 encoded image URL.
        // url: "data:image/jpeg;base64,abcdefg...",
      },
    },
  ],
});

console.log(moderation);

来源示例 14(python):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
from openai import OpenAI

client = OpenAI()

response = client.moderations.create(
    model="omni-moderation-latest",
    input=[
        {"type": "text", "text": "...text to classify goes here..."},
        {
            "type": "image_url",
            "image_url": {
                "url": "https://example.com/image.png",
                # You can also use a Base64 encoded image URL.
                # "url": "data:image/jpeg;base64,abcdefg..."
            },
        },
    ],
)

print(response)

来源示例 15(go):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go/v3"
)

func main() {
    client := openai.NewClient()

    moderation, err := client.Moderations.New(context.Background(), openai.ModerationNewParams{
        Model: openai.ModerationModelOmniModerationLatest,
        Input: openai.ModerationNewParamsInputUnion{
            OfModerationMultiModalArray: []openai.ModerationMultiModalInputUnionParam{
                openai.ModerationMultiModalInputParamOfText("Text to classify goes here."),
                openai.ModerationMultiModalInputParamOfImageURL(openai.ModerationImageURLInputImageURLParam{
                    URL: "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg",
                }),
            },
        },
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(moderation.Results[0].Flagged)
}

来源示例 16(java):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.moderations.ModerationCreateParams;
import com.openai.models.moderations.ModerationImageUrlInput;
import com.openai.models.moderations.ModerationMultiModalInput;
import com.openai.models.moderations.ModerationTextInput;
import java.util.List;

var moderation =
    client
        .moderations()
        .create(
            ModerationCreateParams.builder()
                .model("omni-moderation-latest")
                .inputOfModerationMultiModalArray(
                    List.of(
                        ModerationMultiModalInput.ofText(
                            ModerationTextInput.builder()
                                .text("Text to classify goes here.")
                                .build()),
                        ModerationMultiModalInput.ofImageUrl(
                            ModerationImageUrlInput.builder()
                                .imageUrl(
                                    ModerationImageUrlInput.ImageUrl.builder()
                                        .url(
                                            "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg")
                                        .build())
                                .build())))
                .build());

System.out.println(moderation.results().get(0).flagged());

来源示例 17(csharp):

// [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
using OpenAI.Moderations;
#pragma warning disable OPENAI001

string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "omni-moderation-latest";
ModerationClient client = new(model, key);

ModerationResult result = await client.ClassifyInputsAsync(
    [
        ModerationInputPart.CreateTextPart("Text to classify goes here."),
        ModerationInputPart.CreateImagePart(
            new Uri(
                "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg"
            )
        ),
    ]
);

Console.WriteLine($"Flagged: {result.Flagged}");
Console.WriteLine(
    $"Violence: {result.Violence.Flagged}; score: {result.Violence.Score:F3}; inputs: {result.Violence.ApplicableInputKinds}"
);

来源示例 18(ruby):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
require "openai"

client = OpenAI::Client.new

moderation = client.moderations.create(
  model: OpenAI::Models::ModerationModel::OMNI_MODERATION_LATEST,
  input: [
    {
      type: :text,
      text: "Text to classify goes here."
    },
    {
      type: :image_url,
      image_url: {
        url: "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg"
      }
    }
  ]
)

puts(moderation.results.fetch(0).flagged)

来源示例 19(bash):

## [中文] 请求审核信号并读取分类结果;生成内容须等审核完成再决定展示或行动。图像最大20 MB,不发送已知或疑似CSAM。
curl https://api.openai.com/v1/moderations \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": [
      { "type": "text", "text": "...text to classify goes here..." },
      {
        "type": "image_url",
        "image_url": {
          "url": "https://example.com/image.png"
        }
      }
    ]
  }'

理解审核结果

下例是战争电影单帧图像的完整输出。模型在图像中识别出暴力迹象,violence 分数大于 0.8。

来源示例 20(json):

中文说明:示例图像含战争电影暴力迹象,violence分数大于0.8;分类分数不是直接封禁指令。

{
  "id": "modr-970d409ef3bef3b70c73d8232df86e7d",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": true,
      "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": true,
        "violence/graphic": false
      },
      "category_scores": {
        "sexual": 2.34135824776394e-7,
        "sexual/minors": 1.6346470245419304e-7,
        "harassment": 0.0011643905680426018,
        "harassment/threatening": 0.0022121340080906377,
        "hate": 3.1999824407395835e-7,
        "hate/threatening": 2.4923252458203563e-7,
        "illicit": 0.0005227032493135171,
        "illicit/violent": 3.682979260160596e-7,
        "self-harm": 0.0011175734280627694,
        "self-harm/intent": 0.0006264858507989037,
        "self-harm/instructions": 7.368592981140821e-8,
        "violence": 0.8599265510337075,
        "violence/graphic": 0.37701736389561064
      },
      "category_applied_input_types": {
        "sexual": ["image"],
        "sexual/minors": [],
        "harassment": [],
        "harassment/threatening": [],
        "hate": [],
        "hate/threatening": [],
        "illicit": [],
        "illicit/violent": [],
        "self-harm": ["image"],
        "self-harm/intent": ["image"],
        "self-harm/instructions": ["image"],
        "violence": ["image"],
        "violence/graphic": ["image"]
      }
    }
  ]
}

JSON 字段表示输入包含哪些类别,以及模型对各类别的置信程度。

输出字段 说明
flagged 模型将内容分类为潜在有害时为 true,否则为 false。
categories 各类别违规标记的字典。对应类别被标记违规为 true,否则为 false。
category_scores 各类别分数字典,表示输入包含该类内容的置信度,范围 0—1,越高表示越有把握。
category_applied_input_types 类别分数适用的输入类型。例如暴力血腥类别同时适用图像与文本时,violence/graphic 的值为 ["image", "text"]。

OpenAI 计划持续升级审核端点的底层模型,因此依赖 category_scores 的自定义政策可能需要随时间重新校准。

查看支持的类别

下表列出可检测的内容类别及各自支持的输入类型。标为“仅文本”的类别不支持图像输入。若只向 omni-moderation-latest 发送图像、不附带文本,这些不支持图像的类别会返回 0 分;这不表示图像已经通过相应类别的检测。图像大小上限为 20 MB。

类别 说明 输入
harassment 表达、煽动或宣扬针对任何对象的骚扰性言论。 仅文本
harassment/threatening 骚扰内容中还包含针对任何对象的暴力或严重伤害。 仅文本
hate 基于种族、性别、族裔、宗教、国籍、性取向、残障或种姓表达、煽动或宣扬仇恨。针对非受保护群体(如棋手)的仇恨归为骚扰。 仅文本
hate/threatening 基于上述受保护属性针对某群体的仇恨,并包含暴力或严重伤害。 仅文本
illicit 提供实施违法行为的建议或指示,例如“如何在商店行窃”。 仅文本
illicit/violent 与 illicit 类相同,但还涉及暴力或获取武器。 仅文本
self-harm 宣扬、鼓励或描绘自伤行为,例如自杀、割伤及进食障碍。 文本和图像
self-harm/intent 说话者表达正在或打算实施自伤行为,例如自杀、割伤及进食障碍。 文本和图像
self-harm/instructions 鼓励自伤或提供实施建议和指导,包括自杀、割伤及进食障碍。 文本和图像
sexual 旨在引起性兴奋的内容,例如性行为描写或推广性服务;不包括性教育和健康内容。 文本和图像
sexual/minors 包含未满 18 岁者的性内容。 仅文本
violence 描绘死亡、暴力或身体伤害。 文本和图像
violence/graphic 以血腥细节描绘死亡、暴力或身体伤害。 文本和图像
OpenAI Webhooks
OpenAI API 安全最佳实践
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

其他能力与进阶指南

Embeddings 接口参考

审计日志接口参考

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }