Pre-publication content filtering
Classify user-submitted text or images before publishing them.
AI & ML · Function
The Moderations API identifies potentially harmful text and image content. Use its category flags and scores to apply application-specific filtering, review, or account-safety policies.
The Moderations API evaluates text and image inputs with a moderation model and returns category flags and scores. Applications can use these results to filter content, route cases for review, or take account-level action.
POST /v1/moderations| Name | Type | Description |
|---|---|---|
model | string | The moderation model to use; the documentation identifies omni-moderation-latest as accepting text and image inputs. |
input | string or array | The text and/or image content to classify. |
A moderation result containing the model, successful result data, category flags and scores, or an error object when moderation cannot complete.
from openai import OpenAI
client = OpenAI()
result = client.moderations.create(
model="omni-moderation-latest",
input=[
{"type":"text","text":"I will hurt you."},
{"type":"image_url","image_url":{"url":"https://example.com/image.png"}}
],
)
print(result.results[0].flagged)
print(result.results[0].categories)This sends text and an image to the moderation endpoint and prints whether any category flagged the input plus the category results.
Classify user-submitted text or images before publishing them.
Request moderation alongside generated output and inspect it before display.
Send flagged cases to human review instead of automatically blocking every result.
Use moderation signals as part of account enforcement workflows.
The endpoint returns moderation results for submitted content, including a flagged boolean, category labels, and category scores. The application should apply its own policy to decide whether to block, review, or otherwise respond.
Follow-up: How would you handle a failed moderation operation? Check whether the result is successful before reading scores, then apply an explicit fail-safe policy appropriate to the application.
The current moderation model handles text and image inputs. It does not classify audio, so audio safety requires a separate control or workflow.
Follow-up: What if the application receives mixed multimodal content? Moderate each supported text or image input and define a separate policy for unsupported modalities.
Moderation can be performed as a separate endpoint request, or moderation scores can be requested alongside generated content. In the latter case, the model still generates normally, so the application must inspect the scores before displaying or acting on the output.
Follow-up: What should happen when generated output is flagged? Hold the output from the user-facing path and route it through the application's enforcement or review policy.
Moderate generated contentomni-moderation-latestModerationResultscategory_scoresflaggedResponses APIChat Completions