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

Text Similarity API

The Text Similarity API computes the similarity score between two pieces of text. It uses state-of-the-art NLP machine learning models to first embed (see our Embddings API) the texts into 768-dimension vectors, and then computes the cosine similarity between the two vectors.

(4.3)

From 6,123 users

500+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
431ms471ms504ms907ms1244ms

Didn't find what you were looking for? Suggest an improvement


/v1/textsimilarity POST

https://api.api-ninjas.com/v1/textsimilarity

Returns a similarity score between 0 and 1 (1 is similar and 0 is dissimilar) of two given texts.

Body Parameters

  • text_1  required

    First input text. Maximum 5000 characters.

  • text_2  required

    Second input text. Maximum 5000 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.

  • similarity

    Similarity score between 0 and 1, where 1 indicates identical texts and 0 indicates completely different texts.

Sample Request Live Demo!

text_1
text_2

Try this API endpoint with all available parameters in our API playground

https://api.api-ninjas.com/v1/textsimilarity

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON

Code Examples

1 2 3 4 curl -X POST "https://api.api-ninjas.com/v1/textsimilarity" \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"text_1": "This is an example sentence.", "text_2": "This is just another example sentence."}'

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.