Skip to main content

Quick start

1. Get an API key​

Sign in to the dashboard, pick a project at the top of the page, open API keys and press Create key. The key is shown once, so copy it.

export SAFETY_API_KEY=sk_…
Keep the key on your server

Never put it in a browser or mobile app. Anyone who has it can spend your credit.

2. Install​

npm install @chidakashi-ai/safety

Needs Node 18 or newer.

3. Save a policy set​

A policy set is your rules, under a name.

import { Policies } from '@chidakashi-ai/safety';

const creds = { apiKey: process.env.SAFETY_API_KEY! };

await new Policies(creds).save('chat', `
1) No threats of violence against another person.
2) No sharing of someone's home address or phone number.
`);

Saving usually takes under a minute. Do it once, for example when you deploy, not on every request. You can also write policy sets in the dashboard's Policy manager.

4. Check something​

import { SafetyClient, isSafe } from '@chidakashi-ai/safety';

const client = new SafetyClient(creds);

const result = await client.checkText('I am going to find him and beat him', 'chat', { showReason: true });
// { verdict: 'block', reason: 'Violated this rule: "No threats of violence against another person." …' }

if (!isSafe(result)) {
// block it
}

Images work the same way:

const result = await client.checkImage('./upload.jpg', 'chat');

Use isSafe(result) rather than verdict === 'block': images can also come back unknown, which isn't safe either.

Each check uses a little of your organization's credit. New organizations get some free credit to start. See Credit and billing.

Next​