Create embeddings
Creates an embedding vector representing the input text.
Request body
inputstring or array
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. Some models may also impose a limit on total number of tokens summed across inputs.stringstringRequiredDefaults:
The string that will be turned into an embedding.arrayarrayRequired
The array of strings that will be turned into an embedding.itemsstringDefaults:
arrayarrayRequired
The array of integers that will be turned into an embedding.itemsinteger
arrayarrayRequired
The array of arrays containing integers that will be turned into an embedding.itemsarray
itemsinteger
modelstring
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.
modelstringRequired
modelstringRequired
text-embedding-ada-002string
text-embedding-3-smallstring
text-embedding-3-largestring
encoding_formatstringDefaults: float
The format to return the embeddings in. Can be either
floatorbase64.floatstring
base64string
dimensionsinteger
The number of dimensions the resulting output embeddings should have. Only supported in
text-embedding-3and later models.userstring
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Response
A list of embedding objects.
1 curl https://api.openai.com/v1/embeddings \2 -H "Authorization: Bearer $OPENAI_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "input": "The food was delicious and the waiter...",6 "model": "text-embedding-ada-002",7 "encoding_format": "float"8 }'
1 {2 "object": "list",3 "data": [4 {5 "object": "embedding",6 "embedding": [7 0.0023064255,8 -0.009327292,9 .... (1536 floats total for ada-002)10 -0.0028842222,11 ],12 "index": 013 }14 ],15 "model": "text-embedding-ada-002",16 "usage": {17 "prompt_tokens": 8,18 "total_tokens": 819 }20 }