fix(gemini): filter params from embedding requests - #24370
Merged
Chesars merged 1 commit intoMar 22, 2026
Merged
Conversation
The Gemini batch embedding transformation was spreading all optional_params into the request body via **gemini_params. Params like max_tokens (injected by add_provider_specific_params_to_optional_params) would reach the Gemini API and cause a 400 BadRequestError. Extract _filter_embed_params() that maps dimensions/task_type and keeps only the fields Gemini embeddings actually accept (outputDimensionality, taskType, title). Applied to both transform_openai_input_gemini_content and transform_openai_input_gemini_embed_content. This also fixes drop_params: true not preventing the error, since the param was re-injected after the drop_params check. Fixes BerriAI#24293
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis PR fixes a
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py | Extracts a _filter_embed_params() helper that maps OpenAI field names (dimensions → outputDimensionality, task_type → taskType) and whitelists only the three fields Gemini embeddings actually accept, preventing unsupported params like max_tokens from being spread into the request body. |
| tests/litellm/llms/vertex_ai/test_gemini_batch_embeddings.py | Adds four focused unit tests for the new _filter_embed_params helper and integration tests for both embedding endpoints; all tests are pure mock/unit tests with no real network calls. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["litellm.embedding() called\nwith optional_params\ne.g. {max_tokens: 256, dimensions: 768}"] --> B["_filter_embed_params(optional_params)"]
B --> C{"Map OpenAI keys"}
C -->|"dimensions → outputDimensionality"| D["Rename key"]
C -->|"task_type → taskType"| E["Rename key"]
C -->|other keys unchanged| F["Keep as-is"]
D & E & F --> G["Whitelist filter\n_SUPPORTED_EMBED_PARAMS\n= {outputDimensionality, taskType, title}"]
G -->|"key in whitelist"| H["Include in gemini_params"]
G -->|"key NOT in whitelist\ne.g. max_tokens, temperature"| I["Drop param ❌"]
H --> J{"Which endpoint?"}
J -->|"Text input"| K["transform_openai_input_gemini_content\n→ batchEmbedContents"]
J -->|"Multimodal input"| L["transform_openai_input_gemini_embed_content\n→ embedContent"]
K --> M["EmbedContentRequest(**gemini_params)\nNo 400 BadRequestError"]
L --> N["request_body dict(**gemini_params)\nNo 400 BadRequestError"]
Reviews (1): Last reviewed commit: "fix(gemini): filter unsupported params f..." | Re-trigger Greptile
Contributor
Chesars
merged commit Mar 22, 2026
335f4e8
into
BerriAI:litellm_staging_03_22_2026
38 of 39 checks passed
Chesars
added a commit
that referenced
this pull request
Apr 16, 2026
- streaming_iterator.py: adopted main's more defensive version of the tool-arg queueing check (.get() instead of [], isinstance guard) — same logic, same behavior, lower crash surface - model_prices_and_context_window.json + backup: combined staging's search_context_cost_per_query fields (PR #24372) with main's new supports_service_tier field — both are independent additions to the same Gemini model entries - test_streaming_handler.py: kept Azure streaming regression test (PR #24354) and added main's two new Gemini legacy vertex finish_reason normalization tests - test_gemini_batch_embeddings.py: kept staging's unsupported-params filtering tests (PR #24370) and added main's index/order test
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…op-unsupported-params fix(gemini): filter unsupported params from embedding requests
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
- streaming_iterator.py: adopted main's more defensive version of the tool-arg queueing check (.get() instead of [], isinstance guard) — same logic, same behavior, lower crash surface - model_prices_and_context_window.json + backup: combined staging's search_context_cost_per_query fields (PR BerriAI#24372) with main's new supports_service_tier field — both are independent additions to the same Gemini model entries - test_streaming_handler.py: kept Azure streaming regression test (PR BerriAI#24354) and added main's two new Gemini legacy vertex finish_reason normalization tests - test_gemini_batch_embeddings.py: kept staging's unsupported-params filtering tests (PR BerriAI#24370) and added main's index/order test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Fixes #24293
Pre-Submission checklist
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewType
🐛 Bug Fix
Changes
The Gemini batch embedding transformation spreads all
optional_paramsinto the request body via**gemini_params. Params likemax_tokens(injected byadd_provider_specific_params_to_optional_paramsfor non-OpenAI providers) reach the Gemini API and cause a400 BadRequestError.drop_params: truedoesn't prevent this because the param is re-injected after the drop_params check runs.Extract
_filter_embed_params()that mapsdimensions/task_typeand keeps only the fields Gemini embeddings accept (outputDimensionality,taskType,title). Applied to bothtransform_openai_input_gemini_contentandtransform_openai_input_gemini_embed_content.Tests added
test_filter_embed_params_drops_unsupported— verifies max_tokens/temperature are filteredtest_filter_embed_params_keeps_supported— verifies dimensions/task_type/title pass throughtest_batch_embed_content_drops_max_tokens— integration test for batchEmbedContents pathtest_embed_content_drops_max_tokens— integration test for embedContent path