Moderations

Checks text and images against content categories with a moderation model on your own worker. OpenAI-compatible.

POST /v1/moderations

Checks text or images with a moderation model on one of your workers, and says for each input whether it was flagged and in which categories. Use it to screen what users send, or what a model wrote before you show it.

It follows the OpenAI moderations format, so OpenAI clients work with a Pendra base URL. It also answers at /api/v1/moderations.

Install a moderation model

Install one from the catalogue on a worker, like any other model. The content you send is checked on your own worker.

ModelChecksGood to know
llama-guard3:1bllama-guard3:8b Text The 8B catches more and flags less by mistake. The 1B is much faster.
qwen3guard:0.6bqwen3guard:4bqwen3guard:8b Text, in many languages Can answer borderline. Larger sizes catch more.
singguard:0.8bsingguard:4b Text and images The 4B catches more. The 0.8B suits small GPUs.
Body application/json
model string Required
The moderation model to use, installed on one of your workers.
input string | string[] | object[] Required
What to check:
  • A string, for one result.
  • Up to 32 strings, for one result each, in order.
  • Up to 32 text and image_url parts, checked together for one result, so an image and its caption are judged as a whole.

Checking images

Send images as parts, to a model that checks images such as singguard:4b:

{
  "model": "singguard:4b",
  "input": [
    { "type": "text", "text": "Profile photo for a new account" },
    { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,/9j/4AAQ..." } }
  ]
}

A base64 data: URL always works. An https:// URL works only if the worker's owner has turned on Allow remote image URLs, as for images in chat.

Response

results has one entry per string, or one for a set of parts. Each has:

  • flagged, true if the model judged it unsafe.
  • categories, true for each category it falls into.
  • category_scores, the same as numbers: 1.0, 0.0, or 0.5 for a qwen3guard borderline verdict, which still counts as flagged.
  • category_applied_input_types, whether each category was judged on text, image or both.

Only the categories the model checks are included. A missing category means the model doesn't check it, not that the content is clean. The pendra field names the worker that ran the check.

Categories

Pendra uses OpenAI's category names where one fits, and adds its own under pendra/. Which ones each model checks:

Categoryllama-guard3qwen3guardsingguard
harassment ✓✓✓
hate ✓✓✓
illicit ✓✓✓
illicit/violent ✓✓No
self-harm ✓✓✓
sexual ✓✓✓
sexual/minors ✓NoNo
violence ✓✓✓
pendra/cyber ✓✓No
pendra/disinformation ✓✓✓
pendra/fraud ✓✓✓
pendra/intellectual_property ✓✓No
pendra/nudity No✓✓
pendra/privacy ✓✓No
pendra/specialized_advice ✓NoNo
pendra/unspecified ✓✓✓
  • pendra/cyber is malware and intrusion, pendra/nudity includes non-sexual nudity, and pendra/specialized_advice is unqualified medical, legal or financial advice.
  • pendra/unspecified means flagged without a named category.
  • llama-guard3:1b lists pendra/cyber but never sets it. Only the 8B checks it.
  • qwen3guard reports sexual content involving minors as sexual, and a jailbreak attempt as pendra/unspecified.

Errors

Errors carry a code in error.code and the X-Pendra-Error-Code header, so you can handle them without reading the message. See Moderation errors for every code. Also:

  • Input longer than the model's context gets a 400 with no code. Shorten or split it.
  • A malformed body, such as more than 32 inputs, gets a 422.
  • A check that runs for more than about 80 seconds can fail after a 200. Treat any response without results as not checked.

End-to-end encryption

With end-to-end encryption turned on in the Pendra SDK, your worker reads the content and encrypts the verdict back to you, so Pendra sees neither. It needs Python SDK 0.19.0 or Node SDK 0.18.0 or later, and a recent worker.

To check encrypted chat automatically instead, turn on content filtering for the API key.

Try it in the Playground

Open Moderation mode in the Playground, then paste text or attach an image to see each category's verdict.

Good to know

  • The endpoint only returns verdicts. It never blocks anything, so what to do with flagged content is up to you. A model can miss harmful content or flag harmless content, so treat it as one signal.
  • The usage log records each check's outcome (pass, flagged or error) and flagged categories, never the content. An encrypted check records no verdict.
  • Each string in an array is checked one after another, so 32 strings take about 32 times as long as one. A small model such as llama-guard3:1b usually answers in well under a second.
  • A check can wait behind a long chat reply on the same worker. If you check every request, put the moderation model on a less busy worker.
  • To use one particular worker, send the X-Pendra-Worker-Id header.