Moderation
Last updated: 2026-11-09T06:47:11-03:00 (UTC-3)
POST /v1/moderations follows the OpenAI Moderation API: send text, a list of texts or text with images, and get back, per input, whether it is flagged and a score for each harm category. The gateway puts its usual controls in front of it: the key, the team, rate limits, the request log and the trace. It replaces the alias with the provider’s model and passes everything else through unchanged, in both directions.
Flag: moderations. The alias declares the moderations capability and the key needs the route:moderations scope.
How to turn it on
Section titled “How to turn it on”features: moderations: true # omitted = off: the route answers 404 feature_disabledproviders: - id: openai protocol: openai base_url: https://api.openai.com/v1 api_key_env: OPENAI_API_KEYmodels: - id: moderation capabilities: [moderations] targets: [{provider: openai, model: omni-moderation-latest}] - id: moderation-pinned # a fixed snapshot: scores do not move under you capabilities: [moderations] targets: [{provider: openai, model: omni-moderation-2024-09-26}]keys: - id: content-review principal: content-review team: trust-safety kind: service_account sha256_env: CONTENT_REVIEW_KEY_SHA256 allowed_models: [moderation, moderation-pinned] scopes: ["route:moderations"]team_policies: - team: trust-safety allowed_models: [moderation, moderation-pinned] scopes: ["route:moderations"]- Models:
omni-moderation-latestfollows OpenAI’s current model, which OpenAI upgrades over time;omni-moderation-2024-09-26is the pinned snapshot. If you block oncategory_scoresthresholds, pin the snapshot or recalibrate when the latest model changes. OpenAI’s reference also liststext-moderation-latestandtext-moderation-stable, which accept text only. - OpenAI project: if the project restricts models, allow the moderation models in it; otherwise OpenAI answers 403, and the client receives that 403.
- Price: OpenAI does not charge for moderation, and the response reports no usage (see What is recorded).
- Console and API: the flag changes from Settings & sources or
PUT /api/v1/admin/features/moderationswithout a restart (withfeature_management); the alias and key are edited like any other (inference flags, keys and teams).
Requests
Section titled “Requests”model is the gateway alias. input is one of:
input |
Results | Models |
|---|---|---|
| A string | One | All |
| An array of strings | One per string, in order | All |
An array of parts: {"type": "text", "text": ...} and {"type": "image_url", "image_url": {"url": ...}} |
One for the whole input | omni-moderation-* |
image_url.url is either an https URL, which the provider downloads (the gateway never fetches it), or a base64 data URL such as data:image/png;base64,....
curl http://localhost:8080/v1/moderations \ -H "Authorization: Bearer $GATEWAY_API_KEY" \ -H 'Content-Type: application/json' \ -d '{"model": "moderation", "input": "Have a nice day at the park."}'Several texts at once
Section titled “Several texts at once”curl http://localhost:8080/v1/moderations \ -H "Authorization: Bearer $GATEWAY_API_KEY" \ -H 'Content-Type: application/json' \ -d '{"model": "moderation", "input": ["I love sunny weather.", "The library opens at nine."]}'Text and an image
Section titled “Text and an image”curl http://localhost:8080/v1/moderations \ -H "Authorization: Bearer $GATEWAY_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "model": "moderation", "input": [ {"type": "text", "text": "Is this photo fine to publish?"}, {"type": "image_url", "image_url": {"url": "https://images.example/photo.jpg"}} ] }'With a data URL instead, the image travels in the request:
{"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."}}Python SDK
Section titled “Python SDK”The official openai package works unchanged; only the base URL and the key change:
from openai import OpenAI
client = OpenAI(base_url="https://gateway.example.com/v1", api_key=GATEWAY_API_KEY)
result = client.moderations.create(model="moderation", input="Have a nice day at the park.")print(result.results[0].flagged)
image = client.moderations.create( model="moderation", input=[ {"type": "text", "text": "Is this photo fine to publish?"}, {"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KGgo..."}}, ],)print(image.results[0].category_applied_input_types.violence) # ['text', 'image']Always pass model. The OpenAI API defaults to omni-moderation-latest when model is missing, but on the gateway model names an alias, so a request without it answers 400 invalid_model.
Response
Section titled “Response”The provider’s body comes back intact (shortened here to three of the 13 categories):
{ "id": "modr-4a1b...", "model": "omni-moderation-latest", "results": [ { "flagged": false, "categories": {"violence": false, "sexual": false, "illicit": false}, "category_scores": {"violence": 0.0004, "sexual": 0.00002, "illicit": 0.000005}, "category_applied_input_types": {"violence": ["text", "image"], "sexual": ["text", "image"], "illicit": ["text"]} } ]}| Field | Meaning |
|---|---|
id |
The provider’s ID for this moderation |
model |
The provider’s model that answered (omni-moderation-latest or the snapshot), not the gateway alias |
results[].flagged |
true when any category is flagged |
results[].categories |
One boolean per category; OpenAI may send null for illicit and illicit/violent |
results[].category_scores |
One score from 0 to 1 per category |
results[].category_applied_input_types |
Per category, which inputs the score covers: text, image or both |
The 13 categories are harassment, harassment/threatening, hate, hate/threatening, illicit, illicit/violent, self-harm, self-harm/intent, self-harm/instructions, sexual, sexual/minors, violence and violence/graphic. Seven are scored on text only (harassment, harassment/threatening, hate, hate/threatening, illicit, illicit/violent and sexual/minors): for an image-only input their score is 0. The other six (self-harm, self-harm/intent, self-harm/instructions, sexual, violence and violence/graphic) cover images too. The response headers carry X-Request-Id, traceparent and X-Gateway-Provider (the connection that answered).
Treat the scores as input to your own policy. To block requests to other models automatically, use the moderation guardrail, which calls this route as the caller.
Errors
Section titled “Errors”The gateway’s own refusals happen before any provider call and use its error shape, {"error": {"code": ..., "message": ...}}:
| Status | code |
When |
|---|---|---|
| 400 | invalid_model |
model is missing or not a string |
| 400 | invalid_request |
The body is not a JSON object |
| 401 | unauthorized |
The gateway key is missing or invalid |
| 403 | scope_forbidden |
The key lacks route:moderations |
| 403 | model_forbidden |
The alias is outside the key’s or the team’s allowlist. The allowlist is checked first, so an alias that does not exist also answers this unless the key’s list matches it (for example *): the answer does not reveal which aliases exist |
| 403 | entitlement_forbidden |
With plans, the team’s plan does not include the route, or exact_cache for a cacheable request sent with X-Gateway-Cache: allow |
| 404 | feature_disabled |
The moderations flag is off |
| 404 | model_not_found |
The alias does not exist or is disabled, and the key’s allowlist matches the name |
| 413 | request_too_large |
The body exceeds the route’s limit (see below) |
| 415 | unsupported_media_type |
The body is not application/json |
| 422 | capability_unsupported |
The alias does not declare moderations |
| 422 | quota_profile_unsupported |
A budget or token ceiling applies to the request (see Budgets and TPM); the message ends with (reason: unsupported_operation_or_routing) |
| 429 | rate_limit_exceeded, concurrency_limit_exceeded |
A rate or concurrency policy refused the request |
| 503 | entitlement_unavailable |
With plans, the team’s plan could not be read; the provider is not called |
| 503 | quota_unavailable |
budget_limits or tpm_limits is on and quota storage did not answer; the provider is not called |
Provider errors pass through as received, the status and the provider’s own body, with one change: where the provider quotes the connection’s provider credential, whole, in pieces or masked, the quote is replaced with [redacted] (see security for exactly what is recognized). The rest of the body, its JSON shape, type, code and param included, is unchanged. Examples seen with OpenAI:
| Status | Provider message | Cause |
|---|---|---|
| 400 | Invalid value for 'model' = ... |
The target names a model OpenAI does not have |
| 400 | Field required (loc: body, input) |
The request has no input |
| 400 | Could not download file from URL provided. (code: image_url_unavailable) |
OpenAI could not download the image URL; a data URL avoids it |
| 401 | Incorrect API key provided: [redacted]. You can find your API key at ... (code: invalid_api_key) |
The connection’s provider credential is wrong; the client’s gateway key was accepted. OpenAI quotes the key’s prefix and last four characters; the gateway removes them, so look the key up in the connection, not in the message |
The official SDKs raise their usual exceptions for these statuses: BadRequestError (400), AuthenticationError (401), PermissionDeniedError (403), NotFoundError (404) and so on. A provider 401 reaches the SDK as AuthenticationError even though the client’s key was fine: check the connection’s credential.
Limits
Section titled “Limits”- Body: 8 MiB by default for this route. Base64 makes an image about a third larger, and OpenAI accepts images up to 20 MB, so raise the limit on the alias for large data URLs:
models[].max_request_body_mib, 1 to 64 MiB (request body limits). An https URL keeps the request small. - Image URLs: the provider downloads them, from its own network. A URL it cannot reach answers
400 image_url_unavailable.
What is recorded
Section titled “What is recorded”With usage_analytics and request_logs on (both on in the bundled configuration), each call appears in the usage events and the request log (Logs in the console, GET /api/v1/admin/logs?operation=moderations) and, with logging.request_events: stdout, as one request audit event:
operation: moderations, the alias, the connection, the status, the duration, the key, principal and team, and the request and trace IDs. Gateway refusals carry theirerror_code.- Tokens: none. The moderation response reports no usage, so input and output tokens are recorded as unknown, not zero.
- Cost: unknown, with the reason
unsupported_operation(usage valuation): the gateway does not invent a price for an answer without usage, even though OpenAI does not charge for it. - No content: neither the input texts, the image URLs or data, nor the scores are stored or logged.
Requests refused before the route is admitted for the key (the flag off, an invalid key, scope_forbidden, or the team plan refusing the route) are not in the request log; they are in the gateway’s structured log with their request ID.
With other features
Section titled “With other features”- Exact cache: with the alias policy and
X-Gateway-Cache: allow, an identical request can reuse a stored verdict. Only inputs that carry their whole content are cacheable: text, and images as data URLs. A request with an imagehttpsURL always goes to the provider, because the image behind a URL can change while the request bytes stay the same; such a request carries noX-Gateway-Cacheheader. OpenAI sets a cookie on every response; that does not keep the verdict out of the cache, because the gateway never sends a cookie to the provider and never passes the provider’s cookie on to the client (see what is stored). - Budgets and TPM: moderation has no quota profile. The response reports no usage, so there is nothing to settle a reservation from, and the gateway refuses a call it cannot measure rather than letting it through uncounted. With
budget_limitsortpm_limitson, a moderation request to which any policy applies (a policy on its key, team, user, project, organization, end user or model alias) answers422 quota_profile_unsupportedwith the reasonunsupported_operation_or_routing, before any provider call and without a reservation, whether the policy is a budget, a token ceiling or both. Requests no policy applies to are unaffected, and so is everything with both flags off. To moderate while budgets are on, send moderation with a request that no policy applies to: a key, team, user, project and organization outside every key, team, user, project and organization policy; anX-Gateway-End-Userthat no end-user policy covers (an end-user policy names a team and applies to each of that team’s end users, so a covered team leaves no safe end user); and an alias no model policy names. The moderation guardrail is different: its check is the gateway’s own call, so it takes no reservation and is never refused for quota or RPM, and none of it is charged to the caller’s budget, TPM, TPD or RPM; the request it guards is counted and reserved as usual. When that request is certain to be refused for quota anyway (settled spending already fills an applicable daily or monthly budget or token-per-day counter, or a ceiling is below the request’s smallest possible reservation), it answers the admission’s429 quota_exceededbefore the check is made, so a provider that bills moderation is not charged for it; this precheck needs the PostgreSQL quota store. The exemption exists only for that in-process call; no header or body field gives it to a client’s request. A provider that bills moderation charges the check to the connection’s account, outside the gateway’s budgets: the check is in the request log and the usage ledger (cost unknown, as above) with the derived request ID<request_id>.guardrail, and its price is on the provider’s bill. - Retries and latency routing: both apply to moderation aliases with an explicit policy; latency routing samples only text inputs.
- Moderation guardrail: sends the text of chat, Messages and Responses requests (and optionally the answers) to a moderations alias as the caller, exempt from budgets, token ceilings and RPM. Requests to
/v1/moderationsare not themselves inspected by guardrails.
Verification
Section titled “Verification”Certified on 2026-11-08 against OpenAI with omni-moderation-latest and omni-moderation-2024-09-26: text, an array of texts, text with an image by https URL and by data URL, the official Python SDK openai 3.37.0 (client.moderations.create), the error cases above and the request log without content. The release gate’s SDK check runs client.moderations.create with a multimodal input against a simulated provider.
See also
Section titled “See also”- Capabilities and routes and inference flags
- Guardrails
- API reference:
POST /v1/moderations