Create embeddings
POST
https://api.openai.com/v1/embeddingsCreates an embedding vector representing the input text.
Request
Header Params
Authorization
string
required
Example:
Bearer $OPENAI_API_KEY
Content-Type
string
required
Example:
application/json
Body Params application/json
input
string
required
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. Example Python code for counting tokens.
model
string
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
required
The format to return the embeddings in. Can be either float
or base64
.
Example
{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-ada-002",
"encoding_format": "float"
}
Request samples
Responses
Success(200)
HTTP Code: 200
Content Type : JSONapplication/json
Data Schema
object
string
required
data
array [object {3}]
required
object
string
optional
embedding
array[number]
optional
index
integer
optional
model
string
required
usage
object
required
prompt_tokens
integer
required
total_tokens
integer
required
Example
{
"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
}
}
Last modified: 15 days ago