OpenAI Moderationen
Eine Anfrage über RunAPIs OpenAI-kompatible Moderations-Operation senden.
Übersicht
Verwende RunAPI's OpenAI-kompatible Moderations-Operation mit einem kompatiblen Modell sowie den Anfrage- und Antwortstrukturen des Protokolls.
Schnellstart
- Erstellen Sie einen API-Schlüssel und setzen Sie ihn als RUNAPI_API_KEY.
- Wählen Sie ein kompatibles Modell, senden Sie dann die dokumentierten Pfadparameter und den JSON-Body.
- Lesen Sie die für diesen Vorgang angezeigte JSON-Antwort oder die server-sent events und behandeln Sie Protokollfehler.
Endpunkt
- Basis-URL
https://runapi.ai- Vertragsversion
v1- Bevorzugte Authentifizierung
Authorization: Bearer YOUR_API_TOKEN
Authentifizierungsträger
RunAPI akzeptiert jeden der unten aufgeführten Träger. Generierte Beispiele verwenden den bevorzugten Header des Protokolls.
- header - Bevorzugt
Authorization: Bearer YOUR_API_TOKEN- header
x-api-key: YOUR_API_TOKEN
Kompatible Modelle
Öffnen Sie eine Modellseite für aktuelle Preise, Ratenlimits und Details zur kommerziellen Nutzung.
1 kompatibles Modell anzeigen
Anfrage-Vertrag
Es werden nur Felder aufgeführt, für die sowohl öffentliche Protokoll- als auch RunAPI-Unterstützung belegt ist. Weitere JSON-Body-Felder werden durchgereicht.
JSON-Body2 Felder
input["string", "array"]Text oder gemischter Text- und Bildinhalt zur Klassifikation.
modelstringRunAPI-Moderationsmodellbezeichner; Standard ist omni-moderation-latest.
Anfragebeispiel
{
"input": [
{
"text": "A peaceful landscape.",
"type": "text"
},
{
"image_url": {
"url": "https://runapi.ai/icon.png"
},
"type": "image_url"
}
]
}
Synchrone Antwort
Schema
{
"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"
}
Beispiel
{
"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
}
]
}
Protokollfehler: invalid_request
Schema
{
"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"
}
Beispiel
{
"error": {
"code": null,
"message": "input is required",
"param": "input",
"type": "invalid_request_error"
}
}
Generierte Code-Beispiele
Jedes cURL-, JavaScript- und Python-Beispiel sendet die validierte Anfrage aus diesem Vertrag, ohne ein protokollspezifisches SDK zu benötigen.
Installieren
pip install requests
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())