Embeddings API

The Embeddings API encodes any text into a vector using state-of-the-art NLP machine learning models. It can be used to power semantic search, text comparison tools (also check out our Text Similarity API), recommendation engines, and much more.

/v1/embeddings

HTTP POST

Returns a 768-dimensional vector as an array that encodes the meaning of any given input text.

Body Parameters

text (required) - query text to embed. Maximum 5000 characters.

Headers

X-Api-Key (required) - API Key associated with your account.

Sample Request URL

Live Demo!

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

text

Sample Response

{
  "embeddings": [
    0.013939207419753075,
    -0.07620275765657425,
    -0.014649288728833199,
    -0.00781314168125391,
    -0.0740455836057663,
    0.03170469030737877,
    ...
  ]
}

Code Examples


import requests
body = { 'text': 'This is an example sentence.' }
api_url = 'https://api.api-ninjas.com/v1/embeddings'
response = requests.post(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'}, json=body)
if response.status_code == requests.codes.ok:
    print(response.text)
else:
    print("Error:", response.status_code, response.text)
$.ajax({
    method: 'POST',
    url: 'https://api.api-ninjas.com/v1/embeddings',
    headers: { 'X-Api-Key': 'YOUR_API_KEY'},
    data: JSON.stringify({ "text": "This is an example sentence." }),
    success: function(result) {
        console.log(result);
    },
    error: function ajaxError(jqXHR) {
        console.error('Error: ', jqXHR.responseText);
    }
});
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.