SvelteKit Profanity Filter

Use a SvelteKit server route (+server.js) to keep the key server-side, then call it from your components.

Quick start in SvelteKit

// src/routes/api/moderate/+server.js
import { PROFANITY_API_KEY } from "$env/static/private";

export async function POST({ request }) {
  const { text } = await request.json();
  const r = await fetch("https://api.theprofanityapi.com/v1/check", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${PROFANITY_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ text, context: "comment", mode: "balanced" }),
  });
  return new Response(await r.text(), {
    headers: { "Content-Type": "application/json" },
  });
}

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 →