Skip to main content

Overview

Generate embeddings for text using any of LiteLLM’s supported embedding providers. Returns responses in OpenAI format.

Function Signature

Parameters

Required Parameters

string
required
The embedding model to use.Examples:
  • text-embedding-3-small (OpenAI)
  • text-embedding-ada-002 (OpenAI)
  • amazon.titan-embed-text-v1 (Bedrock)
  • textembedding-gecko@003 (Vertex AI)
  • embed-english-v3.0 (Cohere)
Union[str, List[str]]
required
Input text to embed. Can be a single string or array of strings.

Optional Parameters

int
Number of dimensions for the output embeddings. Only supported by some models (e.g., text-embedding-3 and later).
string
default:"float"
Format to return embeddings in.Options:
  • "float": Array of floats
  • "base64": Base64 encoded string
float
default:"600"
Request timeout in seconds (default 10 minutes).
string
Unique identifier for your end-user, for abuse monitoring.

API Configuration

string
API key for the provider. If not provided, uses environment variables.
string
Base URL for the API endpoint.
string
API version to use (provider-specific).
string
API type (e.g., “azure” for Azure OpenAI).

LiteLLM Specific

bool
default:"false"
Enable response caching.
string
Override the provider detection.Example: custom_llm_provider="bedrock"
dict
Additional metadata to tag the request.

Response

EmbeddingResponse

string
Object type, always “list”.
List[Embedding]
List of embedding objects.
string
Model used for embeddings.
Usage
Token usage information.

Usage Examples

Basic Embedding

Batch Embeddings

Async Embeddings

Custom Dimensions

Multiple Providers

Semantic Search Example

Provider-Specific Examples

Cohere with Input Type

Vertex AI Multimodal Embeddings

Error Handling

Supported Providers

LiteLLM supports embeddings from:
  • OpenAI: text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002
  • Azure OpenAI: All OpenAI embedding models
  • Cohere: embed-english-v3.0, embed-multilingual-v3.0
  • AWS Bedrock: amazon.titan-embed-text-v1, cohere.embed-*
  • Google Vertex AI: textembedding-gecko, text-embedding-004
  • Hugging Face: All embedding models
  • Voyage AI: voyage-2, voyage-code-2
  • Together AI: togethercomputer/m2-bert-80M-*
  • And many more!
See Embedding Providers for the complete list.