npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

safetygates

v0.2.0

Published

Official SDK for SafetyGates content moderation API

Downloads

316

Readme

SafetyGates SDK for Node.js

Official Node.js client for SafetyGates content moderation API.

Installation

npm install safetygates

Quick Start

const SafetyGates = require('safetygates');

const client = new SafetyGates('sg_live_your_api_key');

// Classify text
const result = await client.classify('you suck at this game', ['toxic', 'harassment']);
console.log(result.results.toxic.label);      // true
console.log(result.results.toxic.confidence); // 0.92

// Convenience methods
if (await client.isToxic('some message')) {
  console.log('Message blocked');
}

Get Your API Key

Sign up for free at sg-api.cyclecore.ai/signup

  • Free tier: 1,000 requests/day
  • No credit card required

API Reference

Constructor

const client = new SafetyGates(apiKey, options);

| Parameter | Type | Description | |-----------|------|-------------| | apiKey | string | Your API key (required) | | options.baseUrl | string | API URL (default: https://sg-api.cyclecore.ai) | | options.timeout | number | Request timeout in ms (default: 10000) |

classify(text, gates)

Classify a single text.

const result = await client.classify('hello world', ['toxic', 'spam']);

// Result:
{
  results: {
    toxic: { label: false, confidence: 0.12 },
    spam: { label: false, confidence: 0.08 }
  },
  latency_us: 1234.5
}

classifyBatch(texts, gates)

Classify multiple texts (up to 10,000).

const result = await client.classifyBatch(
  ['hello', 'you suck', 'nice game'],
  ['toxic']
);

// Result:
{
  results: [
    { toxic: { label: false, confidence: 0.1 } },
    { toxic: { label: true, confidence: 0.94 } },
    { toxic: { label: false, confidence: 0.05 } }
  ],
  total_latency_us: 3456.7,
  items_per_second: 867.5
}

isToxic(text, threshold?)

Convenience method to check toxicity.

if (await client.isToxic(message)) {
  // Block message
}

// With custom threshold
if (await client.isToxic(message, 0.8)) {
  // Only block if >80% confident
}

isSpam(text, threshold?)

Convenience method to check spam.

if (await client.isSpam(message)) {
  // Block spam
}

listGates()

Get available classification gates.

const { gates } = await client.listGates();
// [{ id: 'toxic', category: 'moderation', ... }, ...]

Available Gates

| Gate | Language | Description | |------|----------|-------------| | toxic | English | Toxic/abusive content | | spam | English | Spam/promotional | | hate | English | Hate speech | | nsfw | English | Adult content | | harassment | English | Harassment/bullying | | toxic_es | Spanish | Toxic content | | spam_es | Spanish | Spam | | hate_es | Spanish | Hate speech | | toxic_pt | Portuguese | Toxic content | | toxic_fr | French | Toxic content |

Use the GATES constant for autocomplete:

const { GATES } = require('safetygates');
client.classify(text, [GATES.TOXIC, GATES.SPAM]);

Error Handling

const { SafetyGatesError } = require('safetygates');

try {
  await client.classify('test', ['invalid_gate']);
} catch (err) {
  if (err instanceof SafetyGatesError) {
    console.log(err.statusCode); // 400
    console.log(err.detail);     // { detail: "Unknown gates: ['invalid_gate']" }
  }
}

Discord Bot Example

const SafetyGates = require('safetygates');
const { Client, GatewayIntentBits } = require('discord.js');

const sg = new SafetyGates(process.env.SAFETYGATES_KEY);
const discord = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });

discord.on('messageCreate', async (message) => {
  if (message.author.bot) return;

  if (await sg.isToxic(message.content, 0.7)) {
    await message.delete();
    await message.channel.send(`${message.author}, please keep it civil.`);
  }
});

discord.login(process.env.DISCORD_TOKEN);

TypeScript

Full TypeScript support included:

import SafetyGates, { ClassifyResult, GATES } from 'safetygates';

const client = new SafetyGates('sg_live_xxx');
const result: ClassifyResult = await client.classify('test', [GATES.TOXIC]);

Links

License

MIT