Skip to content

embeddings

Create embedding vector representations for input text

POST /embeddings
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.
{
"model": "text-embedding-3-small",
"input": "The food was delicious and the waiter was friendly."
}
{
"model": "text-embedding-3-small",
"input": [
"Hello world",
"Goodbye world",
"How are you?"
]
}
{
"model": "text-embedding-3-small",
"input": "Convert this to an embedding.",
"encoding_format": "base64",
"dimensions": 256
}

Successful response

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.
{
"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
}
}
const response = await fetch('https://api.r9s.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);
import requests
url = "https://api.r9s.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)
Terminal window
curl -X POST "https://api.r9s.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."}'
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.
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.
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.