NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server

Sentiment API

The Sentiment API provides fast and accurate sentiment analysis results for any given text.

(4.7)

From 6,147 users

3,900+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
351ms381ms441ms554ms1028ms

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

  • text  required

    Query text for sentiment analysis. Maximum 2000 characters.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON object with the following fields or an error if the request is unsuccessful.

  • score

    Sentiment analysis score from -1 to 1. 1 is the most positive, -1 is the most negative, and 0 is neutral.

  • text

    Text that was analyzed.

  • sentiment

    Overall sentiment of the text. Possible values are POSITIVE, WEAK_POSITIVE, NEGATIVE, WEAK_NEGATIVE, and NEUTRAL.

Sample Request Live Demo!

text

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 Key

Sample Response

JSON
{
    score:0.622,
    text:"I'm loving it",
    sentiment:"POSITIVE"
}

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

  • 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.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • 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.
  • 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.
  • The score is a numeric value from -1 to 1, where 1 is the most positive, -1 is the most negative, and 0 is neutral, while the sentiment field maps that score to a label such as POSITIVE, WEAK_POSITIVE, NEUTRAL, WEAK_NEGATIVE, or NEGATIVE. If you also need to compare how alike two pieces of text are, see the Text Similarity API.
  • Yes, the required text parameter 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.
  • The Sentiment endpoint only returns score, text, and sentiment and 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.
  • Send a GET request to https://api.api-ninjas.com/v1/sentiment with your phrase in the text query parameter (URL-encoded) and your key in the X-Api-Key header; for example ?text=I%27m%20loving%20it returns a POSITIVE sentiment. If a call fails, consult the error codes reference.