Skip to content

embeddings

Create embeddings

Create embedding vector representations for input text

Request

POST /embeddings

Request Body

FieldTypeRequiredDescription
modelstringYesID of the model to use. You can use the List models API to see all of your available models.
inputstringYesInput text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for text-embedding-ada-002), cannot be an empty string, and any array must be 2048 dimensions or less.
encoding_formatstring (float, base64)NoThe format to return the embeddings in. Can be either “float” or “base64”.
dimensionsintegerNoThe number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.
userstringNoA unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

Request Examples

Single text embedding

{
  "model": "text-embedding-3-small",
  "input": "The food was delicious and the waiter was friendly."
}

Multiple text embeddings

{
  "model": "text-embedding-3-small",
  "input": [
    "Hello world",
    "Goodbye world",
    "How are you?"
  ]
}

Base64 encoded embedding

{
  "model": "text-embedding-3-small",
  "input": "Convert this to an embedding.",
  "encoding_format": "base64",
  "dimensions": 256
}

Successful response

Response Schema

FieldTypeRequiredDescription
objectstringYesThe object type, which is always “list”.
dataArray<EmbeddingObject>YesThe list of embeddings generated by the model.
modelstringYesThe name of the model used to generate the embedding.
usageobjectYesThe usage information for the request.

Response Example

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        -0.0028842222
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

Code Examples

JavaScript (Fetch)

const response = await fetch('https://api.uuroute.ai/v1/embeddings', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "model": "text-embedding-3-small",
  "input": "The food was delicious and the waiter was friendly."
})
});

const data = await response.json();
console.log(data);

Python (requests)

import requests

url = "https://api.uuroute.ai/v1/embeddings"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

response = requests.post(url, json={
  "model": "text-embedding-3-small",
  "input": "The food was delicious and the waiter was friendly."
}, headers=headers)
data = response.json()
print(data)

cURL

curl -X POST "https://api.uuroute.ai/v1/embeddings" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"text-embedding-3-small","input":"The food was delicious and the waiter was friendly."}'

Schema Reference

EmbeddingRequest

FieldTypeRequiredDescription
modelstringYesID of the model to use. You can use the List models API to see all of your available models.
inputstringYesInput text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for text-embedding-ada-002), cannot be an empty string, and any array must be 2048 dimensions or less.
encoding_formatstring (float, base64)NoThe format to return the embeddings in. Can be either “float” or “base64”.
dimensionsintegerNoThe number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.
userstringNoA unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

EmbeddingResponse

FieldTypeRequiredDescription
objectstringYesThe object type, which is always “list”.
dataArray<EmbeddingObject>YesThe list of embeddings generated by the model.
modelstringYesThe name of the model used to generate the embedding.
usageobjectYesThe usage information for the request.

EmbeddingObject

FieldTypeRequiredDescription
objectstringYesThe object type, which is always “embedding”.
embeddingArrayYesThe embedding vector, which is a list of floats. The length of vector depends on the model.
indexintegerYesThe index of the embedding in the list of embeddings.