POST/embeddings

Create embedding vectors

Creates embedding vectors for the supplied text or token input. Provide model and input, and use encoding_format or dimensions to control the returned vectors when the selected model supports those options.

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

5 body fields

Input and options for generating one or more embeddings.

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](https://developers.openai.com/api/reference/resources/models/methods/list) API to see all of your available models, or see our [Model overview](https://developers.openai.com/api/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](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).

7 status codes
200Returns a list containing the generated embedding vectors, the model used, and 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.
400Returned when the embedding input or request parameters are invalid.
errorobjectrequired
401Returned when the API key is missing or revoked, or the client IP is not authorized.
errorobjectrequired
403Returned when organization policy blocks access to a personal API organization.
429Returned when the request exceeds a rate limit. A `slow_down` error indicates that you should reduce traffic and increase it gradually.

One documented failure

  • slow_down

    Your request rate increased too quickly. Please reduce the request rate and gradually increase it again.

    Traffic increased too quickly

errorobjectrequired
500Returned when an internal error prevents the embedding request from being processed.
errorobjectrequired
503Returned when the service is temporarily unavailable or the requested model is overloaded.

One documented failure

  • server_is_overloaded

    The model is temporarily overloaded. Please retry your request after a brief delay.

    The requested model is temporarily overloaded

errorobjectrequired

Error handling

A 400 is returned for invalid input or request parameters; a 401 indicates a missing or revoked API key or an unauthorized client IP; a 403 indicates that organization policy blocks access. A 429 is returned when the request exceeds a rate limit, a 500 when an internal error prevents processing, and a 503 when the service or requested model is temporarily unavailable. model and input are required; input must not be empty or exceed 8192 tokens, encoding_format must be float or base64, and dimensions must be at least 1 and is supported only by text-embedding-3 and later models.