Create Moderation
curl --request POST \
--url https://api.electronhub.ai/v1/moderations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "text-moderation-latest",
"input": "<string>"
}
'import requests
url = "https://api.electronhub.ai/v1/moderations"
payload = {
"model": "text-moderation-latest",
"input": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'text-moderation-latest', input: '<string>'})
};
fetch('https://api.electronhub.ai/v1/moderations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.electronhub.ai/v1/moderations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'text-moderation-latest',
'input' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.electronhub.ai/v1/moderations"
payload := strings.NewReader("{\n \"model\": \"text-moderation-latest\",\n \"input\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.electronhub.ai/v1/moderations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"text-moderation-latest\",\n \"input\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.electronhub.ai/v1/moderations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"text-moderation-latest\",\n \"input\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"model": "<string>",
"results": [
{
"flagged": true,
"categories": {
"sexual": true,
"hate": true,
"harassment": true,
"self-harm": true,
"sexual/minors": true,
"hate/threatening": true,
"violence/graphic": true,
"self-harm/intent": true,
"self-harm/instructions": true,
"harassment/threatening": true,
"violence": true
},
"category_scores": {
"sexual": 123,
"hate": 123,
"harassment": 123,
"self-harm": 123,
"sexual/minors": 123,
"hate/threatening": 123,
"violence/graphic": 123,
"self-harm/intent": 123,
"self-harm/instructions": 123,
"harassment/threatening": 123,
"violence": 123
}
}
]
}API Reference
Moderations
Classify text content for safety violations
POST
/
moderations
Create Moderation
curl --request POST \
--url https://api.electronhub.ai/v1/moderations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "text-moderation-latest",
"input": "<string>"
}
'import requests
url = "https://api.electronhub.ai/v1/moderations"
payload = {
"model": "text-moderation-latest",
"input": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'text-moderation-latest', input: '<string>'})
};
fetch('https://api.electronhub.ai/v1/moderations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.electronhub.ai/v1/moderations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'text-moderation-latest',
'input' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.electronhub.ai/v1/moderations"
payload := strings.NewReader("{\n \"model\": \"text-moderation-latest\",\n \"input\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.electronhub.ai/v1/moderations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"text-moderation-latest\",\n \"input\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.electronhub.ai/v1/moderations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"text-moderation-latest\",\n \"input\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"model": "<string>",
"results": [
{
"flagged": true,
"categories": {
"sexual": true,
"hate": true,
"harassment": true,
"self-harm": true,
"sexual/minors": true,
"hate/threatening": true,
"violence/graphic": true,
"self-harm/intent": true,
"self-harm/instructions": true,
"harassment/threatening": true,
"violence": true
},
"category_scores": {
"sexual": 123,
"hate": 123,
"harassment": 123,
"self-harm": 123,
"sexual/minors": 123,
"hate/threatening": 123,
"violence/graphic": 123,
"self-harm/intent": 123,
"self-harm/instructions": 123,
"harassment/threatening": 123,
"violence": 123
}
}
]
}The Moderations API helps detect potentially harmful content in text.
Create Moderation
POST /moderations
Classify a text to see if it violates OpenAI’s usage policies.
Request Body
string | array
required
The input text to classify
string
The moderation model to use (e.g., “text-moderation-latest”, “text-moderation-stable”)
Response
Returns a moderation object with classification results.Example
const response = await fetch('https://api.electronhub.ai/v1/moderations', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
input: 'I want to hurt someone.',
model: 'text-moderation-latest'
})
});
const data = await response.json();
console.log(data);
import requests
response = requests.post(
'https://api.electronhub.ai/v1/moderations',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={
'input': 'I want to hurt someone.',
'model': 'text-moderation-latest'
}
)
print(response.json())
curl -X POST "https://api.electronhub.ai/v1/moderations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "I want to hurt someone.",
"model": "text-moderation-latest"
}'
Response Format
The response contains the following fields:id: Unique identifier for the moderation requestmodel: The model used for moderationresults: Array of result objects with the following properties:flagged: Whether the content was flaggedcategories: Object with boolean values for each categorycategory_scores: Object with confidence scores for each category
Categories
The moderation model checks for the following categories:- hate: Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste
- hate/threatening: Hateful content that also includes violence or serious harm towards the targeted group
- harassment: Content that expresses, incites, or promotes harassing language towards any target
- harassment/threatening: Harassment content that also includes violence or serious harm towards any target
- self-harm: Content that promotes, encourages, or depicts acts of self-harm
- self-harm/intent: Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm
- self-harm/instructions: Content that encourages performing acts of self-harm
- sexual: Content meant to arouse sexual excitement
- sexual/minors: Sexual content that includes an individual who is under 18 years old
- violence: Content that depicts death, violence, or physical injury
- violence/graphic: Content that depicts death, violence, or physical injury in graphic detail
Authorizations
Enter your API key (starts with 'ek-')
Body
application/json
