Scrums.com logomark
SovTech is now Scrums.com! Same company, new name.
SovTech is now Scrums.com!!
Read more here

Text to Emotion API

API
By:
API Layer
Updated:
April 25, 2025

About this Cloud Hub Solution:

Humans can naturally detect emotions from text, but machines require assistance to do so. The Text to Emotion API enables you to automatically identify the emotions embedded in text data using a simple API and a few lines of code.

How it works

The Text to Emotion API employs sophisticated NLP algorithms to extract underlying emotions from a given text. The process typically involves the following steps: Eliminate unnecessary text from the message. Apply natural language processing techniques.Retrieve the pre-processed text after text pre-processing. Identify words that convey emotions or feelings. Determine the emotion category for each word. Record the count of emotions relevant to the words found. The API endpoint returns a JSON dictionary with emotion categories (happy, surprise, angry, sad, fear) as keys and emotion scores as values. The score ranges from 0.00 to 1.00, with higher values indicating a greater likelihood of the text expressing a particular emotion.

Sample

For instance, consider the famous speech from Hamlet by William Shakespeare.This speech is complex and emotional, and the API is capable of capturing the mixed emotions expressed by Prince Hamlet.

To be, or not to be, that is the question:

Whether 'tis nobler in the mind to suffer

The slings and arrows of outrageous fortune,

Or to take Arms against a Sea of troubles,

And by opposing end them: to die, to sleep;

The simple cURL command to perform the text to emotion analysis is:

curl --location --request POST 'https://api.apilayer.com/text_to_emotion' \--header 'apikey: YOUR API KEY' \--data-raw 'To be, or not to be, that is the question:Whether '\''tis nobler in the mind to sufferThe slings and arrows of outrageous fortune,Or to take Arms against a Sea of troubles,And by opposing end them: to die, to sleep;'

And the response from the API is:

{"Happy": 0.14,  
"Angry": 0.0,   
"Surprise": 0.29,   
"Sad": 0.29,    
"Fear": 0.29}

More code samples (for more programming languages) are available on the Live Demo section right above.

How accurate is the API?

Human emotions can be incredibly complex, making it challenging for computers to accurately identify them. Even humans can struggle to interpret emotions, especially when sarcasm is involved. Without contextual information and nonverbal cues, it can be difficult to predict emotions with certainty. However, the Text to Emotion API is designed to exceed expectations in most cases. We invite you to try it out for your specific use case and see if it meets your needs.

Handling of Emojis

The API is able to identify the emotion from the emojis which describes human behavior. Let’s take an example:

curl --location --request POST 'https://api.apilayer.com/text_to_emotion' \--header 'apikey: YOUR API KEY' \--data-raw 'It\'s not funny. This must be a joke! 😡🤬'

And the response from the API is:

{"Happy": 0.33,    
"Angry": 0.67,    
"Surprise": 0.0,    
"Sad": 0.0,    
"Fear": 0.0}

Textually, there is a chance of being a joke but looking at the emojis, the API correctly classifies the emotion of the text as anger.

Use cases

The API is particularly useful for the following industry applications:

Customer Engagement: The insights provided by the Text to Emotion API enable customer service teams to better understand and interact with their clients. This facilitates a faster and more effective response to customer needs and concerns.

Customer Support with Chatbots: Chatbots provide 24/7 support to users. By integrating emotion detection, chatbots can offer more human-like interactions, leading to increased customer satisfaction.

Social Media Monitoring: Close monitoring of social media posts allows brands to address potential issues before they escalate into crises.

How is Emotion Detection different from Sentiment Analysis?

Sentiment Analysis determines the polarity of a given text by labeling it as positive, negative, or neutral. Emotion Detection takes it a step further by identifying the underlying emotions expressed in the text. For example, Sentiment Analysis might categorize both anger and fear as negative sentiments, but they require distinct communication approaches. Depending on your needs, you may also want to consider using the Sentiment Analysis API.

Explore Tech Stacks Related to

Text to Emotion API

Looking To Build Software Of Your Own?

Custom Software Development

Custom app solutions.
Explore software development
arrow

Mobile App Development

Custom mobile development.
Explore mobile app development
arrow

Product Design

User interface/User experience design
Explore product design
arrow

Web App Development

Custom web development
Explore web app development
arrow