AI / Core OpenAI Codex Application Fundamentals Interview Questions
What is the OpenAI moderation API and why is it important for application safety?
The Moderation API classifies text (and now images) against OpenAI's usage policies, detecting harmful content across multiple categories. It is free to use and essential for any application that accepts user-generated content.
from openai import OpenAI client = OpenAI() # Standalone moderation check response = client.moderations.create( model="omni-moderation-latest", input="I want to hurt someone.", ) result = response.results[0] if result.flagged: print("Content flagged!") for category, flagged in result.categories.__dict__.items(): if flagged: print(f" - {category}: score {getattr(result.category_scores, category):.3f}") # Image moderation (omni-moderation-latest supports images): response = client.moderations.create( model="omni-moderation-latest", input=[ {"type": "text", "text": "Check this text"}, {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}} ] ) # Inline moderation with Responses API (2026 feature): response = client.responses.create( model="gpt-5.5", input="User message here", moderation={}, # get moderation scores inline with the response )
| Category | What it detects |
|---|---|
| hate | Content promoting hatred based on protected characteristics |
| harassment | Content targeting individuals with threats or abuse |
| self-harm | Content promoting self-injury or suicide |
| sexual | Explicit or suggestive sexual content |
| violence | Graphic violence or glorification of harm |
| illicit | Instructions for illegal activities |
Best practice: run moderation on user inputs before sending to the model to prevent policy violations. The Moderation API is free - there is no reason not to use it in consumer-facing applications. In 2026, OpenAI added inline moderation scores directly to the Responses API, enabling a single request to get both the model's response and moderation results.
More Related questions...