> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aihubmix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Moderation

> 提供完全相容於 OpenAI 標準的內容審核 API,讓開發者可以使用多模態審核模型自動識別文字或影像中的有害內容(例如仇恨言論、暴力、非法活動等),確保應用程式合規。

## API 資訊

* **端點**:`https://aihubmix.com/v1/moderations`
* **請求方法**:`POST`
* **驗證**:`Authorization: Bearer <AIHUBMIX_API_KEY>`
* **Content-Type**:`application/json`
* 此端點支援兩種模型:

  1. `omni-moderation-latest`:此模型及其所有快照支援更多分類選項與多模態輸入。

  2. `text-moderation-latest`:僅支援文字輸入,分類選項較少。

## 快速開始

### 用法範例

<CodeGroup>
  ```python Text Input theme={null}
  import openai

  client = openai.OpenAI(
    api_key="AIHUBMIX_API_KEY",  
    base_url="https://aihubmix.com/v1"
  )

  response = client.moderations.create(
      model="text-moderation-latest",
      input="The Yangtze River rolls eastward, its waves washing away heroes. Right and wrong, success and failure, all seem empty; the green hills remain, though the sun sets many times. The white-haired fisherman and woodcutter on the riverbank, accustomed to watching the autumn moon and spring breeze. A pot of turbid wine brings joy in meeting, how many events through time are all laughed off.",
  )

  print(response)
  ```

  ```python Image and Text Input theme={null}
  import openai

  client = openai.OpenAI(
    api_key="AIHUBMIX_API_KEY", 
    base_url="https://aihubmix.com/v1"
  )

  response = client.moderations.create(
      model="omni-moderation-latest",
      input=[
          {"type": "text", "text": "The image depicts a male, with his arms raised, body tense, head tilted back, mouth open, showing extreme agitation or anger."},
          {
              "type": "image_url",
              "image_url": {
                  "url": "https://thumbs.dreamstime.com/b/violent-man-furious-straining-arms-looking-up-concept-person-35012557.jpg",
                  # can also use base64 encoded image URLs
                  # "url": "data:image/jpeg;base64,abcdefg..."
              }
          },
      ],
  )

  print(response)
  ```
</CodeGroup>

### 輸出範例

以下為完整的輸出範例,模型正確地預測了影像中的自我傷害與暴力元素。

```json theme={null}
{
  "id": "modr-5175",
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": true,

      "categories": {
        "harassment": false,
        "harassment_threatening": false,
        "hate": false,
        "hate_threatening": false,
        "illicit": false,
        "illicit_violent": false,

        "self_harm": true,
        "self_harm_instructions": false,
        "self_harm_intent": false,

        "sexual": false,
        "sexual_minors": false,

        "violence": true,
        "violence_graphic": true
      },

      "category_applied_input_types": {
        "harassment": ["text"],
        "harassment_threatening": ["text"],
        "hate": ["text"],
        "hate_threatening": ["text"],
        "illicit": ["text"],
        "illicit_violent": ["text"],

        "self_harm": ["text", "image"],
        "self_harm_instructions": ["text", "image"],
        "self_harm_intent": ["text", "image"],

        "sexual": ["text", "image"],
        "sexual_minors": ["text"],

        "violence": ["text", "image"],
        "violence_graphic": ["text", "image"]
      },

      "category_scores": {
        "harassment": 0.00507676338091392,
        "harassment_threatening": 0.0008967480822931635,
        "hate": 8.830458477845481e-05,
        "hate_threatening": 1.0720880092159908e-05,
        "illicit": 3.740956047302422e-05,
        "illicit_violent": 2.868540823874629e-05,

        "self_harm": 0.6967791744783793,
        "self_harm_instructions": 0.00027978227581033677,
        "self_harm_intent": 0.0003781080988395418,

        "sexual": 0.0007007652612809208,
        "sexual_minors": 2.5071593847983196e-06,

        "violence": 0.5236158587905301,
        "violence_graphic": 0.4213528687243541
      }
    }
  ]
}
```

輸出結果在 JSON 回應中包含數個分類,告知您輸入中存在(如有)哪些類型的內容,以及模型認為其存在程度的高低。

| **輸出分類**                       | **說明**                                                                                                                               |
| :----------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- |
| `flagged`                      | 若模型將內容分類為可能有害則設為 `true`,否則為 `false`。                                                                                                 |
| `categories`                   | 包含各分類違規旗標的字典。對每個分類而言,若模型將其旗標為違反則值為 `true`,否則為 `false`。                                                                               |
| `category_scores`              | 包含模型輸出的各分類分數字典,代表模型對該輸入違反該分類 OpenAI 政策的信心程度。數值介於 0 到 1 之間,數值越高代表信心越高。                                                                |
| `category_applied_input_types` | 此屬性包含對每個分類而言,回應中哪些輸入類型被旗標的資訊。例如,如果模型的影像和文字輸入都被旗標為「violence/graphic」,則 `violence/graphic` 屬性將設為 `["image", "text"]`。此功能僅在 omni 模型上可用。 |

## 內容分類

下表描述了 moderation API 可偵測的內容類型,以及每個分類支援的模型與輸入類型。

<Tip>
  標示為「僅文字」的分類不支援影像輸入。如果您使用 `omni-moderation-latest` 僅向模型傳送影像(不含文字),則模型對這些不支援的分類會傳回 0 分。
</Tip>

| **分類**                   | **說明**                                                                | **模型** | **輸入** |
| :----------------------- | :-------------------------------------------------------------------- | :----- | :----- |
| `harassment`             | 對任何對象表達、煽動或推廣騷擾言論的內容。                                                 | 所有     | 僅文字    |
| `harassment/threatening` | 同時涉及暴力或對任何對象嚴重傷害的騷擾內容。                                                | 所有     | 僅文字    |
| `hate`                   | 基於種族、性別、族群、宗教、國籍、性取向、身心障礙狀態或種姓表達、煽動或推廣仇恨的內容。針對非受保護群體(例如棋手)的仇恨內容歸類為騷擾。 | 所有     | 僅文字    |
| `hate/threatening`       | 基於種族、性別、族群、宗教、國籍、性取向、身心障礙狀態或種姓針對目標群體並涉及暴力或嚴重傷害的仇恨內容。                  | 所有     | 僅文字    |
| `illicit`                | 與 `illicit` 分類所標示相同類型的內容,但同時涉及暴力或取得武器。                                | 僅 Omni | 僅文字    |
| `illicit/violent`        | 類似於標示為 `illicit` 的內容類型,但同時涉及暴力或取得武器的描述。                               | 僅 Omni | 僅文字    |
| `self-harm`              | 推廣、鼓勵或描繪自我傷害行為的內容,例如自殺、割傷與飲食失調。                                       | 所有     | 文字與影像  |
| `self-harm/intent`       | 說話者表達自己正在從事或打算從事自我傷害行為的內容,例如自殺、割傷與飲食失調。                               | 所有     | 文字與影像  |
| `self-harm/instructions` | 鼓勵實施自我傷害行為的內容,例如自殺、割傷與飲食失調,或提供如何實施這類行為的指示或建議。                         | 所有     | 文字與影像  |
| `sexual`                 | 旨在引起性興奮的內容,例如性活動描述,或推廣性服務的內容(不包含性教育與健康)。                              | 所有     | 文字與影像  |
| `sexual/minors`          | 涉及未滿 18 歲個人的色情內容。                                                     | 所有     | 僅文字    |
| `violence`               | 描繪死亡、暴力或身體傷害的內容。                                                      | 所有     | 文字與影像  |
| `violence/graphic`       | 以血腥細節描繪死亡、暴力或身體傷害的內容。                                                 | 所有     | 文字與影像  |

***

最後更新：2026-06-01
