Create embeddings
Create embedding vector representations for input text
Request
POST /embeddings
Request Body
| Field | Type | Required | Description |
|---|
| model | string | Yes | ID of the model to use. You can use the List models API to see all of your available models. |
| input | string | Yes | Input 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_format | string (float, base64) | No | The format to return the embeddings in. Can be either “float” or “base64”. |
| dimensions | integer | No | The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. |
| user | string | No | A 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
| Field | Type | Required | Description |
|---|
| object | string | Yes | The object type, which is always “list”. |
| data | Array<EmbeddingObject> | Yes | The list of embeddings generated by the model. |
| model | string | Yes | The name of the model used to generate the embedding. |
| usage | object | Yes | The 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
| Field | Type | Required | Description |
|---|
| model | string | Yes | ID of the model to use. You can use the List models API to see all of your available models. |
| input | string | Yes | Input 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_format | string (float, base64) | No | The format to return the embeddings in. Can be either “float” or “base64”. |
| dimensions | integer | No | The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. |
| user | string | No | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
EmbeddingResponse
| Field | Type | Required | Description |
|---|
| object | string | Yes | The object type, which is always “list”. |
| data | Array<EmbeddingObject> | Yes | The list of embeddings generated by the model. |
| model | string | Yes | The name of the model used to generate the embedding. |
| usage | object | Yes | The usage information for the request. |
EmbeddingObject
| Field | Type | Required | Description |
|---|
| object | string | Yes | The object type, which is always “embedding”. |
| embedding | Array | Yes | The embedding vector, which is a list of floats. The length of vector depends on the model. |
| index | integer | Yes | The index of the embedding in the list of embeddings. |
Related APIs