fix(embedding): omit null encoding_format for openai requests (#25395)

This commit is contained in:
Utsab Dahal 2026-04-12 08:24:19 +05:45 committed by GitHub
parent 17e145a083
commit e3d160f158
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View file

@ -4913,9 +4913,6 @@ def embedding( # noqa: PLR0915
if encoding_format is not None:
optional_params["encoding_format"] = encoding_format
else:
# Omiting causes openai sdk to add default value of "float"
optional_params["encoding_format"] = None
api_version = None

View file

@ -0,0 +1,34 @@
from unittest.mock import patch
import litellm
@patch("litellm.main.openai_chat_completions.embedding", return_value={"ok": True})
def test_openai_embedding_does_not_send_encoding_format_when_unset(mock_embedding):
"""Regression test: do not send encoding_format=null to OpenAI-compatible APIs."""
litellm.embedding(
model="text-embedding-3-small",
input=["hello"],
api_base="https://example.com/v1",
api_key="test-key",
custom_llm_provider="openai",
)
optional_params = mock_embedding.call_args.kwargs["optional_params"]
assert "encoding_format" not in optional_params
@patch("litellm.main.openai_chat_completions.embedding", return_value={"ok": True})
def test_openai_embedding_preserves_explicit_encoding_format(mock_embedding):
"""Explicit encoding_format should still be forwarded."""
litellm.embedding(
model="text-embedding-3-small",
input=["hello"],
api_base="https://example.com/v1",
api_key="test-key",
custom_llm_provider="openai",
encoding_format="float",
)
optional_params = mock_embedding.call_args.kwargs["optional_params"]
assert optional_params["encoding_format"] == "float"