fix(embedding): respect drop_params for unsupported dimensions parameter - #26868
Conversation
The OpenAI-provider branch in `get_optional_params_embeddings` hard-raised `UnsupportedParamsError` whenever `dimensions` was passed to a non `text-embedding-3` model, even though the error message itself instructed users to set `litellm.drop_params=True`. The flag (per-call and global) was never consulted on this path, breaking the documented escape hatch for users proxying to vLLM/TEI/Ollama-compat embedding servers via the `openai/...` model prefix. Now mirror the `drop_params` handling already used by `_check_valid_arg` in the same function: when either `drop_params=True` (per-call) or `litellm.drop_params=True` (global) is set, silently strip `dimensions` from `non_default_params` and continue; otherwise preserve the existing error to keep current behavior for users who have not opted in. Adds two regression tests (per-call and global flag) and pins the existing raise-by-default behavior against accidental future drift. Fixes BerriAI#26787 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR fixes the
Confidence Score: 5/5Safe to merge — the change is a small, well-scoped guard added before an existing raise, default behaviour is unchanged, and new regression tests confirm both the fix and the fallback. The fix is minimal and surgical: a two-branch check wraps one existing raise, and the unconditional assignment of No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/utils.py | Structural rewrite of the dimensions guard in the OpenAI branch of get_optional_params_embeddings: checks drop_params before raising, then unconditionally assigns optional_params = non_default_params. |
| tests/local_testing/test_get_optional_params_embeddings.py | Adds two new regression tests for per-call and global drop_params, and adds try/finally state isolation to the existing raise test. Pre-existing tests (test_vertex_projects, test_bedrock_embed_v2_with_drop_params) still leak litellm.drop_params = True without restoring. |
Reviews (2): Last reviewed commit: "fixup: simplify drop_params guard per gr..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Drop the redundant `drop_params is not None and` prefix — `drop_params is True` already implies non-None. Behavior unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Pushed |
|
I noticed this was closed unmerged. Was this superseded by another change, or would you prefer a narrower follow-up PR against the current staging branch? The original failure mode was the unsupported |
|
Hi @xr843. Sorry to close your branch. This was done automatically because litellm_oss_staging was auto-deleted after being merged. We've since disabled branch auto-deletion. Reopening |
|
Can you add some screenshot or video proof of this working? I would like to see a before and after this PR please. Thank you for your contributions |
|
Hi @mateo-berri — thanks for re-opening, and here's the before/after proof you asked for. Since repro script (no API key needed)import litellm
from litellm import get_llm_provider
from litellm.utils import get_optional_params_embeddings
from litellm.exceptions import UnsupportedParamsError
model, provider, _, _ = get_llm_provider(model="openai/Qwen/Qwen3-Embedding-0.6B") # OpenAI-provider, NOT text-embedding-3
def run(label, *, drop_call=None, drop_global=False):
litellm.drop_params = drop_global
kw = dict(model=model, dimensions=1024, custom_llm_provider=provider)
if drop_call is not None:
kw["drop_params"] = drop_call
try:
out = get_optional_params_embeddings(**kw)
print(f"{label} -> {out} dimensions leaked? {'dimensions' in out}")
except UnsupportedParamsError:
print(f"{label} -> RAISED UnsupportedParamsError")
finally:
litellm.drop_params = False
run("A. default drop_params=False")
run("B. per-call drop_params=True", drop_call=True)
run("C. global litellm.drop_params=True", drop_global=True)❌ BEFORE (base
|
| scenario | BEFORE | AFTER |
|---|---|---|
default (drop_params=False) |
raises | raises (unchanged) |
per-call drop_params=True |
raises (bug) | dimensions stripped |
global litellm.drop_params=True |
raises (bug) | dimensions stripped |
Case A confirms default behavior is untouched; B and C show the documented drop_params=True escape hatch now actually works instead of dead-ending in a raise. The two new regression tests in tests/local_testing/test_get_optional_params_embeddings.py cover exactly B and C (and fail without the fix). Happy to attach a terminal screenshot too if you'd prefer, but this is fully reproducible from the snippet above. Thanks!
|
LGTM; thanks! |
9119403
into
BerriAI:litellm_oss_staging
Summary
Closes #26787. The OpenAI-provider branch in
get_optional_params_embeddingshard-raisedUnsupportedParamsErrorwheneverdimensionswas passed to a non-text-embedding-3model — even though the error message itself instructed users to setlitellm.drop_params=True. The flag (per-call and global) had no effect, so the documented escape hatch was a dead end.Root cause
litellm/utils.py:3304-3317short-circuited with a raise before honoringdrop_params. The same function's_check_valid_arg(lines 3252-3268) already respectslitellm.drop_params is True or drop_params is True, but this OpenAI-specific check bypassed that path entirely.Fix
Before raising, check
litellm.drop_params is True or drop_params is True. If true, popdimensionsfromnon_default_paramsand continue; otherwise preserve the original raise (default behavior unchanged). Then assignoptional_params = non_default_paramsunconditionally — when dropped,dimensionsis no longer in the dict, so it doesn't leak to the OpenAI request; when supported (text-embedding-3 or inallowed_openai_params), it passes through normally.Changes
litellm/utils.py(lines 3304-3324): structural rewrite of the dimensions checktests/local_testing/test_get_optional_params_embeddings.py:test_openai_non_text_embedding_3_with_per_call_drop_params— per-calldrop_params=Truesucceeds and emits nodimensionstest_openai_non_text_embedding_3_with_global_drop_params—litellm.drop_params=Truesucceeds likewiselitellm.drop_paramswithout restoring, which would otherwise contaminate this test under randomized order)Test plan
pytest tests/local_testing/test_get_optional_params_embeddings.py -v→ 7/7 passdrop_params=False(default) still raisestext-embedding-3andallowed_openai_paramspaths unchangedNotes
drop_paramsprecedence (per-call vs global) follows the existing_check_valid_argpattern: either being True wins. No new policy introduced.dimensionsfor openai_compatible_providers when drop_params=True #23120 (referenced in the issue thread) addresses a different branch in the same function (provider_config.map_openai_paramspath); orthogonal to this fix.BaseEmbeddingConfig.map_openai_paramsand already honordrop_paramsper provider config.