FastAPI Profanity Filter

Add async moderation to FastAPI endpoints with httpx so you don't block the event loop.

Quick start in FastAPI

import os, httpx
from fastapi import HTTPException

@app.post("/comments")
async def create_comment(text: str):
    async with httpx.AsyncClient() as client:
        r = await client.post(
            "https://api.theprofanityapi.com/v1/check",
            headers={"Authorization": f"Bearer {os.environ['PROFANITY_API_KEY']}"},
            json={"text": text, "context": "comment", "mode": "balanced"},
        )
    if r.json()["flagged"]:
        raise HTTPException(422, "flagged")

Why context-aware matters

A plain word list flags "this game is sick" or medical text full of anatomical terms. The Profanity API runs a five-layer pipeline that scores intent, so "die" in a gaming taunt and "die" in a real threat are handled differently. Pick a context and the engine adjusts strictness automatically.


Other integrations

Ready to ship moderation?

Get an API key and 300 free requests a month. No credit card required.

Get started free →