Anti-Spam
Docs pages

Quick start

Send your first check in a few minutes. Using WordPress? The WordPress plugin does this for you.

Get your key

Start free and add your site. Its API key is on the site page in your dashboard. Keep the key on your server and never put it in code that runs in the browser.

Send a check

Send each comment or form entry from your server before you save it, with a new Idempotency-Key each time.

POSThttps://api.anti-spam.store/v1/check
curl
curl -X POST https://api.anti-spam.store/v1/check \
  --max-time 5 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 3f1c8a2e-5b8d-4c1e-9a7b-3d2e1f0a9b8c" \
  -d '{"source":"form","fields":[{"type":"name","value":"Jane Cooper"},{"type":"email","value":"jane@acmeshop.com"},{"type":"textarea","value":"Hello, I would like a quote"}]}'
Node.js
import { randomUUID } from "node:crypto";

const result = await fetch("https://api.anti-spam.store/v1/check", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "Idempotency-Key": randomUUID(), // a new one for each entry
  },
  body: JSON.stringify({
    source: "form",
    fields: [
      { type: "name", value: name },
      { type: "email", value: email },
      { type: "textarea", value: message },
    ],
  }),
  signal: AbortSignal.timeout(5000), // also covers reading the answer
})
  .then((res) => (res.ok ? res.json() : null))
  .catch(() => null); // if we do not answer in time or the answer cannot be read, let the entry through

if (result && result.status === "checked" && result.is_spam === true) {
  // mark the entry as spam
}
PHP
<?php
// A new Idempotency-Key (a UUID) for each entry
$id = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4));
$ch = curl_init('https://api.anti-spam.store/v1/check');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 5, // if we do not answer in time, let the entry through
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer YOUR_API_KEY',
        'Content-Type: application/json',
        'Idempotency-Key: ' . $id,
    ],
    CURLOPT_POSTFIELDS     => json_encode([
        'source' => 'form',
        'fields' => [
            ['type' => 'name', 'value' => $name],
            ['type' => 'email', 'value' => $email],
            ['type' => 'textarea', 'value' => $message],
        ],
    ]),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// if we do not answer in time or the answer cannot be read, let the entry through
$result = is_string($body) && $status === 200 ? json_decode($body, true) : null;
if (is_array($result) && ($result['status'] ?? '') === 'checked' && ($result['is_spam'] ?? null) === true) {
    // mark the entry as spam
}

Use the answer

200 OK
{
  "detection_id": "6f1c2a9e-5b8d-4c1e-9a7b-3d2e1f0a9b8c",
  "status": "checked",
  "spam_probability": 0.97,
  "is_spam": true
}
  • When status is "checked" and is_spam is true, mark the entry as spam.
  • Anything else, including an error, means no verdict: let the entry through.
If we do not answer in time, let the entry through. Set a client timeout of 5 seconds, as the WordPress plugin does.

Next, read how to check a submission in full.