From fe622faa04f26b3a3afeffdc2ceab7d4c54e14c5 Mon Sep 17 00:00:00 2001 From: s-zx <2575376715@qq.com> Date: Mon, 9 Mar 2026 08:57:23 +0100 Subject: [PATCH] fix(embeddings): only drop dimensions for openai_compatible_providers when drop_params=True The previous implementation unconditionally raised UnsupportedParamsError whenever 'dimensions' was passed to an openai_compatible_provider and the model name did not contain 'text-embedding-3', regardless of drop_params. This was backwards-incompatible: providers such as Jina AI, Cohere, or any OpenRouter-routed model that legitimately accept 'dimensions' would suddenly raise a client-side error for callers who had never set drop_params. The correct behaviour mirrors how other unsupported-param guards work in LiteLLM: only drop (or act on) the parameter when the caller has opted in via drop_params=True. When drop_params is not set, forward the parameter as-is and let the upstream endpoint respond. --- litellm/utils.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index 53ab2d8eb6b..382f51788ef 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3454,27 +3454,20 @@ def get_optional_params_embeddings( # noqa: PLR0915 optional_params = non_default_params else: # 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. + # When drop_params=True, silently drop `dimensions` for models whose + # names do not contain "text-embedding-3", because many compatible + # endpoints (vLLM, etc.) return 422 when the parameter is present. + # When drop_params is not set we forward the parameter as-is: some + # compatible providers (Jina AI, Cohere via OpenRouter, …) do support + # `dimensions`, so raising unconditionally would break them. optional_params = non_default_params.copy() if ( "dimensions" in optional_params and model is not None and "text-embedding-3" not in model + and (litellm.drop_params is True or drop_params is True) ): - 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`." - ), - ) + optional_params.pop("dimensions") final_params = add_provider_specific_params_to_optional_params( optional_params=optional_params,