Unprofane

Move a Node client off the Perspective API

googleapis builds a client from a discovery document. Ours names api.unprofane.com as its root, so the same methods call Unprofane.

Tested with googleapis 185.0.0, on every run of the snippet checks. How

Node.js

What changes

googleapis
const client = await google.discoverAPI(Remove: 'https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1',Add: 'https://api.unprofane.com/$discovery/rest?version=v1alpha1',);const res = await client.comments.analyze({key: process.env.UNPROFANE_KEY, // up_test_YOUR_KEY on staging, up_live_YOUR_KEY in productionresource: {comment: { text: 'you are a clown' },requestedAttributes: { TOXICITY: {} },languages: ['en'],doNotStore: true,},});

1 line changes. Build the client with google.discoverAPI from the Unprofane discovery URL and keep the calls.

Tested with googleapis 185.0.0, on every run of the snippet checks.

  • Unchanged
  • The path
  • The request body
  • The response
  • The errors
  • The ?key= parameter

1. Make an Unprofane key for each environment

Sign in and make two keys on the keys page of the dashboard: a test key (up_test_…) for staging and a live key (up_live_…) for production. A test key is free and answers 100 checks a month across the account; a live key needs a plan. Keep your Google key: it is your way back until Google’s service ends on December 31, 2026.

2. Discover the client from Unprofane

google.discoverAPI fetches our discovery document and builds comments.analyze and comments.suggestscore from it, aimed at the root the document names. Read the key from the environment, so staging and production differ only in the value. Every call after it is unchanged.

import { google } from 'googleapis';

const client = await google.discoverAPI(
  'https://api.unprofane.com/$discovery/rest?version=v1alpha1',
);
const res = await client.comments.analyze({
  key: process.env.UNPROFANE_KEY, // up_test_YOUR_KEY on staging, up_live_YOUR_KEY in production
  resource: {
    comment: { text: 'you are a clown' },
    requestedAttributes: { TOXICITY: {} },
    languages: ['en'],
    doNotStore: true,
  },
});
console.log(res.data.attributeScores.TOXICITY.summaryScore.value);

3. Check it on staging

Run your own tests against staging with the test key. A refusal rejects with Google’s status as error.code and Google’s words in error.message.

4. Set the threshold on staging

Do not carry the old number over: the scores come from a different engine, so 0.8 there is not 0.8 here. The replay tool takes a CSV of recent texts with the scores Perspective gave them and shows, for each old threshold, the threshold here that flags the same share, and how often the two flags agree. A queue of the same size is not proof of the same accuracy: two thresholds can flag the same number of comments and disagree on which ones, and agreement with Perspective repeats its mistakes. Before production, run a sample your moderators have already decided (approved and removed) through staging, and for each candidate threshold count the removed items it catches and the approved items it flags. Read the disagreements, then choose.

What carries over, and what does not

Carries over

  • The path /v1alpha1/comments:analyze, the request body and the response shape: attributeScores with summaryScore and spanScores, languages, detectedLanguages.
  • The error envelope (code, message, status) and Google’s words for each refusal, with Google’s status.
  • The key as ?key=, the first one when a client sends two, or as an X-Goog-Api-Key header.
  • comments:suggestscore, answered with {} as Google answered it.
  • The client’s methods, comments.analyze and comments.suggestscore, and its errors.

Not supported

  • The other New York Times attributes (LIKELY_TO_REJECT, SPAM, INFLAMMATORY and the rest) and the bridging attributes are not scored: a request for one is refused as Google refused an attribute it did not know, or left out with dropUnsupportedAttributes.
  • A moderator’s score sent to suggestscore is kept as a correction on your account, beside the score we gave, and read by a person; it changes no score until a later engine.
  • Google’s account errors (a key restricted to a referrer or an address, the API not enabled, billing) have no counterpart: a key here is valid or it is not.

Scored differently

  • The scores come from a different engine: the rules give each attribute a floor from the matched words and the model’s reading lifts the rest. Until the Civil Comments calibration ships, the scale is the engine’s own rather than a fit to Perspective’s.
  • A RAW score is the same number as the probability.
  • Some comments Google refused are scored: languages it did not score (Hebrew, Turkish and others), SEXUALLY_EXPLICIT outside English, and HTML comments read without their tags.
  • With spanAnnotations, each sentence’s span is scored by the rules on that sentence alone; the summary score is the whole engine’s.

Roll back

Discover from Google’s URL again and put your Google key back. This works until Google’s service ends on December 31, 2026.

const client = await google.discoverAPI(
  'https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1',
);

How it was tested

Tested with googleapis 185.0.0 on every run of the snippet checks: this guide’s code as printed with a test key and a live key, then two refusals, a bad key and a suggestscore, against a local Unprofane API. It passed against the real model on October 13, 2026, and its rollback against Google’s own API on October 13, 2026.

Then

Sources