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

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.

(4.6)

From 4,698 users

3,700+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
331ms343ms388ms636ms1215ms

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


/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.

Response

A JSON object with the following fields or an error if the request is unsuccessful.

  • embeddings

    Array of floating-point numbers representing the text embedding vector.

Sample Request Live Demo!

text

Try our APIs in the API playground

Sign up for a free API key to get started — no credit card required.

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

Headers

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

Sample Response

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

Code Examples

1 2 3 4 curl -X POST "https://api.api-ninjas.com/v1/embeddings" \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"text": "This is an 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.

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the Embeddings API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.
  • The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.
  • The Embeddings API encodes text into vectors using state-of-the-art NLP machine learning models, making it ideal for semantic search, recommendation engines, clustering, and text comparison tools. For directly scoring how alike two pieces of text are, you can also pair it with our Text Similarity API, or explore other NLP tools on the APIs page.
  • Send a POST request to /v1/embeddings with a JSON body containing the text parameter, which is required and accepts a maximum of 5000 characters. See the error codes page for details on responses to invalid input.
  • The response is a JSON object with an embeddings field, a 768-dimensional array of floating-point numbers that encodes the meaning of your input text. These vectors can feed downstream tasks such as those handled by our Sentiment API or Text Language API.
  • Every call to /v1/embeddings returns a 768-dimensional vector as an array in the embeddings field, regardless of input length. Review your plan options on the pricing page before integrating at scale.