Unprofane
DocsCompatibility

Perspective API compatibility

The exact contract of the Perspective-compatible endpoint. What is the same as Google's API, request for request and error for error, and what is not.

Google’s Perspective API shuts down after December 31, 2026 (Google’s notice). https://api.unprofane.com/v1alpha1/comments:analyze answers the same request with the same response and the same error envelope, so a client moves by changing its base URL and its key. Coral takes https://api.unprofane.com/v1alpha1 as its custom endpoint; Discourse’s plugin hardcodes Google’s host, so it takes a one-line fork and a rebuild.

This page is the contract, field by field. To move a client step by step, start at the migration hub; to see how the two score on the same judged texts, read Unprofane vs the Perspective API.

Shell
curl -X POST "https://api.unprofane.com/v1alpha1/comments:analyze?key=up_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"comment":{"text":"you are a clown"},"requestedAttributes":{"TOXICITY":{}},"languages":["en"],"doNotStore":true}'

What is the same#

  • The path, the request body, the response shape (attributeScores, summaryScore, spanScores), the error envelope with code, message and status.
  • The errors themselves. Before launch we sent Google a request for each way a request can go wrong (the key, the body, each field’s type, the attributes, the languages, the size, the quota), and every answer we give is Google’s, word for word, with the same status. A test replays all of them against the API on every change.
  • The production attributes: TOXICITY, SEVERE_TOXICITY, IDENTITY_ATTACK, INSULT, PROFANITY, THREAT, SEXUALLY_EXPLICIT, and the experimental aliases. FLIRTATION is answered as SEXUALLY_EXPLICIT, and OBSCENE, whose definition is the same as PROFANITY’s, as PROFANITY.
  • The key as ?key= (the first one, when a client sends two), as an X-Goog-Api-Key header, or as a bearer header with an Unprofane key.
  • The JSON Google read: any content type, a gzip body, single quotes, bare keys, trailing commas, snake_case field names, a list given as one string, a number given as a string, a byte that is not UTF-8 read as a space, and the same nesting limit.
  • Google’s query parameters: prettyPrint=false for compact JSON, fields to keep some fields (and Google’s refusal of a mask it cannot read), alt=json (other alt values refused as Google refused them), quotaUser and the $ forms. A request field set in the query (?comment.text=…) is bound as Google bound it, and a form body is read as query parameters, as Google read it.
  • A browser’s preflight, and the CORS headers on every answer to a request that names its origin. The path with a trailing slash, or with extra leading slashes (//v1alpha1/comments:analyze, which a client sends when it joins a base URL ending in / to a path), and X-HTTP-Method-Override.
  • Google’s batch endpoint, POST /batch, where googleapiclient’s new_batch_http_request() sends its requests (the discovery document’s batchPath). The layout is Google’s, the Content-ID comes back as Google sent it, and each part is answered as the same request sent alone: its own key, limits, refusals and usage, so a batch of ten comments is ten checks. The request’s headers reach every part, and a part’s own header wins. A nested batch, a part for a path the API does not have, and a body that is not a batch are refused in Google’s words.
  • spanScores: one span over the whole comment, or one per sentence with spanAnnotations. scoreThreshold leaves out an attribute under it, scoreType takes PROBABILITY and RAW, and clientToken comes back.
  • doNotStore is honored: this endpoint keeps no text, whether it is set or not. (The /v1 check endpoints keep the texts they check for 90 days; see privacy.)
  • comments:suggestscore is answered with {}, as Google answered it. Where Google kept a moderator’s score for itself, it reaches us: the comment and each attribute’s suggested score are stored as a correction on your account, beside the score we gave, and every one is read (see feedback). At most the account’s hourly corrections are stored; the rest are answered and not stored.

What is different#

  • Scores come from a different engine. The rules give each attribute a floor from the matched words; the model’s reading lifts the rest. The replay tool takes a CSV of your texts with their old scores and maps your thresholds onto ours. The old scores never leave your browser; the texts are checked like any other check made on the site, so they are kept for 90 days.
  • With spanAnnotations, each sentence’s span is scored by the rules on that sentence alone; the summary score is the whole engine’s.
  • A byte that is not UTF-8, or half of an escaped emoji pair, is a space to Google and a masked letter to our engine: a word broken by one (“di\xffkhead”) is read as the word, where Google’s reading let it through. What the response shows (the accepted request, the offsets) is Google’s.
  • A RAW score is the same number as the probability: the engine has no separate raw scale.
  • The other New York Times attributes (ATTACK_ON_AUTHOR, ATTACK_ON_COMMENTER, INCOHERENT, INFLAMMATORY, LIKELY_TO_REJECT, SPAM, UNSUBSTANTIAL) and the bridging attributes (AFFINITY_EXPERIMENTAL, COMPASSION_EXPERIMENTAL, CURIOSITY_EXPERIMENTAL, NUANCE_EXPERIMENTAL, PERSONAL_STORY_EXPERIMENTAL, REASONING_EXPERIMENTAL, RESPECT_EXPERIMENTAL) are not scored: a request for one answers the error Google gives an attribute it does not know (Unknown requested attribute), or leaves it out when dropUnsupportedAttributes is set.
  • Where Google refused and we can answer, we answer: a comment in a language Google detected but did not score (Hebrew, Turkish and the rest are scored), a comment Google found no language in at all (a run of one letter, an escaped half of an emoji pair), unless it is blank, SEXUALLY_EXPLICIT in every language the other attributes take (Google scored it in English only), and an HTML comment (Google refused it; we score the text without its tags). Languages you name in languages are held to Google’s list, as Google held them.
  • A secret key sent from a browser (a page’s fetch) is refused with PERMISSION_DENIED, where Google answered: in a page, the key is visible to every visitor. Call from your server.
  • A query string Google’s front end found too long (a 411 and its HTML page) is read.
  • A body larger than the route’s byte limit is refused before it is read, where Google read far larger ones to say the comment was too long.
  • A batch answers at most 100 parts whose comments hold 30,000 characters together, and reads at most 256 KiB, where Google answered every part it was sent. A batch over any of them is refused whole with INVALID_ARGUMENT; send more as several batches.
  • A spent minute answers Google’s quota error with your project in place of Google’s project number and our plans as the place to ask for more. A spent month or a spent daily test cap answers RESOURCE_EXHAUSTED in our own words, since Google had neither.
  • A wrong path or method answers 404, as Google’s did, with a JSON body where Google sent its HTML error page.
  • Our own failure answers 500 INTERNAL with Google’s standard words for its own. Google’s other 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.
  • Every response also carries Unprofane-Engine and Unprofane-Route headers, and the usage counts as one check per request.
  • Until the Civil Comments calibration ships, the scores are the engine’s own scale rather than a fit to Perspective’s. The replay tool says which is in force.

Thresholds#

Do not carry the old number over: 0.8 there is not 0.8 here. The replay tool shows, for each old threshold, the threshold here that flags the same share of your texts 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 through staging with a test key, count for each candidate threshold the removed items it catches and the approved items it flags, and read the disagreements. Keep your Google key until the switch is done: it is the way back until Google’s service ends.

Guides by client#

Each guide names the version it was checked against, a staging check, the thresholds and how to roll back.

  • Coral Talk: set Custom endpoint to https://api.unprofane.com/v1alpha1 and the API key to an Unprofane key.
  • Discourse: fork the plugin, change GOOGLE_API_DOMAIN, rebuild, and put an Unprofane key in perspective_google_api_key. A Discourse you cannot add plugins to cannot run the fork.
  • Python, googleapiclient: pass our discovery URL to discovery.build.
  • Node, googleapis: build the client with google.discoverAPI from our discovery URL.
  • Raw HTTP: change the host.

To score a list of texts or an Apify dataset without a client, run the Unprofane Actor on Apify with an Unprofane key and the Perspective output: it calls this endpoint and writes each attribute’s summary score as a column.