Create Embeddings

Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms for tasks like search, clustering, and recommendations.

Endpoint Overview

  • Endpoint URL: https://api.codingplanx.ai/v1/embeddings
  • HTTP Method: POST
  • Authentication: Include Authorization: Bearer {{YOUR_API_KEY}} in the request Header.

Request Parameters

Header Parameters

ParameterTypeRequiredExampleDescription
AuthorizationstringYesBearer YOUR_API_KEYAPI Key for authentication.
Content-TypestringYesapplication/jsonMust be set to application/json.

Body Parameters (application/json)

ParameterTypeRequiredDescription
modelstringYesThe ID of the model to use. For example, text-embedding-3-large or text-embedding-ada-002.
inputstring / arrayYesInput text to embed. Can be a single string or an array of strings. The maximum length for each input must not exceed 8192 tokens.

Response Parameters

HTTP Status Codes

  • 200: Success
  • 401: Unauthorized (Invalid API Key)
  • 429: Too Many Requests (Rate limit exceeded)
  • 500: Internal Server Error

Response Body Structure (JSON)

ParameterTypeDescription
objectstringThe object type, which is always list.
dataarrayAn array containing the embedding objects.
objectstringAlways embedding.
embeddingarrayA list of floating point numbers representing the vector of the text.
indexintegerThe index of the embedding in the input array.
modelstringThe ID of the model actually used.
usageobjectToken usage statistics for the request.
prompt_tokensintegerThe number of tokens used by the prompt/input.
total_tokensintegerThe total number of tokens used in the request.

Request Examples

cURL

curl --location --request POST 'https://api.codingplanx.ai/v1/embeddings' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "model": "text-embedding-3-large",
  "input": "Meow meow meow meow meow"
}'

Python (Requests)

import requests
import json

url = "https://api.codingplanx.ai/v1/embeddings"
payload = json.dumps({
  "model": "text-embedding-3-large",
  "input": "Embeddings in machine learning are very useful."
})
headers = {
  'Authorization': 'Bearer YOUR_API_KEY',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.json())

Response Example

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        0.0014231221,
        "..."
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-3-large",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

FAQs (Frequently Asked Questions)

Q1: Does this endpoint support batch processing? Yes. You can pass an array of strings (e.g., ["text1", "text2"]) to the input parameter. The API will process and return the embeddings for all texts in a single response, differentiated by the index within the data array.

Q2: What is the token limit? What should I do if my text is too long? The maximum length for each input text is 8192 tokens. If your text exceeds this limit, it is highly recommended to perform text chunking first. You can then retrieve embeddings for each chunk separately and process them according to your business requirements (e.g., calculating the average or storing chunks individually).

Q3: What is the dimensionality of the generated vectors? The dimensionality depends on your chosen model. For example:

  • text-embedding-ada-002 typically returns 1536 dimensions.
  • text-embedding-3-large defaults to 3072 dimensions (but supports dimensionality reduction via additional parameters; please refer to the advanced documentation for details).

Q4: Why am I receiving a 401 Unauthorized error? A 401 error usually indicates that the Authorization header is either missing or invalid. Please verify that you have correctly included the Bearer prefix and that your API Key is spelled accurately.

Q5: Can I compare embedding vectors generated by different models? No. Different models produce completely different vector spaces. You cannot calculate the cosine similarity between a vector generated by ada-002 and one from text-embedding-3-large. When performing similarity searches, the vectors stored in your database and the query vector must be generated using the exact same model.