Sample - OpenAI API
POST/embeddings

Create text embeddings

Creates embedding vectors representing the supplied text or token input. Provide model and input, then optionally choose the output encoding, vector dimensions, and end-user identifier. A successful response includes the generated vectors and token usage information.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

5 body fields

Embedding request containing the required model and input, with optional output and safety-identification settings.

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).

3 status codes
200Returns a list of embedding objects with their vectors and indexes, the model used, the object type, and prompt and total token usage.
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 was rejected because a rate limit was exceeded; a `slow_down` error indicates that traffic increased too quickly.

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
503Returned when the service is temporarily unavailable because the requested model is overloaded; retry after a brief delay.

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 429 is returned when traffic exceeds the allowed rate; reduce the request rate if a slow_down error occurs. A 503 is returned when the service or requested model is temporarily overloaded; retry after a brief delay. model and input are required, input cannot be empty or exceed 8192 tokens, and encoding_format must be float or base64.