mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(embeddings): drop dimensions param for openai_compatible_providers when drop_params=True
When using litellm.embedding() or litellm.aembedding() with an openai_compatible_provider (e.g. hosted_vllm, openrouter), the dimensions parameter was always forwarded to the upstream API even when drop_params=True. This caused 422 errors from any vLLM endpoint or compatible server that does not support dimensions. Root cause: the else branch in get_optional_params_embeddings() that handles openai_compatible_providers did a bare optional_params = non_default_params with no validation or drop_params handling. The OpenAI-specific branch correctly limits dimensions to text-embedding-3-* models but this guard was absent for the compatible-providers path. Fix: copy non_default_params and, when dimensions is present and the model is not text-embedding-3-*, either drop it (if drop_params is True) or raise UnsupportedParamsError, matching the behaviour of the dedicated provider branches. Fixes #23119
This commit is contained in:
parent
160e2d9642
commit
986c0eb900
1 changed files with 22 additions and 1 deletions
|
|
@ -3453,7 +3453,28 @@ def get_optional_params_embeddings( # noqa: PLR0915
|
|||
else:
|
||||
optional_params = non_default_params
|
||||
else:
|
||||
optional_params = non_default_params
|
||||
# openai_compatible_providers (e.g. hosted_vllm, openrouter, etc.)
|
||||
# Pass all params through, but honour drop_params for `dimensions`
|
||||
# because many vLLM / compatible endpoints don't support it and return
|
||||
# 422 when it is present. Only text-embedding-3-* models support it.
|
||||
optional_params = non_default_params.copy()
|
||||
if (
|
||||
"dimensions" in optional_params
|
||||
and model is not None
|
||||
and "text-embedding-3" not in model
|
||||
):
|
||||
if litellm.drop_params is True or drop_params is True:
|
||||
optional_params.pop("dimensions")
|
||||
else:
|
||||
raise UnsupportedParamsError(
|
||||
status_code=500,
|
||||
message=(
|
||||
f"Setting 'dimensions' is not supported for model '{model}' "
|
||||
f"with provider '{custom_llm_provider}'. Only text-embedding-3-* "
|
||||
"models support this parameter. To drop it from the call, set "
|
||||
"`litellm.drop_params = True`."
|
||||
),
|
||||
)
|
||||
|
||||
final_params = add_provider_specific_params_to_optional_params(
|
||||
optional_params=optional_params,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue