Sentiment Analysis API

Sentiment API Documentation

Comprehensive guide to integrate sentiment analysis into your applications. Analyze text sentiment and extract entity-based insights with our powerful API endpoints.

Quick Start

Get up and running with the Sentiment API in minutes

1. Get API Key
Sign up and receive your unique API key for authentication
2. Make Request
Send HTTP requests to our sentiment analysis endpoints
3. Get Results
Receive sentiment scores and analysis in JSON format
Quick Example
cURL Request
curl -X POST "https://api.example.com/sentiment" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "I love this amazing product!"}'

Authentication

Secure your API requests with API key authentication

Getting Your API Key
1

Sign up for an account

Create your developer account at our platform

2

Generate API key

Navigate to API Keys section and create a new key

3

Copy and secure

Copy your API key and store it securely

Using Your API Key

Include your API key in the Authorization header of every request:

Header Format
Authorization: Bearer YOUR_API_KEY_HERE

Security Note

Never expose your API key in client-side code or public repositories. Always use environment variables or secure configuration management.

API Endpoints

Two powerful endpoints for comprehensive sentiment analysis

Overall Sentiment Analysis
Analyze the emotional tone and sentiment of any text
POST /sentiment

Request

Headers:

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Body:

{
  "text": "Your text to analyze"
}

Response

{
  "sentiment": "positive",
  "compound_score": 0.6369,
  "positive_score": 0.636,
  "negative_score": 0.0,
  "neutral_score": 0.364,
  "confidence": 0.95
}
Entity-Based Sentiment Analysis
Analyze sentiment for specific entities mentioned in text
POST /entity-sentiment

Request

Headers:

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Body:

{
  "text": "Your text to analyze"
}

Response

{
  "entities": [
    {
      "name": "Google",
      "type": "ORGANIZATION",
      "sentiment": "positive",
      "score": 0.8,
      "magnitude": 0.8
    },
    {
      "name": "Microsoft",
      "type": "ORGANIZATION", 
      "sentiment": "negative",
      "score": -0.3,
      "magnitude": 0.3
    }
  ],
  "overall_sentiment": "mixed"
}
Health Check
Monitor API status and connectivity
GET /health

Request

Headers:

Authorization: Bearer YOUR_API_KEY

Response

{
  "ok": true,
  "timestamp": "2024-01-15T10:30:00Z",
  "version": "1.0.0"
}

Code Examples

Ready-to-use code snippets in your preferred language

JavaScript / Node.js
Node.js Example
const axios = require('axios');

const analyzeSentiment = async (text) => {
  try {
    const response = await axios.post(
      'https://api.example.com/sentiment',
      { text },
      {
        headers: {
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
        }
      }
    );
    
    return response.data;
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
};

// Usage
analyzeSentiment("I love this amazing product!")
  .then(result => console.log(result));
Python
Python Example
import requests

def analyze_sentiment(text, api_key):
    url = "https://api.example.com/sentiment"
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    data = {"text": text}
    
    try:
        response = requests.post(url, json=data, headers=headers)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")
        return None

# Usage
api_key = "YOUR_API_KEY"
result = analyze_sentiment("I love this amazing product!", api_key)
print(result)
cURL
cURL Examples

Overall Sentiment:

curl -X POST "https://api.example.com/sentiment" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "I love this amazing product!"}'

Entity Sentiment:

curl -X POST "https://api.example.com/entity-sentiment" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Google is great, Microsoft has issues"}'
Postman Collection

Import our Postman collection to test all endpoints:

Note: Remember to set your API key in the collection variables before testing the endpoints.

Troubleshooting

Common issues and solutions for smooth API integration

Authentication Errors

401 Unauthorized

Check that your API key is correct and included in the Authorization header

403 Forbidden

Verify your API key has the necessary permissions and hasn't expired

Rate Limiting

If you receive 429 Too Many Requests:

  • • Implement exponential backoff in your requests
  • • Check your current usage in the dashboard
  • • Consider upgrading your plan for higher limits
Request Issues

400 Bad Request

Ensure your request body contains valid JSON with the required "text" field

413 Payload Too Large

Text input is limited to 10,000 characters per request

Best Practices
  • • Store API keys in environment variables
  • • Implement proper error handling and retry logic
  • • Use HTTPS for all API requests
  • • Monitor your API usage and rate limits
  • • Cache results when appropriate
Need More Help?

Can't find the solution you're looking for? Our support team is here to help.