From 986c0eb9005c3aeef1008328a06454b409b29555 Mon Sep 17 00:00:00 2001 From: s-zx <2575376715@qq.com> Date: Sun, 8 Mar 2026 23:21:12 +0100 Subject: [PATCH] fix(embeddings): drop dimensions param for openai_compatible_providers when drop_params=True When using litellm.embedding() or litellm.aembedding() with an openai_compatible_provider (e.g. hosted_vllm, openrouter), the dimensions parameter was always forwarded to the upstream API even when drop_params=True. This caused 422 errors from any vLLM endpoint or compatible server that does not support dimensions. Root cause: the else branch in get_optional_params_embeddings() that handles openai_compatible_providers did a bare optional_params = non_default_params with no validation or drop_params handling. The OpenAI-specific branch correctly limits dimensions to text-embedding-3-* models but this guard was absent for the compatible-providers path. Fix: copy non_default_params and, when dimensions is present and the model is not text-embedding-3-*, either drop it (if drop_params is True) or raise UnsupportedParamsError, matching the behaviour of the dedicated provider branches. Fixes #23119 --- litellm/utils.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index dfacefe6971..53ab2d8eb6b 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3453,7 +3453,28 @@ def get_optional_params_embeddings( # noqa: PLR0915 else: optional_params = non_default_params else: - optional_params = non_default_params + # openai_compatible_providers (e.g. hosted_vllm, openrouter, etc.) + # Pass all params through, but honour drop_params for `dimensions` + # because many vLLM / compatible endpoints don't support it and return + # 422 when it is present. Only text-embedding-3-* models support it. + optional_params = non_default_params.copy() + if ( + "dimensions" in optional_params + and model is not None + and "text-embedding-3" not in model + ): + if litellm.drop_params is True or drop_params is True: + optional_params.pop("dimensions") + else: + raise UnsupportedParamsError( + status_code=500, + message=( + f"Setting 'dimensions' is not supported for model '{model}' " + f"with provider '{custom_llm_provider}'. Only text-embedding-3-* " + "models support this parameter. To drop it from the call, set " + "`litellm.drop_params = True`." + ), + ) final_params = add_provider_specific_params_to_optional_params( optional_params=optional_params,