From 76e15655c2f12f5728c0f298579dfe91a19ea989 Mon Sep 17 00:00:00 2001 From: Hasnaat Hussain Date: Thu, 13 Aug 2026 00:40:26 +0500 Subject: [PATCH] test(utils): cover embedding dimension guard branches Signed-off-by: Hasnaat Hussain --- litellm/utils.py | 14 +++++--------- tests/test_litellm/test_utils.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index 7327816cd89..891a2e350ba 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3766,15 +3766,11 @@ def get_optional_params_embeddings( final_params.pop("extra_body", None) # High-performance check optimized to avoid allocations in hot paths - if (litellm.drop_params is True or drop_params is True) and ( - custom_llm_provider == "azure" or custom_llm_provider in litellm.openai_compatible_providers - ): - if ( - model is not None - and "text-embedding-3" not in model - and "dimensions" not in (allowed_openai_params or []) - ): - final_params.pop("dimensions", None) + if litellm.drop_params is True or drop_params is True: + if custom_llm_provider == "azure" or custom_llm_provider in litellm.openai_compatible_providers: + is_legacy_model = model is not None and "text-embedding-3" not in model + if is_legacy_model and "dimensions" not in (allowed_openai_params or []): + final_params.pop("dimensions", None) return final_params diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py index aaccf28110b..438c0e39908 100644 --- a/tests/test_litellm/test_utils.py +++ b/tests/test_litellm/test_utils.py @@ -761,6 +761,22 @@ def test_embedding_dimensions_drop_params_for_openai_compatible_provider(provide dimensions=512, ) assert preserved["dimensions"] == 512 + + litellm.drop_params = True + model_supported = litellm.utils.get_optional_params_embeddings( + model=f"{provider}/text-embedding-3-small", + custom_llm_provider=provider, + dimensions=512, + ) + assert model_supported["dimensions"] == 512 + + explicitly_allowed = litellm.utils.get_optional_params_embeddings( + model=f"{provider}/legacy-model", + custom_llm_provider=provider, + dimensions=512, + allowed_openai_params=["dimensions"], + ) + assert explicitly_allowed["dimensions"] == 512 finally: litellm.drop_params = previous_drop_params