Skip to content

Create embeddings

POST https://api.fastapi.ai/v1/embeddings

Creates an embedding vector representing the input text.

Request body


input string or array 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 an array of token arrays.

The input must not exceed the max input tokens for the model (8192 tokens for all embedding models), cannot be an empty string, and any array must be 2048 dimensions or less. In addition to the per-input token limit, all embedding models enforce a maximum of 300,000 tokens summed across all inputs in a single request.


model string Required
ID of the model to use.


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


encoding_format string Optional Defaults to float
The format to return the embeddings in. Can be either float or base64.


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

Returns


Returns a list of embedding objects.

Example

Request

bash
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

bash
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [0.0023064255, -0.009327292],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

那年我双手插兜, 让bug稳如老狗