Create embeddings

POSThttps:/api.openai.com/v1/embeddings

Creates an embedding vector representing the input text.

Request body

  • input
    string 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.

    • string
      string
      Required
      Defaults:
      The string that will be turned into an embedding.
    • array
      array
      Required
      The array of strings that will be turned into an embedding.
      • items
        string
        Defaults:
    • array
      array
      Required
      The array of integers that will be turned into an embedding.
      • items
        integer
    • array
      array
      Required
      The array of arrays containing integers that will be turned into an embedding.
      • items
        array
        • items
          integer
  • model
    string

    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.

    • model
      string
      Required
    • model
      string
      Required
      • text-embedding-ada-002
        string
      • text-embedding-3-small
        string
      • text-embedding-3-large
        string
  • encoding_format
    string
    Defaults: float

    The format to return the embeddings in. Can be either float or base64.

    • float
      string
    • base64
      string
  • dimensions
    integer

    The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.

  • user
    string

    A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Response

A list of embedding objects.

Example request
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
}'
Example response
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": 0
13
}
14
],
15
"model": "text-embedding-ada-002",
16
"usage": {
17
"prompt_tokens": 8,
18
"total_tokens": 8
19
}
20
}
Built with