← Blog

Claude API Content Moderation Pipeline Setup

2026-11-20 · 5 min read · SubToAPI Team

Setting up a content moderation pipeline with the Claude API means sending user-generated content to Claude with a classification prompt, parsing a structured verdict back, and wiring that verdict into your app's moderation logic (block, flag for review, or allow). Unlike purpose-built moderation endpoints, Claude lets you define custom categories, severity levels, and context-aware rules in plain language, which matters when your platform's definition of "unsafe" doesn't match a generic blocklist.

This guide walks through the actual pipeline: the prompt structure, the schema you should ask Claude to return, how to set thresholds, and how to keep latency and cost under control when you're moderating every message, comment, or upload in real time.

Why use Claude instead of a dedicated moderation API

Dedicated moderation endpoints are fast and cheap, but they're trained on fixed categories (hate, violence, sexual content, self-harm) and don't adapt well to domain-specific rules. If you're moderating a trading forum for market manipulation, a dating app for scam patterns, or a kids' platform for age-inappropriate language that's technically "safe" by general standards, a generic classifier misses context Claude can reason about.

The tradeoff is latency and cost per call. A practical setup often runs a cheap first-pass filter (regex, keyword lists, or a lightweight model) and escalates ambiguous or high-risk content to Claude for a nuanced second opinion. That hybrid approach keeps your pipeline fast for the 90% of obviously-fine content while giving you reasoning-grade judgment on the rest.

Step 1: Define your moderation categories

Before writing any code, write down the categories you actually need to detect. Vague prompts produce vague results. Be specific:

Step 2: Build the classification prompt

Ask Claude to return structured JSON, not prose. This makes the output parseable and lets you set programmatic thresholds.

SYSTEM PROMPT:
You are a content moderation classifier for a community platform.
Classify the user message against these categories: harassment,
spam, self_harm, scam, other_violation. For each category return
a boolean "flagged" and a "confidence" score from 0 to 1. Also
return an overall "action" field: "allow", "review", or "block".
Respond with JSON only, no explanation.
curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "max_tokens": 300,
    "system": "You are a content moderation classifier... respond with JSON only.",
    "messages": [
      {"role": "user", "content": "USER MESSAGE: \"Reach out to me on Telegram for the real deal, forget the platform fees\""}
    ]
  }'

Expected response body (inside the message content):

{
  "harassment": {"flagged": false, "confidence": 0.02},
  "spam": {"flagged": false, "confidence": 0.1},
  "self_harm": {"flagged": false, "confidence": 0.0},
  "scam": {"flagged": true, "confidence": 0.87},
  "other_violation": {"flagged": false, "confidence": 0.05},
  "action": "block"
}

Step 3: Set thresholds, not single verdicts

Don't let "action": "block" from the model be the only signal you trust. Build your own threshold logic on top of the confidence scores so you can tune sensitivity without changing the prompt:

function decide(classification, thresholds = { block: 0.8, review: 0.5 }) {
  const maxConfidence = Math.max(
    ...Object.values(classification)
      .filter(v => typeof v === "object")
      .map(v => v.confidence)
  );

  if (maxConfidence >= thresholds.block) return "block";
  if (maxConfidence >= thresholds.review) return "review";
  return "allow";
}

This lets you loosen or tighten enforcement per category — self-harm content, for example, usually warrants a lower review threshold than mild spam.

Step 4: Wire it into your application flow

A typical pipeline for user-generated content:

  1. Pre-filter: strip obvious spam with cheap regex/keyword checks before calling Claude.
  2. Classify: send remaining content to Claude via your API integration.
  3. Decide: apply your threshold function to the JSON response.
  4. Act: allow, hold for human review, or block — log the full classification for audit trails.
  5. Escalate: route "review" items into a moderation queue with the original content and Claude's reasoning attached for human moderators.

Keep the system prompt and category list in your codebase, not hardcoded inline, so you can version and test changes without redeploying call sites.

Handling scale and latency

If you're moderating every chat message or comment in real time, synchronous moderation calls add latency to the user-facing request path. Two patterns handle this:

Batch non-urgent content (e.g., overnight review of flagged historical content) into fewer, larger requests where possible to reduce overhead. For streaming use cases, note that moderation classification doesn't need token-by-token streaming — request a single complete JSON response instead of using the streaming endpoint, since you need the full verdict before acting. See /docs/streaming if you're deciding between modes, and /docs/messages for the full request schema.

Running this through SubToAPI

If you're already using Claude through SubToAPI, your moderation pipeline uses the same sub_live_ API key as your other Claude-powered features, with usage tracked separately per key if you create a dedicated key for the moderation service. That's useful for cost attribution — you can see exactly how much of your spend goes to moderation versus your core product without separate billing accounts. Start with /signup for a free trial, check /docs/quickstart for the initial setup, and review /pricing if you're estimating costs across Solo, Team, and Scale tiers based on your expected moderation volume.

Testing your pipeline before launch

Build a test set of known-bad and known-good examples from your actual platform data, including edge cases (sarcasm, context-dependent terms, borderline language). Run it through your pipeline and manually verify the "review" bucket isn't capturing too much (false positives burn moderator time) or too little (false negatives mean violations ship). Tune thresholds against this test set before going live, and re-test whenever you change the system prompt or model version.

questions

Can Claude replace a dedicated moderation API entirely? For most platforms, no — use a cheap pre-filter for obvious cases and Claude for nuanced or ambiguous content. This keeps costs and latency reasonable while still getting context-aware judgment where it matters.

How do I prevent false positives from blocking legitimate users? Use a three-tier action system (allow/review/block) instead of a binary decision, and route "review" cases to human moderators rather than auto-blocking anything below your highest confidence threshold.

Should moderation calls block the user-facing request? Only for high-risk content types like public posts or uploads. For lower-stakes content like chat messages, post first and moderate asynchronously to avoid adding latency to every interaction.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →