Unode
User GuideAPI ReferenceHelp & SupportBusiness Cooperation

OpenAI Embeddings

Official Documentation

Introduction

Get vector representations of given input text that can be easily used by machine learning models and algorithms. For related guides, see Embeddings Guide.

Important notes:

  • Some models may have limits on the total number of tokens in the input

  • You can use example Python code to calculate token counts

  • For example: the text-embedding-ada-002 model outputs vectors with 1536 dimensions

Supported Models

Currently supported models include:

ModelDescription
text-embedding-ada-002Ada text embedding model (1536 dimensions)
text-embedding-3-smallSmall text embedding model (1536 dimensions)
text-embedding-3-largeLarge text embedding model (3072 dimensions)

Request Examples

curl https://www.unodetech.xyz/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "input": "The food was delicious and the waiter...",
    "model": "text-embedding-ada-002",
    "encoding_format": "float"
  }'

Response Example:

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        // ... (1536 floating point numbers for ada-002)
        -0.0028842222
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}
curl https://www.unodetech.xyz/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "input": ["The food was delicious", "The waiter was friendly"],
    "model": "text-embedding-ada-002",
    "encoding_format": "float"
  }'

Response Example:

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        // ... (1536 floating point numbers)
      ],
      "index": 0
    },
    {
      "object": "embedding",
      "embedding": [
        -0.008815289,
        // ... (1536 floating point numbers)  
      ],
      "index": 1
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 12,
    "total_tokens": 12
  }
}

Request

Endpoint

POST /v1/embeddings

Create embedding vectors that represent the input text.

Authentication Method

Include the following in the request header for API key authentication:

Authorization: Bearer $API_KEY

Where $API_KEY is your API key.

Request Body Parameters

Response

Successful Response

Returns a list of embedding objects.

Embedding Object

Represents an embedding vector returned by the embeddings endpoint.

{
  "object": "embedding",
  "embedding": [
    0.0023064255,
    -0.009327292,
    // ... (1536 floating point numbers total for ada-002)
    -0.0028842222
  ],
  "index": 0
}

Error Response

When there are issues with the request, the API will return an error response object with HTTP status codes in the 4XX-5XX range.

Common Error Status Codes

  • 401 Unauthorized: Invalid or missing API key
  • 400 Bad Request: Invalid request parameters, such as empty input or exceeding token limits
  • 429 Too Many Requests: API call limit exceeded
  • 500 Internal Server Error: Internal server error

Error response example:

{
  "error": {
    "message": "The input exceeds the maximum length. Please reduce the length of your input.",
    "type": "invalid_request_error",
    "param": "input",
    "code": "context_length_exceeded"
  }
}

Last updated on