メインコンテンツへスキップ
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 互換のモデレーションリクエストを送信します。
ベアラーヘッダーには CometAPI API キーを使用します: Authorization: Bearer $COMETAPI_KEY

リクエスト本文

FieldTypeRequiredDescription
inputstring or arrayYesチェックするコンテンツです。1 つのテキスト入力には文字列を、複数のテキストをまとめてチェックする場合は文字列の配列を、またはテキストと image_url のような OpenAI 形式のマルチモーダル要素を使用します。
modelstringYesモデレーションの model ID です。特定のモデレーションモデル要件がない限り、テキストと画像のモデレーションには omni-moderation-latest を使用します。
マルチモーダルのモデレーションでは、omni-moderation-latest のような対応モデルを使って OpenAI 形式のマルチモーダル入力を送信します。公開画像 URL は CometAPI サーバーからダウンロード可能である必要があります。画像をコピー可能なテストにするには、base64 の data URL を使用します。

リクエスト例

テキスト入力が 1 つだけで分類したい場合は、単一のテキスト文字列を送信します。
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."
  }'
複数のテキスト入力を 1 回のリクエストでチェックしたい場合は、文字列の配列を送信します。
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"
        }
      }
    ]
  }'

レスポンス形式

レスポンスには idmodelresultsusage が含まれます。results の各項目には、対応する入力がフラグ付けされたかどうか、カテゴリごとの真偽値、カテゴリスコア、各カテゴリに適用された入力タイプが含まれます。バッチテキストリクエストでは、results に入力文字列ごとに 1 項目が含まれます。課金と監視の項目には 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.