Skip to content

Latest commit

 

History

History
202 lines (140 loc) · 6.79 KB

File metadata and controls

202 lines (140 loc) · 6.79 KB

🧠 Sentiment Analysis API

Free, Open-Source Sentiment Analysis API — Built for Speed, Privacy & Scale

License: MIT Cloudflare Workers Zero Dependencies Edge Native

The fastest free open-source sentiment analysis API on the planet.
Zero latency. Zero data sold. Zero cost.

Live API Docs →  |  Try It Free →  |  Star on GitHub ⭐


What is the Sentiment Analysis API?

The Sentiment Analysis API is a free, open-source, lightning-fast NLP API that processes any text and returns a clear sentiment score — whether it's POSITIVE, NEGATIVE, NEUTRAL, or MIXED — in milliseconds.

Unlike cloud-based NLP services that charge per call, require accounts, or harvest your data, this API:

  • 🚀 Runs at the edge — deployed on Cloudflare's global network (300+ locations) so every request is served from the datacenter closest to your user
  • 🔒 Respects user privacy — PII (emails, phone numbers, card numbers) is automatically masked before any data is stored
  • 💸 100% Free — MIT licensed, self-hostable in under 5 minutes
  • Sub-2ms response times — no external API calls, no cold starts, pure edge compute

Whether you're building a product review analyzer, social media sentiment dashboard, customer feedback tool, or brand monitoring system — this API is the fastest way to get started.


✨ Features

Feature Description
🎯 4-Way Sentiment Classification POSITIVE, NEGATIVE, NEUTRAL, MIXED — not just a binary result
📊 Detailed Scores Confidence score, magnitude, positive/negative sub-scores
🔑 Keyword Extraction Top keywords from the text, stop-word filtered
🌍 Language Detection Auto-detects English, Russian, Arabic, Hindi, Chinese, and more
🔐 PII Auto-Masking Emails, phone numbers, and card numbers masked before storage
📈 Comprehensive Analytics Every request logged with geo, device, and performance data
📖 Interactive Docs Full Swagger UI available at /docs
🌐 OpenAPI 3.0 Machine-readable spec at /openapi.json
♾️ CORS Enabled Works from any browser, mobile app, or server

🚀 Quick Start

Analyze text in one cURL command:

curl -X POST https://your-api.workers.dev/analyze \
  -H "Content-Type: application/json" \
  -d '{"text": "I absolutely love this product! The quality is outstanding."}'

Response:

{
  "success": true,
  "data": {
    "label": "POSITIVE",
    "score": 0.9124,
    "magnitude": 0.7231,
    "positive_score": 0.8800,
    "negative_score": 0.0200,
    "keywords": ["love", "product", "quality", "outstanding"],
    "token_count": 12,
    "sentence_count": 1,
    "language_hint": "en"
  },
  "meta": {
    "ray_id": "8a1b2c3d4e5f0000",
    "execution_time_ms": 1.45,
    "api_version": "1.0.0"
  }
}

📦 Use Cases

  • E-commerce — Analyze product reviews at scale
  • Customer Support — Automatically flag negative feedback tickets
  • Social Media Monitoring — Track brand sentiment on Twitter/Reddit/news
  • Content Moderation — Pre-screen text for emotional extremes
  • Survey Analysis — Process open-ended responses instantly
  • Chatbots & AI Agents — Give your LLM app emotional awareness
  • Market Research — Gauge public sentiment on topics and trends

🛠️ Self-Host in 5 Minutes

This API is entirely self-hostable on your own Cloudflare Workers account (free tier is more than sufficient):

# 1. Clone the repo
git clone https://github.com/your-org/Sentiment-Analysis-API.git
cd Sentiment-Analysis-API

# 2. Install dependencies
npm install

# 3. Create the D1 database
npx wrangler d1 create saa_db
# → Copy the database_id into wrangler.toml

# 4. Run the schema migration
npm run db:init:remote

# 5. Deploy to Cloudflare Workers
npm run deploy

Your private API is live in under 5 minutes. No servers to manage, no scaling to worry about.


📡 API Reference

Method Endpoint Description
POST /analyze Analyze text sentiment
GET /health Health check
GET /docs Interactive Swagger UI
GET /openapi.json OpenAPI 3.0 specification

Request Body (POST /analyze)

Field Type Required Description
text string ✅ Yes The text to analyze (1–50,000 chars)
language string ❌ No ISO 639-1 language hint (e.g. "en")

🔒 Privacy First

We designed this API with privacy as a first-class feature:

  • No user accounts required — call the API directly
  • PII Auto-Masking — emails, phone numbers, and card numbers are masked (u***@domain.com, *******1234) before storage
  • No data sold — analytics are used only for API health monitoring
  • Self-hostable — deploy to your own Cloudflare account; your data never touches our servers

⚡ Why Cloudflare Workers?

Traditional NLP APIs run on centralized servers. If you're in Mumbai and the server is in Virginia, you're paying 300ms+ in round-trip latency before the first byte.

This API runs on Cloudflare's edge network — 300+ locations worldwide. Your request is handled by the datacenter nearest to you, typically in under 5ms network round-trip. Combined with our sub-2ms processing time, you get extremely fast, real-time sentiment analysis at global scale.


📊 Performance Benchmarks

Metric Value
⚡ Average Response Time < 5ms (edge-local)
🧮 Processing Time (server-side) < 2ms
📈 Max Text Length 50,000 characters
🌍 Global Coverage 300+ edge locations
📦 Cold Start None (Cloudflare Workers, always warm)

🤝 Contributing

This is a community project. PRs, issues, and feature requests are welcome!

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/AmazingFeature
  3. Commit your changes: git commit -m 'Add AmazingFeature'
  4. Push to the branch: git push origin feature/AmazingFeature
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License — see LICENSE for details.

Free forever. No strings attached.


Built with ❤️ using Cloudflare Workers · Powered by edge computing

⭐ If this project helped you, please star it on GitHub!