跳至主要內容
API 參考
API 參考

OpenAI 內容審核

透過 RunAPI 的 OpenAI 相容 Moderations 操作傳送請求。

01

概覽

使用 RunAPI 的 OpenAI 相容 Moderations 操作,配合相容模型及該協定的請求與回應格式。

快速入門

  1. 建立 API 金鑰並將其設定為 RUNAPI_API_KEY。
  2. 選擇相容的模型,然後發送文檔中的路徑參數和 JSON 主體。
  3. 讀取此操作所示的 JSON 回應或伺服器推送事件,並處理協定錯誤。

端點

POST /v1/moderations
基礎 URL
https://runapi.ai
合約版本
v1
建議的身份驗證方式
Authorization: Bearer YOUR_API_TOKEN
02

身份驗證載體

RunAPI 接受以下列出的每種載體。生成的範例使用協議的首選標頭。

header - 建議
Authorization: Bearer YOUR_API_TOKEN
header
x-api-key: YOUR_API_TOKEN
03

相容模型

開啟模型頁面以查看當前定價、速率限制及商業用途詳情。

顯示 1 個相容模型
04

請求合約

JSON 內容

僅列出同時具有公開協議和 RunAPI 支援證明的欄位。額外的 JSON 主體欄位將直接傳遞。

JSON 內文2 個欄位
input["string", "array"]
必填

待分類的文字或文字與圖像混合內容。

modelstring
選填

RunAPI 審核模型識別符;預設為 omni-moderation-latest。

請求範例

JSON
{
  "input": [
    {
      "text": "A peaceful landscape.",
      "type": "text"
    },
    {
      "image_url": {
        "url": "https://runapi.ai/icon.png"
      },
      "type": "image_url"
    }
  ]
}
05

同步回應

HTTP 200

結構描述

JSON
{
  "additionalProperties": true,
  "properties": {
    "id": {
      "minLength": 1,
      "type": "string"
    },
    "model": {
      "minLength": 1,
      "type": "string"
    },
    "results": {
      "items": {
        "additionalProperties": true,
        "properties": {
          "categories": {
            "additionalProperties": true,
            "type": "object"
          },
          "category_applied_input_types": {
            "additionalProperties": true,
            "type": "object"
          },
          "category_scores": {
            "additionalProperties": true,
            "type": "object"
          },
          "flagged": {
            "type": "boolean"
          }
        },
        "required": [
          "flagged",
          "categories",
          "category_scores"
        ],
        "type": "object"
      },
      "minItems": 1,
      "type": "array"
    }
  },
  "required": [
    "id",
    "model",
    "results"
  ],
  "type": "object"
}

範例

JSON
{
  "id": "modr_123",
  "model": "omni-moderation-latest",
  "results": [
    {
      "categories": {
        "sexual": false,
        "violence": false
      },
      "category_applied_input_types": {
        "sexual": [
          "text",
          "image"
        ],
        "violence": [
          "text",
          "image"
        ]
      },
      "category_scores": {
        "sexual": 0.0002,
        "violence": 0.0001
      },
      "flagged": false
    }
  ]
}
06

協定錯誤:invalid_request

HTTP 400

結構描述

JSON
{
  "additionalProperties": true,
  "properties": {
    "error": {
      "additionalProperties": true,
      "properties": {
        "code": {
          "type": [
            "string",
            "null"
          ]
        },
        "message": {
          "type": "string"
        },
        "param": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": "string"
        }
      },
      "required": [
        "message",
        "type"
      ],
      "type": "object"
    }
  },
  "required": [
    "error"
  ],
  "type": "object"
}

範例

JSON
{
  "error": {
    "code": null,
    "message": "input is required",
    "param": "input",
    "type": "invalid_request_error"
  }
}
07

已生成的程式碼範例

每個 cURL、JavaScript 及 Python 範例均透過此合約發送已驗證的請求,無需使用特定協議的 SDK。

安裝

Shell
pip install requests
PYTHON
import requests

response = requests.post(
    "https://runapi.ai/v1/moderations",
    headers={"Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json"},
    json={"input": [{"type": "text", "text": "A peaceful landscape."}, {"type": "image_url", "image_url": {"url": "https://runapi.ai/icon.png"}}]}
)
response.raise_for_status()
print(response.json())