Create embeddings
POST https://api.fastapi.ai/v1/embeddings
Creates an embedding vector representing the input text.
Request body
input
string or array Required
nput 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. Example Python code for counting tokens. Some models may also impose a limit on total number of tokens summed across inputs.
string string
The string that will be turned into an embedding.
array array
The array of strings that will be turned into an embedding.
array array
The array of integers that will be turned into an embedding.
array array
The array of arrays containing integers that will be turned into an embedding.
model
string or array Required
ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.
encoding_format
string Optional Defaults to float
The format to return the embeddings in. Can be either float
or base64
.
dimensions
integer Optional
The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3
and later models.
user
string Optional
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Returns
A list of embedding objects.
The embedding object
Represents an embedding vector returned by embedding endpoint.
index
integer
The index of the embedding in the list of embeddings.
embedding
array
The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the embedding guide.
object
string
The object type, which is always "embedding".
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
.... (1536 floats total for ada-002)
-0.0028842222,
],
"index": 0
}
Example
Request
curl https://api.fastapi.ai/v1/embeddings \
-H "Authorization: Bearer $FAST_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-ada-002",
"encoding_format": "float"
}'
Response
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
.... (1536 floats total for ada-002)
-0.0028842222,
],
"index": 0
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}