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.
HTTP POST
Returns a 768-dimensional vector as an array that encodes the meaning of any given input text.
text
(required) - query text to embed. Maximum 5000 characters.
X-Api-Key
(required) - API Key associated with your account.
Live Demo!
https://api.api-ninjas.com/v1/embeddings
text:
{
"embeddings": [
0.013939207419753075,
-0.07620275765657425,
-0.014649288728833199,
-0.00781314168125391,
-0.0740455836057663,
0.03170469030737877,
...
]
}
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);
}
});