跳转到主要内容
POST
/
v1
/
moderations
curl https://api.cometapi.com/v1/moderations \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -d '{
  "model": "omni-moderation-latest",
  "input": "I want to bake cookies for my family."
}'
{
  "id": "modr-1594",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "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,
        "sexual": false,
        "sexual/minors": false,
        "violence": false,
        "violence/graphic": false
      },
      "category_scores": {
        "harassment": 0.0001,
        "harassment/threatening": 0.0001,
        "hate": 0.0001,
        "hate/threatening": 0.0001,
        "illicit": 0.0001,
        "illicit/violent": 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.0001,
        "violence/graphic": 0.0001
      },
      "category_applied_input_types": {
        "harassment": [
          "text"
        ],
        "harassment/threatening": [
          "text"
        ],
        "hate": [
          "text"
        ],
        "hate/threatening": [
          "text"
        ],
        "illicit": [
          "text"
        ],
        "illicit/violent": [
          "text"
        ],
        "self-harm": [
          "text"
        ],
        "self-harm/intent": [
          "text"
        ],
        "self-harm/instructions": [
          "text"
        ],
        "sexual": [
          "text"
        ],
        "sexual/minors": [
          "text"
        ],
        "violence": [
          "text"
        ],
        "violence/graphic": [
          "text"
        ]
      }
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 0,
    "total_tokens": 12,
    "input_tokens": 12,
    "output_tokens": 0,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    },
    "input_tokens_details": null,
    "claude_cache_creation_1_h_tokens": 0,
    "claude_cache_creation_5_m_tokens": 0
  }
}
使用此端点,在将用户生成内容发送到模型端点之前先进行检查。发送一个包含 modelinput 值的 OpenAI 兼容审核请求。
在 bearer 头中使用 CometAPI API key:Authorization: Bearer $COMETAPI_KEY

请求体

FieldTypeRequiredDescription
inputstring or arrayYes要检查的内容。单个文本输入使用字符串,批量文本检查使用字符串数组,或者使用 OpenAI 风格的多模态部分,例如文本加 image_url
modelstringYes审核 model ID。除非你有特定的审核模型要求,否则文本和图像审核请使用 omni-moderation-latest
对于多模态审核,请发送使用支持该能力的模型的 OpenAI 风格多模态输入,例如 omni-moderation-latest。公开图像 URL 必须能被 CometAPI 服务器下载。若要测试可复制的图像,请使用 base64 data URL。

请求示例

当你只需要对一个文本输入进行分类时,发送单个文本字符串:
curl https://api.cometapi.com/v1/moderations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": "I want to bake cookies for my family."
  }'
当你想在一次请求中检查多个文本输入时,发送字符串数组:
curl https://api.cometapi.com/v1/moderations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": [
      "I want to bake cookies.",
      "I want to kill someone."
    ]
  }'
当你的审核输入包含 CometAPI 可以下载的图像时,发送文本加图像 URL:
curl https://api.cometapi.com/v1/moderations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": [
      { "type": "text", "text": "...text to classify goes here..." },
      {
        "type": "image_url",
        "image_url": {
          "url": "https://www.gstatic.com/webp/gallery/1.png"
        }
      }
    ]
  }'
当你需要一个自包含的图像请求时,请使用 base64 data URL:
curl https://api.cometapi.com/v1/moderations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": [
      { "type": "text", "text": "...text to classify goes here..." },
      {
        "type": "image_url",
        "image_url": {
          "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAADElEQVR4nGP4//8/AAX+Av4N70a4AAAAAElFTkSuQmCC"
        }
      }
    ]
  }'

响应结构

响应包含 idmodelresultsusageresults 中的每一项都会报告匹配输入是否被标记、类别布尔值、类别分数,以及应用于每个类别的输入类型。对于批量文本请求,results 中每个输入字符串对应一项。使用 usage 进行计费和监控字段。

授权

Authorization
string
header
必填

CometAPI API key used for model requests. Send it as Authorization: Bearer $COMETAPI_KEY.

请求体

application/json
model
string
必填

Required moderation model ID. Use omni-moderation-latest for text and image moderation unless you have a specific moderation model requirement.

示例:

"omni-moderation-latest"

input
必填

Content to check. Use a string for one text input, an array of strings for batch text checks, or OpenAI-style multimodal parts such as text plus image_url when the selected model supports it.

示例:

"I want to check this text before sending it to a model."

响应

Moderation decisions and token usage.

id
string
必填

Moderation request ID.

示例:

"modr-1594"

model
string
必填

Model used for moderation.

示例:

"omni-moderation-latest"

results
object[]
必填

Moderation decisions. For batch text input, this array contains one result per input string.

usage
object
必填

Token usage for the moderation request. Additional provider accounting fields can be present.