---
title: "OpenAI Moderation API Guide: Screen User Input in 5 Steps"
description: "Screen user input with the OpenAI Moderation API before your main model call: curl and Python examples, result fields, thresholds, and a blocking flow."
url: https://cdnping.org/en/blog/openai-moderation-api-guide
language: en
published: 2026-11-14
category: "Developer tools"
tags: ["OpenAI","Moderation","Content moderation","API security","Developer tools"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# OpenAI Moderation API Guide: Screen User Input in 5 Steps

The OpenAI Moderation API is an endpoint that checks whether text (and, for some models, images) contains harmful content. The pattern is simple: send the user's input to `/v1/moderations` first, read `flagged` and the per-category results, then decide whether to call your main model. Whether it is billed and what limits apply are covered in OpenAI's current documentation, so check there.

If your app forwards user input straight to OpenAI, whatever your end users send counts against your API organization. Screening it first is a cheap way to protect yourself.

## Why moderate in your own app first?

OpenAI's usage policies apply to every request made with your API key, whether you wrote the content or your users did. If too much violating content gets through, your organization can be warned, restricted, or even suspended. The exact handling is defined by OpenAI's official usage policies.

So any public-facing product (chatbot, support tool, writing assistant) should have at least two layers:

- Moderate user input before the request, and reject violations without sending them to the main model.
- Where needed, moderate the model's output as well.

Internal scripts are low risk and can skip this, but as soon as strangers can type text into your product, add it.

## How do you call it?

The endpoint is `POST https://api.openai.com/v1/moderations`, authenticated with a Bearer key like any other endpoint. Check the official docs for the current model name. The examples use `omni-moderation-latest` from the omni family, which the docs say accepts image input in addition to text.

curl example:

```bash
curl https://api.openai.com/v1/moderations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "omni-moderation-latest",
    "input": "User text to be moderated"
  }'
```

Python example with the official SDK:

```python
from openai import OpenAI

client = OpenAI()
resp = client.moderations.create(
    model="omni-moderation-latest",
    input="User text to be moderated",
)
result = resp.results[0]
print(result.flagged)
print(result.categories)
print(result.category_scores)
```

`input` can be a single string or an array of strings. With an array, `results` returns one result per item, in order.

## What do the result fields mean?

Each item in `results` has three main groups of data:

| Field | Meaning |
| --- | --- |
| `flagged` | Boolean. True if any category is judged to be a violation |
| `categories` | One boolean per category: whether it was triggered |
| `category_scores` | One score from 0 to 1 per category. Higher means the model is more confident |

With omni models you also get `category_applied_input_types`, which says whether each category was triggered by text or by an image.

Category names include harassment, hate, illicit, self-harm, sexual, and violence, plus their subcategories (for example `harassment/threatening`, `self-harm/intent`, `sexual/minors`, `violence/graphic`). For the complete, current list, go by the official docs and do not hard-code assumptions about it.

## Should you tune the thresholds yourself?

You can start by using `flagged` as is. The official docs note that `category_scores` are not strict probabilities and that scores may shift as the model is updated. If you set custom thresholds, calibrate them on your own data rather than copying someone else's numbers.

A practical middle path:

1. Block on `flagged` first, and log the blocked samples.
2. Sample and manually review items whose `category_scores` are high but which were not flagged.
3. If your use case is especially sensitive to a category (for example, a product aimed at minors), set a stricter threshold for that category alone.

## 5-step integration checklist

1. Call the API from your server and never expose the key in the frontend. See [How to use OpenAI project API keys](/en/blog/openai-project-api-keys-permissions) to create a dedicated project key for moderation with limited permissions.
2. When user input arrives, call Moderation first, then the main model.
3. When `flagged` is true, return a fixed refusal message. Do not expose all the category details to the user.
4. Log the time, user identifier, and triggered categories, but do not store more of the original text than you need. For privacy requirements, see [What is Zero Data Retention](/en/blog/zero-data-retention-explained).
5. Set a timeout and retries on the moderation call. For parameter syntax, see [How to configure OpenAI SDK timeout and retries](/en/blog/openai-anthropic-sdk-timeout-retry-config).

Decide your policy for when the moderation service is unavailable: let requests through (user experience first) or reject them (safety first). For public-facing products, rejecting or degrading is the more common choice, but it depends on your business.

## Is passing moderation enough?

No. Moderation is only a filter. It cannot guarantee that every violation is caught, and it does not replace your own terms of use, rate limits, and human review. It is also a good idea to set a spending limit so a bill does not spiral if your app is abused. See [How to set a spending limit and usage alerts for the OpenAI API](/en/blog/openai-api-set-spending-limit).

Also, the extra call in the request path adds a little latency. You can check recent probe results for the official API endpoint on [cdnping's OpenAI status page](/en/status/openai) to tell whether a problem is on your side or an upstream fluctuation.

## New to APIs? How to choose an access route

If you are still choosing how to connect, the common routes are the official API, cloud-provider hosting, and aggregation gateways. For a side-by-side comparison, see [How to choose an AI API access route](/en/blog/official-api-vs-cloud-vs-gateway).

AGI Plan is a commercial partner of cdnping. It is a multi-provider LLM aggregation gateway with monthly subscriptions, payment in RMB, and no overseas credit card required. Tools such as Claude Code and Codex work by changing a single endpoint address. Some models are marked as available outside China only; the [AGI Plan models page](https://agiplan.dev/models) is the source of truth. The service states that it is not an officially authorized channel. Whether a specific endpoint like Moderation is forwarded by a gateway depends on that service's documentation, so check it first and do not assume it works. To see the setup steps, read the [AGI Plan quick start](https://agiplan.dev/startup).

## Next steps

- Run the curl command above locally once and compare the responses for normal text and violating text.
- Add moderation to your request entry point and log the blocked samples.
- Also check your key permissions and spending limits, and prepare an emergency procedure using [What to do if your OpenAI API key leaks](/en/blog/openai-api-key-leaked-response).
