Skip to content

OpenAI Embeddings Format

This page overview

Official documentation

OpenAI Embeddings

Get vector representations of the provided input text. These vectors can be easily used by machine learning models and algorithms. For related guidance, see the Embeddings Guide.

Please note:

  • Some models may have limits on the total number of input tokens
  • You can use the sample Python code to calculate the number of tokens
  • For example, the output vector dimension of the text-embedding-ada-002 model is 1536
curl https://4All API地址/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $4All API_API_KEY" \
-d '{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-ada-002",
"encoding_format": "float"
}'

Response example:

{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
// ... (1536 floating-point numbers, for ada-002)
-0.0028842222
],
"index": 0
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
curl https://4All API地址/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $4All API_API_KEY" \
-d '{
"input": ["The food was delicious", "The waiter was friendly"],
"model": "text-embedding-ada-002",
"encoding_format": "float"
}'

Response example:

{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
// ... (1536 floating-point numbers)
],
"index": 0
},
{
"object": "embedding",
"embedding": [
-0.008815289,
// ... (1536 floating-point numbers)
],
"index": 1
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 12,
"total_tokens": 12
}
}
POST /v1/embeddings

Create embedding vectors that represent the input text.

Include the following in the request headers for API key authentication:

Authorization: Bearer $4All API_API_KEY

Where $OPENAI_API_KEY is your API key.

  • Type: string or array
  • Required: Yes

The input text to embed, encoded as a string or an 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 model’s maximum input token limit (text-embedding-ada-002 supports up to 8192 tokens), must not be an empty string, and any array dimension must be less than or equal to 2048.

  • Type: string
  • Required: Yes

The model ID to use. You can use the List models API to view all available models, or refer to the model overview for their descriptions.

  • Type: string
  • Required: No
  • Default: float

The format of the returned embeddings. Can be float or base64.

  • Type: integer
  • Required: No

The number of dimensions the generated output embedding should have. Supported only for text-embedding-3 and later models.

  • Type: string
  • Required: No

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

Returns a list of embedding objects.

  • Type: string
  • Description: Object type, value is "list"
  • Type: array
  • Description: Array containing embedding objects
  • Attributes:
  • object: Object type, value is "embedding"
  • embedding: Embedding vector, a list of floating-point numbers. The vector length depends on the model
  • index: The index of the embedding in the list
  • Type: string
  • Description: The name of the model used
  • Type: object
  • Description: Token usage statistics
  • Attributes:
  • prompt_tokens: Number of tokens used by the prompt
  • total_tokens: Total number of tokens

Represents the embedding vector returned by the embeddings endpoint.

{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
// ... (a total of 1536 floating-point numbers for ada-002)
-0.0028842222
],
"index": 0
}
  • Type: integer
  • Description: The index of the embedding in the list
  • Type: array
  • Description: Embedding vector, a list of floating-point numbers. The vector length depends on the model; see the Embeddings Guide for details
  • Type: string
  • Description: Object type, always "embedding"

When a request fails, the API returns an error response object with an HTTP status code in the 4XX-5XX range.

  • 401 Unauthorized: Invalid API key or API key not provided
  • 400 Bad Request: Invalid request parameters, such as empty input or exceeding the token limit
  • 429 Too Many Requests: API rate limit exceeded
  • 500 Internal Server Error: Internal server error

Error response example:

{
"error": {
"message": "The input exceeds the maximum length. Please reduce the length of your input.",
"type": "invalid_request_error",
"param": "input",
"code": "context_length_exceeded"
}
}