Files
LocalAI/docs/content/features/moderation.md
localai-org-maint-bot 133c546c3f feat(api): add text moderation endpoint (#11316)
* feat(api): add text moderation endpoint

Add an OpenAI-compatible /v1/moderations endpoint backed by constrained local text generation. Register its auth and discovery surfaces, document the text-only MVP, and cover response shaping and access control.

Assisted-by: Codex:gpt-5

* test(mcp): update assistant client stub

Keep the LocalAI Assistant holder test stub aligned with the scheduling methods added to LocalAIClient so repository-wide type checking succeeds.\n\nAssisted-by: Codex:gpt-5

---------

Co-authored-by: localai-org-maint-bot <306269227+localai-org-maint-bot@users.noreply.github.com>
2026-08-03 18:03:46 +02:00

1.2 KiB

+++ disableToc = false title = "Moderation" weight = 65 url = "/features/moderation/" +++

LocalAI exposes an OpenAI-compatible text moderation endpoint at POST /v1/moderations. It uses a local text-generation model with a constrained JSON grammar, so no separate moderation service or cloud API is required.

curl http://localhost:8080/v1/moderations \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-instruct-model",
    "input": "Text to classify"
  }'

input may be one string or an array of strings. The response contains one result per input with flagged, categories, category_scores, and category_applied_input_types fields. The category names match the OpenAI moderation API, including harassment, hate, illicit activity, self-harm, sexual content, and violence categories.

The selected model must support text completion. For consistent results, use an instruction-tuned model that follows safety-classification prompts well. LocalAI constrains the output shape, but the model determines the classification quality and confidence scores.

{{% notice note %}}

This first implementation supports text only. OpenAI-style multimodal input objects containing images return a validation error.

{{% /notice %}}