DEV Community
Perspective API shuts down on December 31. Here's how to replace it by changing one line
Google's Jigsaw is turning off Perspective API. It already stopped accepting new users earlier this year, and after December 31, 2026 it stops answering everyone else. If you run comments, a forum or a chat with Perspective behind it, that's a few weeks from now. Coral's toxic comment filter, the Discourse plugin, Drupal modules and plenty of homemade scripts all call the same endpoint: https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze
This post shows how to point that call somewhere else without rewriting anything. Disclosure: this is written by the team behind VigiMod, the API used in the examples. It's free during the beta. The short version VigiMod exposes the same path and accepts the same JSON. You change the host and the key: - https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key=PERSPECTIVE_KEY
+ https://api.vigimod.com/v1alpha1/comments:analyze?key=VIGIMOD_KEY
The request body stays the same, and the response has the same shape (attributeScores..summaryScore.value), so the code that reads it doesn't change either. Before and after in Python Before: import requests
r = requests.post(
"https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze",
params={"key": PERSPECTIVE_KEY},
json={
"comment": {"text": message},
"languages": ["en"],
"requestedAttributes": {"TOXICITY": {}, "INSULT": {}, "THREAT": {}},
},
)
scores = {k: v["summaryScore"]["value"] for k, v in r.json()["attributeScores"].items()}
flagged = scores["TOXICITY"] >= 0.8
After: import requests
r = requests.post(
"https://api.vigimod.com/v1alpha1/comments:analyze", # new host
params={"key": VIGIMOD_KEY}, # new key
json={
"comment": {"text": message},
"languages": ["en"],
"requestedAttributes": {"TOXICITY": {}, "INSULT": {}, "THREAT": {}},
},
)
scores = {k: v["summaryScore"]["value"] for k, v in r.json()["attributeScores"].items()}
flagged = scores["TOXICITY"] >= 0.8
With curl curl -s "https://api.vigimod.com/v1alpha1/comments:analyze?key=$VIGIMOD_KEY" \
- H "Content-Type: application/json" \
- d '{"comment": {"text": "you are an idiot"},
"requestedAttributes": {"TOXICITY": {}, "INSULT": {}}}'
{
"attributeScores": {
"TOXICITY": {"summaryScore": {"value": 1.0, "type": "PROBABILITY"}},
"INSULT": {"summaryScore": {"value": 0.9998, "type": "PROBABILITY"}}
}
}
With Node.js const r = await fetch(
https://api.vigimod.com/v1alpha1/comments:analyze?key=${process.env.VIGIMOD_KEY},
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
comment: { text: message },
requestedAttributes: { TOXICITY: {}, PROFANITY: {} },
}),
},
);
const { attributeScores } = await r.json();
const toxicity = attributeScores.TOXICITY.summaryScore.value;
Coral, Discourse and Drupal Coral. In Admin → Configure → Moderation, under the Toxic Comment Filter, set the Perspective endpoint to https://api.vigimod.com/v1alpha1 and paste your VigiMod key. If your Coral version has a timeout for the check (older versions use TALK_PERSPECTIVE_TIMEOUT, 300 ms by default), give it some room, around 1000 ms: when the answer arrives late, Coral skips the score. Discourse. The official Perspective plugin calls Google's host directly and has no setting for it. In your copy of the plugin, replace commentanalyzer.googleapis.com with api.vigimod.com, and put the VigiMod key in perspective_google_api_key. Drupal and everything else. Any module or script that lets you set the Perspective URL works as is. If the URL is hardcoded, it's one line. Which attributes are supported Perspective attribute Scored from TOXICITY toxicity SEVERE_TOXICITY hate and threats (a message that is only rude stays under 0.7) IDENTITY_ATTACK hate INSULT insults THREAT threats SEXUALLY_EXPLICIT sexual content PROFANITY (and OBSCENE) swearing and vulgar language FLIRTATION flirting and sex...
Powered by Readybot.io
External Link
Platform
You are about to visit:
https://example.comThis will open in a new tab. Make sure you trust this link.