Swagger Petstore - OpenAPI 3.0
POST/embeddings

Create text embeddings

Creates an embedding vector representing input text. Supply text as a string or array of strings, or as token arrays. The embedding captures semantic meaning and can be used for similarity search, clustering, or classification tasks.

  • IdempotentThe SDK sends Idempotency-Key, so a retried request is only applied once.

5 body fields

Embedding request parameters.

inputstringrequired
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 all embedding models), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. 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.
Default:
modelstringrequired
ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models) for descriptions of them.
encoding_formatstringoptional
The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).
Allowed:floatbase64Default:float
dimensionsintegeroptional
The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.
userstringoptional
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices#end-user-ids).

2 status codes
200Returns an array of embedding objects, each containing the embedding vector, its index, and the model used. Includes token usage information.
dataarray<object>required
The list of embeddings generated by the model.
modelstringrequired
The name of the model used to generate the embedding.
objectstringrequired
The object type, which is always "list".
Allowed:list
usageobjectrequired
The usage information for the request.
429Returned when the request rate limit is exceeded.
errorobjectrequired

Error handling

A 429 is returned when the request rate limit is exceeded. Both model and input are required — omitting either returns an error. input must not be an empty string and cannot exceed 8192 tokens; arrays must contain between 1 and 2048 items. encoding_format must be either float or base64 if specified.