If you build apps for mental health, journaling, or self-improvement, you probably want to detect cognitive distortions in user text. But training an NLP model takes weeks and thousands of labeled examples.
I built a CBT Thought Analyzer API that detects 12 cognitive distortions (catastrophizing, all-or-nothing thinking, mind reading, etc.) in plain text — no training data, no ML pipeline, just an API call.
It is live on RapidAPI. Here is how to use it.
3 Lines of Python
import requests
response = requests.post(
"https://cbt-thought-analyzer.p.rapidapi.com/analyze",
headers={"X-RapidAPI-Key": "YOUR_KEY", "X-RapidAPI-Host": "cbt-thought-analyzer.p.rapidapi.com"},
json={"text": "I failed this task. I am a complete failure. Nothing will ever work out."}
)
print(response.json())
Output:
{
"distortions": [
{"name": "all-or-nothing-thinking", "confidence": 0.92, "excerpt": "I am a complete failure"},
{"name": "catastrophizing", "confidence": 0.85, "excerpt": "Nothing will ever work out"},
{"name": "labeling", "confidence": 0.78, "excerpt": "I am a complete failure"}
],
"summary": "3 distortions detected. Consider reframing with evidence-based alternatives."
}
3 Lines of JavaScript
const res = await fetch("https://cbt-thought-analyzer.p.rapidapi.com/analyze", {
method: "POST",
headers: {"X-RapidAPI-Key": "YOUR_KEY", "X-RapidAPI-Host": "cbt-thought-analyzer.p.rapidapi.com", "Content-Type": "application/json"},
body: JSON.stringify({text: "I failed this task. I am a complete failure."})
});
const data = await res.json();
3 Lines of curl
curl -X POST https://cbt-thought-analyzer.p.rapidapi.com/analyze \
-H "X-RapidAPI-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "I failed this task. I am a complete failure."}'
Why an API instead of a library?
I open-sourced the CBT Toolkit — 36 free browser-based tools, vanilla JS, no dependencies. But some developers need:
- Server-side analysis (Python/Node backends, not browser)
- Batch processing (analyze 10,000 journal entries)
- No setup (no npm install, no pip install, just an API key)
The RapidAPI listing handles all three. Free tier = 100 requests/month.
The 12 Distortions Detected
| Distortion | Example |
|---|---|
| All-or-nothing thinking | "I am a complete failure" |
| Catastrophizing | "Nothing will ever work out" |
| Labeling | "I am an idiot" |
| Mind reading | "They think I am incompetent" |
| Fortune telling | "I will definitely fail" |
| Emotional reasoning | "I feel guilty, so I must be guilty" |
| Personalization | "The team failed because of me" |
| Should statements | "I should never make mistakes" |
| Overgeneralization | "This always happens to me" |
| Mental filter | (focuses only on the negative) |
| Disqualifying the positive | "That success does not count" |
| Jumping to conclusions | (assumes worst without evidence) |
Try it free
- Go to RapidAPI and search "CBT Thought Analyzer"
- Subscribe to the free tier (100 requests/month)
- Copy the 3-line snippet above
No credit card needed for the free tier.
Full disclosure: I am the creator. The CBT Toolkit is 100% free and open-source (36 browser tools, vanilla JS). The API is for developers who need server-side analysis without self-hosting. If you just need browser-based tools, use the free toolkit.
Top comments (0)