Perspective API

⭐ Beginner's Pick Machine Learning / API Key Intermediate HTTPS
Varies by plan (check documentation)

Overview

Perspective is a free NLP API from Jigsaw (Google) that scores text for toxic, obscene, insulting, or threatening content, returning a probability between 0 and 1 for each attribute. It is widely used for building comment moderation systems and community safety tools. The API supports multiple languages and can analyze text for a range of harmful content types.

💡

Beginner Tip

Use a threshold of 0.7 or higher for the TOXICITY attribute when auto-moderating comments—lower thresholds can produce too many false positives for legitimate content. Always combine automated scoring with human review for edge cases.

Available Data

Perspective data via REST API
JSON-formatted response data
Requires API key authentication

Example Response

JSON Response
{
  "url": "https://example.com",
  "safe": true,
  "threat_level": "none",
  "categories": [
    "clean"
  ],
  "scan_date": "2025-01-15T10:00:00Z"
}

Field Reference

attributeScores Map of requested attribute names to their score objects (e.g., TOXICITY, INSULT, THREAT).
attributeScores.TOXICITY.summaryScore.value Probability score from 0 to 1 that the text is toxic; scores above 0.7 are generally considered high risk.
attributeScores.TOXICITY.summaryScore.type Scoring type used, typically 'PROBABILITY' indicating a probability estimate.
languages List of language codes detected in or specified for the analyzed text.
detectedLanguages Languages automatically detected in the submitted comment text.

Implementation Example

const url = "https://perspectiveapi.com/";
// Replace headers or query params with the values required by this API.
const response = await fetch(url, {
  headers: {
  "X-API-Key": "YOUR_API_KEY"
  }
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

Common Errors & Troubleshooting

400 Bad Request: API key not valid API key is missing, incorrect, or the Perspective API is not enabled in your Google Cloud project
Enable the Perspective API at perspectiveapi.com, then create an API key in Google Cloud Console and add it as the key query parameter.
400 LANGUAGE_NOT_SUPPORTED The text language is not supported by the requested attribute
Check the Perspective API supported languages list—not all attributes support all languages. Use 'en' for the broadest attribute support.
429 Resource Exhausted: Quota exceeded Default quota is only 1 QPS (query per second) for new projects
Add a delay between requests or apply for a quota increase through the Perspective API quota request form in your Google Cloud project.

Matrix Score Breakdown

🌐 Reachability 30/30
⚡ Speed 10/20
🔒 Security 15/15
🛠 Developer XP 12/20
✓ Reliability 10/15

Partially tested on Apr 5, 2026

Technical Specifications

Auth API Key
HTTPS REQUIRED
CORS UNKNOWN
Category Machine Learning
Difficulty Intermediate
Verified: 2026-04-04

Similar APIs

View All →