DEV Community

CBT Tools
CBT Tools

Posted on

How to Add CBT Thought Analysis to Your App in 3 Lines (via RapidAPI)

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())
Enter fullscreen mode Exit fullscreen mode

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."
}
Enter fullscreen mode Exit fullscreen mode

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();
Enter fullscreen mode Exit fullscreen mode

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."}'
Enter fullscreen mode Exit fullscreen mode

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:

  1. Server-side analysis (Python/Node backends, not browser)
  2. Batch processing (analyze 10,000 journal entries)
  3. 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

  1. Go to RapidAPI and search "CBT Thought Analyzer"
  2. Subscribe to the free tier (100 requests/month)
  3. 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)