Method Signature
Parameters
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.Constraints:
- Must not exceed the max input tokens for the model (8192 tokens for all embedding models)
- Cannot be an empty string
- Any array must be 2048 dimensions or less
- Maximum of 300,000 tokens summed across all inputs in a single request
ID of the model to use. You can use the List models API to see all available models, or see the Model overview for descriptions.Popular models:
text-embedding-3-smalltext-embedding-3-largetext-embedding-ada-002
The number of dimensions the resulting output embeddings should have. Only supported in
text-embedding-3 and later models.The format to return the embeddings in. Can be either
float or base64.Note: The SDK automatically decodes base64 embeddings to float arrays for convenience.A unique identifier representing your end-user, which can help OpenAI monitor and detect abuse. Learn more.
Response
Returns aCreateEmbeddingResponse object:
Examples
Single Text Embedding
Multiple Texts in One Request
Using Custom Dimensions
Embedding Tokens Directly
Async Usage
Notes
- The Python SDK automatically optimizes embedding encoding by using base64 format by default and decoding it to floats
- If NumPy is installed, the SDK uses it for faster base64 decoding
- See the Embeddings Guide for best practices and use cases
- Use tiktoken to count tokens before sending requests