fix(embeddings): accept encoding_format='float' for vertex_ai/gemini embeddings (#33617)

OpenAI SDKs (and litellm's own client since ~1.84) send
encoding_format='float' by default, but the vertex embedding config only
supports ['dimensions'], so get_optional_params_embeddings raised
UnsupportedParamsError at the provider default value. Any
OpenAI-compatible client talking to a litellm proxy with vertex
embedding models got a 400 unless the operator set proxy-wide
drop_params: true.

Float lists are exactly what the vertex API returns, so the param is a
no-op: pop it before validation. Other values (e.g. 'base64') keep the
existing unsupported-param behavior (dropped with drop_params, raise
otherwise).

Fixes #33173

Co-authored-by: Mihidum Hettiyahandi <55163074+mihidumh@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
devin-ai-integration[bot] 2026-07-16 19:09:10 -07:00 • committed by GitHub
parent 229159c790
commit 69a476f791
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 56 additions and 1 deletions

View file

@ -3197,6 +3197,12 @@ def get_optional_params_embeddings(
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",

View file

@ -4714,7 +4714,6 @@ class TestValidateEnvironmentTencent:
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