Trust2API

SpamGuard API

Classify text as spam or not-spam with a fast Naive Bayes + rules engine. Ideal for comments, forms, and UGC.

Project Description: SpamGuard API (RapidAPI)

SpamGuard is a lightweight, production-ready HTTP API for classifying user-generated content (e.g., comments, messages, reviews) as spam or not-spam. It combines two complementary detectors—Naive Bayes and a rule-based “Snooker” engine—to provide fast, explainable results suitable for moderation pipelines, forms, and community platforms.

  • Base RapidAPI URL: https://spamguard-api1.p.rapidapi.com
  • Required header x-rapidapi-host: spamguard-api1.p.rapidapi.com

How It Works

  1. You send a JSON payload describing the content to check.
  2. The API runs two analyzers:
    • Naive Bayes: A probabilistic classifier trained to estimate the likelihood of spam.
    • Snooker: A lightweight rule/heuristic-based checker tuned for short texts like blog comments.
  3. The API returns:
    • An overall is_spam boolean decision.
    • Per-engine details: score (confidence/likelihood) and is_spam for both snooker and bayes.

The combined signal lets you build policies such as auto-block, flag-for-review, or allow-with-throttling.

When To Use It

  • Moderating blog comments, contact forms, support tickets, and forum posts.
  • Pre-screening UGC before publishing.
  • Enriching existing moderation systems with a separate, explainable signal.

Authentication (RapidAPI)

Requests must include your RapidAPI key and host headers:

  • X-RapidAPI-Key: <YOUR_RAPIDAPI_KEY>
  • X-RapidAPI-Host: spamguard-api1.p.rapidapi.com

Endpoint

  • POST /verify — Classify content as spam or not.

Request URL:

https://spamguard-api1.p.rapidapi.com/verify

Request Model

  • content (string, required): Text to classify; may include HTML.
  • url (string, optional): A related URL that may help detection.
  • author (string, optional): Author’s display name.

Max request body size: 4 MB.

Example JSON body:

{
  "content": "Get our special promotion",
  "url": "https://getpromo.xyz?getit=free",
  "author": "James Bond"
}

Sample Requests

  • cURL:
curl -X POST \
  'https://spamguard-api1.p.rapidapi.com/verify' \
  -H 'X-RapidAPI-Host: spamguard-api1.p.rapidapi.com' \
  -H 'X-RapidAPI-Key: <YOUR_RAPIDAPI_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
    "content": "Get our special promotion",
    "url": "https://getpromo.xyz?getit=free",
    "author": "James Bond"
  }'
  • JavaScript (fetch):
const res = await fetch('https://spamguard-api1.p.rapidapi.com/verify', {
  method: 'POST',
  headers: {
    'X-RapidAPI-Host': 'spamguard-api1.p.rapidapi.com',
    'X-RapidAPI-Key': process.env.RAPIDAPI_KEY,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({
    content: 'Get our special promotion',
    url: 'https://getpromo.xyz?getit=free',
    author: 'James Bond'
  })
});
const data = await res.json();
console.log(data);
  • PowerShell (Invoke-RestMethod):
$response = Invoke-RestMethod \
  -Method Post \
  -Uri 'https://spamguard-api1.p.rapidapi.com/verify' \
  -Headers @{ \
    'X-RapidAPI-Host' = 'spamguard-api1.p.rapidapi.com'; \
    'X-RapidAPI-Key'  = $env:RAPIDAPI_KEY; \
    'Content-Type'    = 'application/json'; \
    'Accept'          = 'application/json' \
  } \
  -Body (@{ \
    content = 'Get our special promotion'; \
    url     = 'https://getpromo.xyz?getit=free'; \
    author  = 'James Bond' \
  } | ConvertTo-Json)

$response

Sample Response

{
  "is_spam": true,
  "details": {
    "snooker": {
      "score": -1.0,
      "is_spam": true
    },
    "bayes": {
      "score": 0.79583853,
      "is_spam": false
    }
  }
}
  • is_spam: Overall decision you can act on immediately.
  • details.snooker and details.bayes provide transparency and tunability.

Status Codes

  • 200 OK — Classification succeeded.
  • 400 Bad Request — Invalid or oversized payload, or schema issues.
  • 401 Unauthorized — Missing/invalid RapidAPI credentials.

Quick Start (What to Do)

  1. Get access:
    • Sign in to RapidAPI and subscribe to the SpamGuard API.
    • Copy your X-RapidAPI-Key from the dashboard.
  2. Integrate the /verify endpoint in your service:
    • Add headers X-RapidAPI-Key and X-RapidAPI-Host.
    • Send JSON with at least the content field.
  3. Act on the response:
    • If is_spam is true, block or flag the content.
    • Optionally inspect details to build nuanced rules (e.g., flag only if both engines agree, or if a score threshold is met).
  4. Monitor and iterate:
    • Log results and decisions.
    • Adjust your thresholds per channel (comments vs. contact forms, etc.).

Implementation Notes (How It Works Internally)

  • Naive Bayes: Uses token frequencies to compute posterior probabilities of spam vs. ham; robust to noisy text and efficient for short messages.
  • Snooker: Applies curated heuristics (keyword patterns, link density, suspicious TLDs, etc.) to generate a quick, interpretable signal.
  • Ensemble Decision: The API returns both signals and a consolidated is_spam decision designed for safe defaults while leaving room for custom policies.

Best Practices

  • Always send Accept: application/json and Content-Type: application/json.
  • Sanitize user input (strip dangerous HTML) on your side regardless of classification.
  • Rate-limit inbound form submissions to reduce abuse and cost.
  • Use details to create channel-specific policies.
  • Log the request context (never raw secrets) and the full response to aid audits.

Troubleshooting

  • 401 Unauthorized: Verify your RapidAPI subscription and ensure headers X-RapidAPI-Key and X-RapidAPI-Host are set.
  • 400 Bad Request: Check JSON schema, ensure content is present, and the body is < 4 MB.
  • Network/CORS: For browsers, use a backend proxy if your environment blocks custom headers.

FAQ

  • Can I rely solely on is_spam? Yes—is_spam is a sensible default. Use details for more nuanced workflows.
  • Does the API support HTML? Yes, content may contain HTML; still sanitize on your side.
  • What’s the max payload? 4 MB.

Changelog Highlights

  • Dual-engine classification (Naive Bayes + Snooker)
  • Per-engine scores and booleans for transparency
  • OpenAPI schema and interactive Scalar UI (local feature)

Contact and Support

Use your RapidAPI subscription dashboard for quota and billing. For technical issues or feature requests, open an issue on the project repository or contact the API provider via RapidAPI support.