Every API here is available over the APIs.io API and to AI agents over MCP.
openapi: 3.2.0
info:
title: OpenAI Moderations API
description: The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
version: 2.3.0
termsOfService: https://openai.com/policies/terms-of-use
contact:
name: OpenAI Support
url: https://help.openai.com/
license:
name: MIT
identifier: MIT
servers:
- url: https://api.openai.com/v1
security:
- ApiKeyAuth: []
tags:
- name: Moderations
description: Given text and/or image inputs, classifies if those inputs are potentially harmful.
paths:
/moderations:
post:
operationId: createModeration
tags:
- Moderations
summary: Create moderation
description: 'Classifies if text and/or image inputs are potentially harmful. Learn
more in the moderation guide.'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateModerationRequest'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/CreateModerationResponse'
'429':
$ref: '#/components/responses/InferenceRateLimited'
'503':
$ref: '#/components/responses/InferenceServiceUnavailable'
x-oaiMeta:
group: moderations
examples:
- title: Single string
request:
curl: "curl https://api.openai.com/v1/moderations \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n -d '{\n \"input\": \"I want to kill them.\"\n }'\n"
python: 'from openai import OpenAI
client = OpenAI()
moderation = client.moderations.create(input="I want to kill them.")
print(moderation)
'
javascript: "import OpenAI from \"openai\";\n\nconst openai = new OpenAI();\n\nasync function main() {\n const moderation = await openai.moderations.create({ input: \"I want to kill them.\" });\n\n console.log(moderation);\n}\nmain();\n"
csharp: "using System;\nusing System.ClientModel;\n\nusing OpenAI.Moderations;\n\nModerationClient client = new(\n model: \"omni-moderation-latest\",\n apiKey: Environment.GetEnvironmentVariable(\"OPENAI_API_KEY\")\n);\n\nClientResult<ModerationResult> moderation = client.ClassifyText(\"I want to kill them.\");\n"
response: "{\n \"id\": \"modr-AB8CjOTu2jiq12hp1AQPfeqFWaORR\",\n \"model\": \"text-moderation-007\",\n \"results\": [\n {\n \"flagged\": true,\n \"categories\": {\n \"sexual\": false,\n \"hate\": false,\n \"harassment\": true,\n \"self-harm\": false,\n \"sexual/minors\": false,\n \"hate/threatening\": false,\n \"violence/graphic\": false,\n \"self-harm/intent\": false,\n \"self-harm/instructions\": false,\n \"harassment/threatening\": true,\n \"violence\": true\n },\n \"category_scores\": {\n \"sexual\": 0.000011726012417057063,\n \"hate\": 0.22706663608551025,\n \"harassment\": 0.5215635299682617,\n \"self-harm\": 2.227119921371923e-6,\n \"sexual/minors\": 7.107352217872176e-8,\n \"hate/threatening\": 0.023547329008579254,\n \"violence/graphic\": 0.00003391829886822961,\n \"self-harm/intent\": 1.646940972932498e-6,\n \"self-harm/instructions\": 1.1198755256458526e-9,\n \"harassment/threatening\": 0.5694745779037476,\n \"violence\": 0.9971134662628174\n }\n }\n ]\n}\n"
- title: Image and text
request:
curl: "curl https://api.openai.com/v1/moderations \\\n -X POST \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n -d '{\n \"model\": \"omni-moderation-latest\",\n \"input\": [\n { \"type\": \"text\", \"text\": \"...text to classify goes here...\" },\n {\n \"type\": \"image_url\",\n \"image_url\": {\n \"url\": \"https://example.com/image.png\"\n }\n }\n ]\n }'\n"
python: "from openai import OpenAI\nclient = OpenAI()\n\nresponse = client.moderations.create(\n model=\"omni-moderation-latest\",\n input=[\n {\"type\": \"text\", \"text\": \"...text to classify goes here...\"},\n {\n \"type\": \"image_url\",\n \"image_url\": {\n \"url\": \"https://example.com/image.png\",\n # can also use base64 encoded image URLs\n # \"url\": \"data:image/jpeg;base64,abcdefg...\"\n }\n },\n ],\n)\n\nprint(response)\n"
javascript: "import OpenAI from \"openai\";\nconst openai = new OpenAI();\n\nconst moderation = await openai.moderations.create({\n model: \"omni-moderation-latest\",\n input: [\n { type: \"text\", text: \"...text to classify goes here...\" },\n {\n type: \"image_url\",\n image_url: {\n url: \"https://example.com/image.png\"\n // can also use base64 encoded image URLs\n // url: \"data:image/jpeg;base64,abcdefg...\"\n }\n }\n ],\n});\n\nconsole.log(moderation);\n"
response: "{\n \"id\": \"modr-0d9740456c391e43c445bf0f010940c7\",\n \"model\": \"omni-moderation-latest\",\n \"results\": [\n {\n \"flagged\": true,\n \"categories\": {\n \"harassment\": true,\n \"harassment/threatening\": true,\n \"sexual\": false,\n \"hate\": false,\n \"hate/threatening\": false,\n \"illicit\": false,\n \"illicit/violent\": false,\n \"self-harm/intent\": false,\n \"self-harm/instructions\": false,\n \"self-harm\": false,\n \"sexual/minors\": false,\n \"violence\": true,\n \"violence/graphic\": true\n },\n \"category_scores\": {\n \"harassment\": 0.8189693396524255,\n \"harassment/threatening\": 0.804985420696006,\n \"sexual\": 1.573112165348997e-6,\n \"hate\": 0.007562942636942845,\n \"hate/threatening\": 0.004208854591835476,\n \"illicit\": 0.030535955153511665,\n \"illicit/violent\": 0.008925306722380033,\n \"self-harm/intent\": 0.00023023930975076432,\n \"self-harm/instructions\": 0.0002293869201073356,\n \"self-harm\": 0.012598046106750154,\n \"sexual/minors\": 2.212566909570261e-8,\n \"violence\": 0.9999992735124786,\n \"violence/graphic\": 0.843064871157054\n },\n \"category_applied_input_types\": {\n \"harassment\": [\n \"text\"\n ],\n \"harassment/threatening\": [\n \"text\"\n ],\n \"sexual\": [\n \"text\",\n \"image\"\n ],\n \"hate\": [\n \"text\"\n ],\n \"hate/threatening\": [\n \"text\"\n ],\n \"illicit\": [\n \"text\"\n ],\n \"illicit/violent\": [\n \"text\"\n ],\n \"self-harm/intent\": [\n \"text\",\n \"image\"\n ],\n \"self-harm/instructions\": [\n \"text\",\n \"image\"\n ],\n \"self-harm\": [\n \"text\",\n \"image\"\n ],\n \"sexual/minors\": [\n \"text\"\n ],\n \"violence\": [\n \"text\",\n \"image\"\n ],\n \"violence/graphic\": [\n \"text\",\n \"image\"\n ]\n }\n }\n ]\n}\n"
components:
schemas:
CreateModerationRequest:
type: object
properties:
input:
description: 'Input (or inputs) to classify. Can be a single string, an array of strings, or
an array of multi-modal input objects similar to other models.
'
oneOf:
- type: string
description: A string of text to classify for moderation.
default: ''
example: I want to kill them.
- type: array
description: An array of strings to classify for moderation.
items:
type: string
default: ''
example: I want to kill them.
- type: array
description: An array of multi-modal inputs to the moderation model.
items:
oneOf:
- type: object
description: An object describing an image to classify.
properties:
type:
description: Always `image_url`.
type: string
enum:
- image_url
x-stainless-const: true
image_url:
type: object
description: Contains either an image URL or a data URL for a base64 encoded image.
properties:
url:
type: string
description: Either a URL of the image or the base64 encoded image data.
format: uri
example: https://example.com/image.jpg
required:
- url
required:
- type
- image_url
- type: object
description: An object describing text to classify.
properties:
type:
description: Always `text`.
type: string
enum:
- text
x-stainless-const: true
text:
description: A string of text to classify.
type: string
example: I want to kill them
required:
- type
- text
model:
description: 'The content moderation model you would like to use. Learn more in
[the moderation guide](https://developers.openai.com/api/docs/guides/moderation), and learn about
available models [here](https://developers.openai.com/api/docs/guides/moderation).
'
nullable: false
default: omni-moderation-latest
example: omni-moderation-2024-09-26
anyOf:
- type: string
- type: string
enum:
- omni-moderation-latest
- omni-moderation-2024-09-26
- text-moderation-latest
- text-moderation-stable
x-oaiTypeLabel: string
required:
- input
_MisalignmentErrorType:
anyOf:
- type: string
- type: string
enum:
- potentially_unintended_data_transfer
- potentially_unintended_data_access
- potentially_unintended_destructive_activity
- other
CreateModerationResponse:
type: object
description: Represents if a given text input is potentially harmful.
properties:
id:
type: string
description: The unique identifier for the moderation request.
model:
type: string
description: The model used to generate the moderation results.
results:
type: array
description: A list of moderation objects.
items:
type: object
properties:
flagged:
type: boolean
description: Whether any of the below categories are flagged.
categories:
type: object
description: A list of the categories, and whether they are flagged or not.
properties:
hate:
type: boolean
description: Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. Hateful content aimed at non-protected groups (e.g., chess players) is harassment.
hate/threatening:
type: boolean
description: Hateful content that also includes violence or serious harm towards the targeted group based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste.
harassment:
type: boolean
description: Content that expresses, incites, or promotes harassing language towards any target.
harassment/threatening:
type: boolean
description: Harassment content that also includes violence or serious harm towards any target.
illicit:
anyOf:
- type: boolean
description: Content that includes instructions or advice that facilitate the planning or execution of wrongdoing, or that gives advice or instruction on how to commit illicit acts. For example, "how to shoplift" would fit this category.
- type: 'null'
illicit/violent:
anyOf:
- type: boolean
description: Content that includes instructions or advice that facilitate the planning or execution of wrongdoing that also includes violence, or that gives advice or instruction on the procurement of any weapon.
- type: 'null'
self-harm:
type: boolean
description: Content that promotes, encourages, or depicts acts of self-harm, such as suicide, cutting, and eating disorders.
self-harm/intent:
type: boolean
description: Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders.
self-harm/instructions:
type: boolean
description: Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts.
sexual:
type: boolean
description: Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services (excluding sex education and wellness).
sexual/minors:
type: boolean
description: Sexual content that includes an individual who is under 18 years old.
violence:
type: boolean
description: Content that depicts death, violence, or physical injury.
violence/graphic:
type: boolean
description: Content that depicts death, violence, or physical injury in graphic detail.
required:
- hate
- hate/threatening
- harassment
- harassment/threatening
- illicit
- illicit/violent
- self-harm
- self-harm/intent
- self-harm/instructions
- sexual
- sexual/minors
- violence
- violence/graphic
category_scores:
type: object
description: A list of the categories along with their scores as predicted by model.
properties:
hate:
type: number
description: The score for the category 'hate'.
hate/threatening:
type: number
description: The score for the category 'hate/threatening'.
harassment:
type: number
description: The score for the category 'harassment'.
harassment/threatening:
type: number
description: The score for the category 'harassment/threatening'.
illicit:
type: number
description: The score for the category 'illicit'.
illicit/violent:
type: number
description: The score for the category 'illicit/violent'.
self-harm:
type: number
description: The score for the category 'self-harm'.
self-harm/intent:
type: number
description: The score for the category 'self-harm/intent'.
self-harm/instructions:
type: number
description: The score for the category 'self-harm/instructions'.
sexual:
type: number
description: The score for the category 'sexual'.
sexual/minors:
type: number
description: The score for the category 'sexual/minors'.
violence:
type: number
description: The score for the category 'violence'.
violence/graphic:
type: number
description: The score for the category 'violence/graphic'.
required:
- hate
- hate/threatening
- harassment
- harassment/threatening
- illicit
- illicit/violent
- self-harm
- self-harm/intent
- self-harm/instructions
- sexual
- sexual/minors
- violence
- violence/graphic
category_applied_input_types:
type: object
description: A list of the categories along with the input type(s) that the score applies to.
properties:
hate:
type: array
description: The applied input type(s) for the category 'hate'.
items:
type: string
enum:
- text
x-stainless-const: true
hate/threatening:
type: array
description: The applied input type(s) for the category 'hate/threatening'.
items:
type: string
enum:
- text
x-stainless-const: true
harassment:
type: array
description: The applied input type(s) for the category 'harassment'.
items:
type: string
enum:
- text
x-stainless-const: true
harassment/threatening:
type: array
description: The applied input type(s) for the category 'harassment/threatening'.
items:
type: string
enum:
- text
x-stainless-const: true
illicit:
type: array
description: The applied input type(s) for the category 'illicit'.
items:
type: string
enum:
- text
x-stainless-const: true
illicit/violent:
type: array
description: The applied input type(s) for the category 'illicit/violent'.
items:
type: string
enum:
- text
x-stainless-const: true
self-harm:
type: array
description: The applied input type(s) for the category 'self-harm'.
items:
type: string
enum:
- text
- image
self-harm/intent:
type: array
description: The applied input type(s) for the category 'self-harm/intent'.
items:
type: string
enum:
- text
- image
self-harm/instructions:
type: array
description: The applied input type(s) for the category 'self-harm/instructions'.
items:
type: string
enum:
- text
- image
sexual:
type: array
description: The applied input type(s) for the category 'sexual'.
items:
type: string
enum:
- text
- image
sexual/minors:
type: array
description: The applied input type(s) for the category 'sexual/minors'.
items:
type: string
enum:
- text
x-stainless-const: true
violence:
type: array
description: The applied input type(s) for the category 'violence'.
items:
type: string
enum:
- text
- image
violence/graphic:
type: array
description: The applied input type(s) for the category 'violence/graphic'.
items:
type: string
enum:
- text
- image
required:
- hate
- hate/threatening
- harassment
- harassment/threatening
- illicit
- illicit/violent
- self-harm
- self-harm/intent
- self-harm/instructions
- sexual
- sexual/minors
- violence
- violence/graphic
required:
- flagged
- categories
- category_scores
- category_applied_input_types
required:
- id
- model
- results
x-oaiMeta:
name: The moderation object
example: "{\n \"id\": \"modr-0d9740456c391e43c445bf0f010940c7\",\n \"model\": \"omni-moderation-latest\",\n \"results\": [\n {\n \"flagged\": true,\n \"categories\": {\n \"harassment\": true,\n \"harassment/threatening\": true,\n \"sexual\": false,\n \"hate\": false,\n \"hate/threatening\": false,\n \"illicit\": false,\n \"illicit/violent\": false,\n \"self-harm/intent\": false,\n \"self-harm/instructions\": false,\n \"self-harm\": false,\n \"sexual/minors\": false,\n \"violence\": true,\n \"violence/graphic\": true\n },\n \"category_scores\": {\n \"harassment\": 0.8189693396524255,\n \"harassment/threatening\": 0.804985420696006,\n \"sexual\": 1.573112165348997e-6,\n \"hate\": 0.007562942636942845,\n \"hate/threatening\": 0.004208854591835476,\n \"illicit\": 0.030535955153511665,\n \"illicit/violent\": 0.008925306722380033,\n \"self-harm/intent\": 0.00023023930975076432,\n \"self-harm/instructions\": 0.0002293869201073356,\n \"self-harm\": 0.012598046106750154,\n \"sexual/minors\": 2.212566909570261e-8,\n \"violence\": 0.9999992735124786,\n \"violence/graphic\": 0.843064871157054\n },\n \"category_applied_input_types\": {\n \"harassment\": [\n \"text\"\n ],\n \"harassment/threatening\": [\n \"text\"\n ],\n \"sexual\": [\n \"text\",\n \"image\"\n ],\n \"hate\": [\n \"text\"\n ],\n \"hate/threatening\": [\n \"text\"\n ],\n \"illicit\": [\n \"text\"\n ],\n \"illicit/violent\": [\n \"text\"\n ],\n \"self-harm/intent\": [\n \"text\",\n \"image\"\n ],\n \"self-harm/instructions\": [\n \"text\",\n \"image\"\n ],\n \"self-harm\": [\n \"text\",\n \"image\"\n ],\n \"sexual/minors\": [\n \"text\"\n ],\n \"violence\": [\n \"text\",\n \"image\"\n ],\n \"violence/graphic\": [\n \"text\",\n \"image\"\n ]\n }\n }\n ]\n}\n"
_MisalignmentSteer:
properties:
message:
type: string
description: The public continuation instruction.
type: object
required:
- message
Error:
type: object
properties:
code:
anyOf:
- type: string
- type: 'null'
message:
type: string
param:
anyOf:
- type: string
- type: 'null'
type:
type: string
misalignment:
$ref: '#/components/schemas/MisalignmentErrorDetailsResource'
required:
- type
- message
- param
- code
ErrorResponse:
type: object
properties:
error:
$ref: '#/components/schemas/Error'
required:
- error
MisalignmentErrorDetailsResource:
properties:
error_type:
$ref: '#/components/schemas/_MisalignmentErrorType'
description: An optional classification; clients must accept additional values.
detailed_explanation:
type: string
description: The public explanation for this block.
steer:
$ref: '#/components/schemas/_MisalignmentSteer'
description: An optional public continuation instruction.
type: object
required: []
responses:
InferenceRateLimited:
description: The request was rejected because a rate limit was exceeded. A slow_down error means traffic increased too quickly; reduce your request rate, then increase it gradually.
headers:
Retry-After:
description: The minimum number of seconds to wait before retrying. This header is returned when the server has computed a retry delay and may be omitted.
schema:
type: integer
minimum: 1
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
examples:
slowDown:
summary: Traffic increased too quickly
value:
error:
message: Your request rate increased too quickly. Please reduce the request rate and gradually increase it again.
type: rate_limit_error
param: null
code: slow_down
InferenceServiceUnavailable:
description: The service is temporarily unavailable. A server_is_overloaded error means the requested model is temporarily overloaded; retry after a brief delay.
headers:
Retry-After:
description: The minimum number of seconds to wait before retrying. This header is returned when the server has computed a retry delay and may be omitted.
schema:
type: integer
minimum: 1
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
examples:
serverOverloaded:
summary: The requested model is temporarily overloaded
value:
error:
message: The model is temporarily overloaded. Please retry your request after a brief delay.
type: service_unavailable_error
param: null
code: server_is_overloaded
securitySchemes:
ApiKeyAuth:
type: http
scheme: bearer
AdminApiKeyAuth:
type: http
scheme: bearer
x-oaiMeta:
navigationGroups:
- id: responses
title: Responses API
- id: webhooks
title: Webhooks
- id: endpoints
title: Platform APIs
- id: vector_stores
title: Vector stores
- id: chatkit
title: ChatKit
beta: true
- id: containers
title: Containers
- id: live
title: Live (alpha)
- id: realtime
title: Realtime
- id: chat
title: Chat Completions
- id: assistants
title: Assistants
deprecated: true
- id: administration
title: Administration
- id: legacy
title: Legacy
groups:
# --- truncated at 32 KB (58 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/openai/refs/heads/main/openapi/openai-moderations-api-openapi.yml