📊 Sentiment Analysis API Documentation
📌 Overview
The Sentiment Analysis API in TyphAI NLP Suite analyzes the sentiment of textual data. It classifies text sentiment as positive, neutral, or negative, and provides a detailed confidence score, identifies essential keywords, and offers a clear reason behind the sentiment classification.
🛠️ Endpoint
POST https://typhai-nlp-suite.p.rapidapi.com/api/v1/sentiment-analyses
📥 Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
text | string | ✅ | The input text to analyze. |
language | string | ❌ | The language of the text (e.g., en , es , fr ). Defaults to English if not specified. |
context | string | ❌ | Domain/context for increased accuracy (e.g., general , finance , health , ecommerce ). |
📤 Response Example
{
"id": "cff3d09f-cfe3-4eae-a2d4-fd94fa6ca29d",
"text": "I love this service!",
"sentiment": "positive",
"confidence": 0.95,
"reason": "The use of 'love' indicates a strong positive sentiment towards the service.",
"keywords": ["service", "love", "positive experience", "recommend"]
}
🚀 Usage Examples
1️⃣ cURL Request
curl -X POST "https://typhai-nlp-suite.p.rapidapi.com/api/v1/sentiment-analyses" \
-H "Content-Type: application/json" \
-H "X-RapidAPI-Host: typhai-nlp-suite.p.rapidapi.com" \
-H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
-d '{"text": "This product is amazing!"}'
2️⃣ Fetch API (JavaScript)
fetch("https://typhai-nlp-suite.p.rapidapi.com/api/v1/sentiment-analyses", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-RapidAPI-Host": "typhai-nlp-suite.p.rapidapi.com",
"X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY",
},
body: JSON.stringify({ text: "This product is amazing!" }),
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error(error));
3️⃣ Axios Request (JavaScript)
import axios from "axios";
const options = {
method: "POST",
url: "https://typhai-nlp-suite.p.rapidapi.com/api/v1/sentiment-analyses",
headers: {
"Content-Type": "application/json",
"X-RapidAPI-Host": "typhai-nlp-suite.p.rapidapi.com",
"X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY",
},
data: { text: "This product is amazing!" },
};
axios
.request(options)
.then((response) => console.log(response.data))
.catch((error) => console.error(error));
🎮 Try It Yourself
const TestSentimentAPI = () => {
const [apiKey, setApiKey] = useState("");
const [text, setText] = useState("");
const [response, setResponse] = useState(null);
const [loading, setLoading] = useState(false);
const handleRequest = async () => {
if (!apiKey) {
alert("Please enter your RapidAPI Key.");
return;
}
setLoading(true);
try {
const res = await axios.post(
"https://typhai-nlp-suite.p.rapidapi.com/api/v1/sentiment-analyses",
{ text },
{
headers: {
"Content-Type": "application/json",
"X-RapidAPI-Host": "typhai-nlp-suite.p.rapidapi.com",
"X-RapidAPI-Key": apiKey,
},
}
);
setResponse(res.data);
} catch (error) {
setResponse(error.message);
}
setLoading(false);
};
return (
<div>
<h3>Test Sentiment Analysis API</h3>
<input
type="text"
placeholder="Enter RapidAPI Key"
value={apiKey}
onChange={(e) => setApiKey(e.target.value)}
/>
<input
type="text"
placeholder="Enter text"
value={text}
onChange={(e) => setText(e.target.value)}
/>
<button onClick={handleRequest} disabled={loading}>
{loading ? "Loading..." : "Send Request"}
</button>
{response && <pre>{JSON.stringify(response, null, 2)}</pre>}
</div>
);
};
<TestSentimentAPI />;
📩 Need Help? Visit our FAQ .
🚀 Start analyzing sentiment today with TyphAI NLP Suite on RapidAPI!
Last updated on