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 POST

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

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


Parameters

  • text  required

    Query text to embed. Maximum 5000 characters.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Sample Request Live Demo!

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

Sample Response

JSON
1 2 3 4 5 6 7 8 9 10 11 { "embeddings": [ 0.013939207419753075, -0.07620275765657425, -0.014649288728833199, -0.00781314168125391, -0.0740455836057663, 0.03170469030737877, ... ] }

Code Examples

1 2 3 4 5 6 7 8 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)

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.