API 参考
OpenAI Moderations
通过 RunAPI 的 OpenAI 兼容 Moderations operation 发送请求。
01
概览
使用兼容模型和对应协议的请求、响应结构调用 RunAPI 的 OpenAI 兼容 Moderations operation。
快速开始
- 创建 API Key,并将其设置为 RUNAPI_API_KEY。
- 选择兼容模型,然后发送文档所列的路径参数和 JSON 请求体。
- 读取此 operation 展示的 JSON 响应或服务器发送事件,并处理协议错误。
端点
- 基础 URL
https://runapi.ai- Contract 版本
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 请求体请求 Contract
这里只列出同时具有公共协议与 RunAPI 支持证据的字段;其他 JSON 请求体字段会原样传递。
JSON 请求体2 个字段
input["string", "array"]
必填
Text or mixed text and image content to classify.
modelstring
可选
RunAPI moderation model identifier; defaults to 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
同步响应
Schema
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
HTTP 400
协议错误:invalid_request
Schema
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 示例都会发送此 Contract 中经过验证的请求,无需协议专用 SDK。
CURL
curl -X POST https://runapi.ai/v1/moderations \
-H Authorization:\ Bearer\ YOUR_API_TOKEN \
-H Content-Type:\ application/json \
-d \{\"input\":\[\{\"type\":\"text\",\"text\":\"A\ peaceful\ landscape.\"\},\{\"type\":\"image_url\",\"image_url\":\{\"url\":\"https://runapi.ai/icon.png\"\}\}\]\}
JAVASCRIPT
const response = await fetch("https://runapi.ai/v1/moderations", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_TOKEN",
"Content-Type": "application/json"
},
body: JSON.stringify({
"input": [
{
"type": "text",
"text": "A peaceful landscape."
},
{
"type": "image_url",
"image_url": {
"url": "https://runapi.ai/icon.png"
}
}
]
})
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
console.log(data);
安装
BASH
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())