Moderations¶
If your app already asks OpenAI's moderation model whether a text is harmful, keep doing so through the gateway: the check itself becomes a recorded call, under the same key and policies as the rest of your traffic.
What it is¶
POST /v1/moderations, OpenAI's classifier for harmful text and images. It exists only in OpenAI's world: the gateway
passes it on unchanged to OpenAI and Azure OpenAI. Other providers have no equivalent, so a call naming one of
their models gets a 400.
Moderations is your app's own check. Vidai's guardrails and VidaiGuard checks run in the gateway on every call whether you use it or not.
The two settings¶
The same as for the OpenAI SDK: base address https://<your-gateway>/v1 and your Vidai key. See
OpenAI SDK for Python.
A minimal call¶
from openai import OpenAI
client = OpenAI()
result = client.moderations.create(
model="omni-moderation-latest",
input="I want to return my order.",
)
print(result.results[0].flagged)
import OpenAI from "openai";
const client = new OpenAI();
const result = await client.moderations.create({
model: "omni-moderation-latest",
input: "I want to return my order.",
});
console.log(result.results[0].flagged);
curl https://<your-gateway>/v1/moderations \
-H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" \
-d '{"model": "omni-moderation-latest", "input": "I want to return my order."}'
Name the model: the gateway routes by model, so the moderation model must be one your organisation approved under
Models. A call with no model (OpenAI's own default) gets 400 bad_request, "Missing required field: 'model'".
Reading what the gateway did¶
Use client.moderations.with_raw_response.create(...) (Python) or .withResponse() (TypeScript) and read
x-vidai-request-id, as shown on Chat Completions.
Errors¶
The codes are those of Chat Completions. Specific to this endpoint: a model on another provider gets a 400, and nothing is sent.
What goes through the gateway¶
| Feature | Through the gateway |
|---|---|
moderations.create, text and image input |
Yes, to OpenAI and Azure OpenAI |
| Other providers | No: a 400 |
Check it works in a minute¶
Run the curl above. An answer with results means the address, key and model are right.
Good to know¶
- A moderation call is charged and recorded like any other call: give a moderation step its own key if you want its cost apart in Cost and Request logs.
- The answer's
resultsare for your app to act on: the gateway passes them back unchanged.