diff --git a/litellm/utils.py b/litellm/utils.py index e63bf402bf8..49e7fb3fd8f 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3309,12 +3309,19 @@ def get_optional_params_embeddings( # noqa: PLR0915 and "dimensions" in non_default_params.keys() and "dimensions" not in (allowed_openai_params or []) ): - raise UnsupportedParamsError( - status_code=500, - message="Setting dimensions is not supported for OpenAI `text-embedding-3` and later models. To drop it from the call, set `litellm.drop_params = True`.", - ) - else: - optional_params = non_default_params + # Honor drop_params (per-call) and litellm.drop_params (global) the same + # way `_check_valid_arg` does above. The raised error message itself + # tells users to set `drop_params=True`, so respect it here. + if litellm.drop_params is True or ( + drop_params is not None and drop_params is True + ): + non_default_params.pop("dimensions", None) + else: + raise UnsupportedParamsError( + status_code=500, + message="Setting dimensions is not supported for OpenAI `text-embedding-3` and later models. To drop it from the call, set `litellm.drop_params = True`.", + ) + optional_params = non_default_params elif custom_llm_provider == "triton": supported_params = get_supported_openai_params( model=model, diff --git a/tests/local_testing/test_get_optional_params_embeddings.py b/tests/local_testing/test_get_optional_params_embeddings.py index 8a94c8f4682..667207de789 100644 --- a/tests/local_testing/test_get_optional_params_embeddings.py +++ b/tests/local_testing/test_get_optional_params_embeddings.py @@ -97,12 +97,69 @@ def test_openai_non_text_embedding_3_without_allowed_openai_params_raises(): """ from litellm.exceptions import UnsupportedParamsError - model, custom_llm_provider, _, _ = get_llm_provider( - model="openai/nvidia/llama-3.2-nv-embedqa-1b-v2" - ) - with pytest.raises(UnsupportedParamsError): - get_optional_params_embeddings( + # ensure global drop_params is off (other tests in this file flip it on) + prev_drop_params = litellm.drop_params + litellm.drop_params = False + try: + model, custom_llm_provider, _, _ = get_llm_provider( + model="openai/nvidia/llama-3.2-nv-embedqa-1b-v2" + ) + with pytest.raises(UnsupportedParamsError): + get_optional_params_embeddings( + model=model, + dimensions=1024, + custom_llm_provider=custom_llm_provider, + ) + finally: + litellm.drop_params = prev_drop_params + + +def test_openai_non_text_embedding_3_drop_params_per_call(): + """ + Regression for https://github.com/BerriAI/litellm/issues/26787 + + When drop_params=True is passed per-call, `dimensions` should be silently + stripped for a non-`text-embedding-3` OpenAI-provider model instead of + raising UnsupportedParamsError. + """ + prev_drop_params = litellm.drop_params + litellm.drop_params = False # ensure only per-call flag is in effect + try: + model, custom_llm_provider, _, _ = get_llm_provider( + model="openai/Qwen/Qwen3-Embedding-0.6B" + ) + optional_params = get_optional_params_embeddings( + model=model, + dimensions=1024, + custom_llm_provider=custom_llm_provider, + drop_params=True, + ) + print(f"received optional_params: {optional_params}") + assert "dimensions" not in optional_params + finally: + litellm.drop_params = prev_drop_params + + +def test_openai_non_text_embedding_3_drop_params_global(): + """ + Regression for https://github.com/BerriAI/litellm/issues/26787 + + When `litellm.drop_params = True` is set globally, `dimensions` should be + silently stripped for a non-`text-embedding-3` OpenAI-provider model + instead of raising UnsupportedParamsError. + """ + prev_drop_params = litellm.drop_params + litellm.drop_params = True + try: + model, custom_llm_provider, _, _ = get_llm_provider( + model="openai/Qwen/Qwen3-Embedding-0.6B" + ) + optional_params = get_optional_params_embeddings( model=model, dimensions=1024, custom_llm_provider=custom_llm_provider, ) + print(f"received optional_params: {optional_params}") + assert "dimensions" not in optional_params + finally: + litellm.drop_params = prev_drop_params