Sentiment API
The Sentiment API provides fast and accurate sentiment analysis results for any given text.
From 6,147 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 351ms | 381ms | 441ms | 554ms | 1028ms |
Didn't find what you were looking for? Suggest an improvement
/v1/sentiment GET
https://api.api-ninjas.com/v1/sentiment
Returns sentiment analysis score and overall sentiment for a given block of text.
Parameters
textrequiredQuery text for sentiment analysis. Maximum 2000 characters.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON object with the following fields or an error if the request is unsuccessful.
scoreSentiment analysis score from -1 to 1.
1is the most positive,-1is the most negative, and0is neutral.textText that was analyzed.
sentimentOverall sentiment of the text. Possible values are
POSITIVE,WEAK_POSITIVE,NEGATIVE,WEAK_NEGATIVE, andNEUTRAL.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/sentiment?text=I'm loving it!Headers
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/sentiment?text=I%27m%20loving%20it" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
Frequently Asked Questions
Can I use the Sentiment API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Sentiment API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Sentiment API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Sentiment API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.What does the score field represent and how is it different from the sentiment field?
Thescoreis a numeric value from -1 to 1, where1is the most positive,-1is the most negative, and0is neutral, while thesentimentfield maps that score to a label such asPOSITIVE,WEAK_POSITIVE,NEUTRAL,WEAK_NEGATIVE, orNEGATIVE. If you also need to compare how alike two pieces of text are, see the Text Similarity API.Is there a length limit on the text I can analyze?
Yes, the requiredtextparameter accepts a maximum of 2000 characters per request, so longer documents should be split into smaller chunks before calling the endpoint. You can review usage limits on the pricing page.Can I detect the language of the text before running sentiment analysis?
The Sentiment endpoint only returnsscore,text, andsentimentand does not report language, so to identify the language first use the Text Language API. You can also browse other text tools in the API catalog.How do I call the endpoint to analyze a phrase?
Send a GET request tohttps://api.api-ninjas.com/v1/sentimentwith your phrase in thetextquery parameter (URL-encoded) and your key in theX-Api-Keyheader; for example?text=I%27m%20loving%20itreturns aPOSITIVEsentiment. If a call fails, consult the error codes reference.