Unprofane

Move a Python client off the Perspective API

The Google client builds itself from a discovery document. Ours names api.unprofane.com as its root, so the client keeps working.

Tested with google-api-python-client 2.201.0, on every run of the snippet checks. How

Python

What changes

google-api-python-client
client = discovery.build("commentanalyzer","v1alpha1",developerKey=os.environ["UNPROFANE_KEY"],  # up_test_YOUR_KEY on staging, up_live_YOUR_KEY in productionRemove: discoveryServiceUrl="https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1",Add: discoveryServiceUrl="https://api.unprofane.com/$discovery/rest?version=v1alpha1",static_discovery=False,)response = client.comments().analyze(body={"comment": {"text": "you are a clown"},"requestedAttributes": {"TOXICITY": {}},"languages": ["en"],"doNotStore": True,}).execute()

1 line changes. Give discovery.build a discoveryServiceUrl on the Unprofane host and keep every call the same.

Tested with google-api-python-client 2.201.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. Change the build call

Pass the Unprofane discovery URL and read the key from the environment, so staging (the test key) and production (the live key) differ only in the value. Everything after the build call is unchanged.

import os
from googleapiclient import discovery

client = discovery.build(
    "commentanalyzer",
    "v1alpha1",
    developerKey=os.environ["UNPROFANE_KEY"],  # up_test_YOUR_KEY on staging, up_live_YOUR_KEY in production
    discoveryServiceUrl="https://api.unprofane.com/$discovery/rest?version=v1alpha1",
    static_discovery=False,
)

response = client.comments().analyze(body={
    "comment": {"text": "you are a clown"},
    "requestedAttributes": {"TOXICITY": {}},
    "languages": ["en"],
    "doNotStore": True,
}).execute()

print(response["attributeScores"]["TOXICITY"]["summaryScore"]["value"])

3. Check it on staging

Run your own tests against staging with the test key. A refusal arrives as an HttpError with Google’s status and words, so the error handling you wrote for Perspective keeps working.

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, its batch requests (new_batch_http_request(), each request answered and counted as if sent alone), and its HttpError.

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

Put Google’s discovery URL and your Google key back. This works until Google’s service ends on December 31, 2026.

discoveryServiceUrl="https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1"

How it was tested

Tested with google-api-python-client 2.201.0 on every run of the snippet checks: this guide’s code as printed with a test key and a live key, then three 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