Node.js
← Full documentation
Node.js integration guide
Add spam detection to Express, Fastify, Next.js, or any Node.js app. Uses native fetch (Node 18+) — no extra dependencies needed.
Authentication: All requests need a Bearer token in the
Authorization header. Generate one in Settings → API Tokens.
Helper function (native fetch)
const KIREIFILTER_TOKEN = process.env.KIREIFILTER_TOKEN;
async function checkSpam({ type, content, metadata = {} }) {
const res = await fetch('https://kireifilter.net/api/v1/spam-check', {
method: 'POST',
headers: {
'Authorization': `Bearer ${KIREIFILTER_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ type, content, metadata }),
});
if (!res.ok) throw new Error(`KireiFilter error: ${res.status}`);
return res.json();
}
module.exports = { checkSpam };
Express contact form route
const { checkSpam } = require('./spamCheck');
router.post('/contact', async (req, res) => {
const { message } = req.body;
const { isSpam, score } = await checkSpam({
type: 'comment',
content: message,
metadata: { ip: req.ip },
});
if (isSpam)
return res.status(422).json({ error: 'Submission rejected' });
// send email notification...
res.json({ status: 'sent' });
});
Response fields
| Field | Type | Description |
|---|---|---|
| isSpam | boolean | true if score ≥ 0.5 |
| score | number | 0.0 (clean) to 1.0 (spam). Spam threshold is 0.5. |
| reasons | string[] | Detection signals that contributed to the score |