diff --git a/litellm/utils.py b/litellm/utils.py index 0636d3683b7..1127090118e 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3197,6 +3197,12 @@ def _check_valid_arg(supported_params: Optional[list]): non_default_params=non_default_params, optional_params={}, kwargs=kwargs ) elif custom_llm_provider == "vertex_ai" or custom_llm_provider == "gemini": + # OpenAI SDKs (and litellm's own client) send encoding_format="float" + # by default; float lists are exactly what the vertex API returns, so + # the param is a no-op — don't reject the provider default. Other + # values (e.g. "base64") stay on the unsupported-param path below. + if non_default_params.get("encoding_format") == "float": + non_default_params.pop("encoding_format") supported_params = get_supported_openai_params( model=model, custom_llm_provider="vertex_ai", diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py index 6d515ecdc73..cb114ffcf04 100644 --- a/tests/test_litellm/test_utils.py +++ b/tests/test_litellm/test_utils.py @@ -4714,7 +4714,6 @@ def test_reports_key_missing(self): assert "TENCENT_API_KEY" in result["missing_keys"] - @pytest.mark.parametrize( "model", [ @@ -4741,3 +4740,53 @@ def test_gemini_image_models_do_not_support_reasoning( f"{model} incorrectly classified as reasoning-capable. " "Add 'supports_reasoning: false' to its model_cost entry." ) + + +class TestVertexEmbeddingEncodingFormat: + """vertex_ai/gemini embeddings must accept encoding_format="float" — it's + the OpenAI SDK default and float lists are exactly what the vertex API + returns. Other values keep the unsupported-param behavior (drop with + drop_params, raise otherwise). Issue #33173.""" + + def test_encoding_format_float_is_accepted_and_dropped(self): + optional_params = litellm.utils.get_optional_params_embeddings( + model="gemini-embedding-001", + encoding_format="float", + custom_llm_provider="vertex_ai", + ) + assert "encoding_format" not in optional_params + + def test_encoding_format_float_accepted_for_gemini_provider(self): + optional_params = litellm.utils.get_optional_params_embeddings( + model="gemini-embedding-001", + encoding_format="float", + custom_llm_provider="gemini", + ) + assert "encoding_format" not in optional_params + + def test_encoding_format_base64_still_rejected_without_drop_params(self): + with pytest.raises(Exception) as excinfo: + litellm.utils.get_optional_params_embeddings( + model="gemini-embedding-001", + encoding_format="base64", + custom_llm_provider="vertex_ai", + ) + assert "encoding_format" in str(excinfo.value) + + def test_encoding_format_base64_dropped_with_drop_params(self): + optional_params = litellm.utils.get_optional_params_embeddings( + model="gemini-embedding-001", + encoding_format="base64", + custom_llm_provider="vertex_ai", + drop_params=True, + ) + assert "encoding_format" not in optional_params + + def test_dimensions_still_mapped(self): + optional_params = litellm.utils.get_optional_params_embeddings( + model="gemini-embedding-001", + encoding_format="float", + dimensions=256, + custom_llm_provider="vertex_ai", + ) + assert optional_params.get("outputDimensionality") == 256