Fix: Vertex AI Gemini labels field provider-aware filtering - #14563
Merged
ishaan-jaff merged 4 commits intoSep 15, 2025
Merged
Conversation
- Test Google GenAI endpoints exclude labels even when explicitly provided - Test Vertex AI endpoints include labels when provided - Cover provider detection logic for different endpoint URLs - Verify metadata-to-labels conversion only happens for Vertex AI - Ensure edge cases are handled properly (null/empty api_base)
- Add _is_google_genai_endpoint() function to detect Google GenAI vs Vertex AI endpoints - Update _transform_request_body() to accept api_base parameter - Only include labels field for Vertex AI endpoints (not Google GenAI) - Pass api_base through sync/async transform functions - Maintain backward compatibility with existing usage - Fixes issue where Google GenAI requests failed with unsupported labels field
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This is really critical, any temp workaround for it ? |
ishaan-jaff
suggested changes
Sep 15, 2025
…arsing Replace URL-based endpoint detection with custom_llm_provider parameter checking for cleaner, more reliable provider identification. Changes: - Remove _is_google_genai_endpoint() helper function - Update labels condition to use custom_llm_provider != "gemini" - Remove api_base parameter from _transform_request_body() - Simplify sync/async transform function signatures - Update tests to reflect new parameter structure - Remove obsolete test_provider_detection test This approach aligns with existing codebase patterns where custom_llm_provider="gemini" identifies Google AI Studio endpoints that don't support labels, while vertex_ai/vertex_ai_beta identify Vertex AI endpoints that do support labels.
|
Might now be a good time to include updated error messages, so that litellm/litellm/litellm_core_utils/exception_mapping_utils.py Lines 1170 to 1363 in 30c3e7b |
ishaan-jaff
suggested changes
Sep 15, 2025
ghost
reviewed
Sep 16, 2025
| data["cachedContent"] = cached_content | ||
| if labels is not None: | ||
| # Only add labels for Vertex AI endpoints (not Google GenAI/AI Studio) and only if non-empty | ||
| if labels and custom_llm_provider != LlmProviders.GEMINI: |
There was a problem hiding this comment.
@timelfrink we should not do this check in here
it should be in the gemini/chat/transformation -
this is a cleaner separation
ishaan-jaff
pushed a commit
that referenced
this pull request
Sep 18, 2025
* Add comprehensive tests for Vertex AI Gemini labels provider filtering - Test Google GenAI endpoints exclude labels even when explicitly provided - Test Vertex AI endpoints include labels when provided - Cover provider detection logic for different endpoint URLs - Verify metadata-to-labels conversion only happens for Vertex AI - Ensure edge cases are handled properly (null/empty api_base) * Fix Vertex AI Gemini labels field provider-aware filtering - Add _is_google_genai_endpoint() function to detect Google GenAI vs Vertex AI endpoints - Update _transform_request_body() to accept api_base parameter - Only include labels field for Vertex AI endpoints (not Google GenAI) - Pass api_base through sync/async transform functions - Maintain backward compatibility with existing usage - Fixes issue where Google GenAI requests failed with unsupported labels field * Refactor labels filtering to use custom_llm_provider instead of URL parsing Replace URL-based endpoint detection with custom_llm_provider parameter checking for cleaner, more reliable provider identification. Changes: - Remove _is_google_genai_endpoint() helper function - Update labels condition to use custom_llm_provider != "gemini" - Remove api_base parameter from _transform_request_body() - Simplify sync/async transform function signatures - Update tests to reflect new parameter structure - Remove obsolete test_provider_detection test This approach aligns with existing codebase patterns where custom_llm_provider="gemini" identifies Google AI Studio endpoints that don't support labels, while vertex_ai/vertex_ai_beta identify Vertex AI endpoints that do support labels. * Use LlmProviders.GEMINI constant instead of hardcoded string
miguelangelmorenochacon
added a commit
to CartoDB/litellm
that referenced
this pull request
Oct 28, 2025
- Add LlmProviders import for provider filtering - Add metadata-to-labels conversion for OpenAI-style metadata - Add provider-aware filtering to exclude labels from Google GenAI/AI Studio - Update tests to verify correct behavior: * Labels are included for Vertex AI endpoints * Labels are excluded for Google GenAI endpoints * Metadata is converted to labels only for Vertex AI - Remove extra_body handling (not in upstream implementation) This aligns with the upstream BerriAI/litellm implementation that was merged through PRs BerriAI#9175, BerriAI#14563, and BerriAI#14448. Fixes BerriAI#13692 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
miguelangelmorenochacon
pushed a commit
to CartoDB/litellm
that referenced
this pull request
Oct 28, 2025
…14563) * Add comprehensive tests for Vertex AI Gemini labels provider filtering - Test Google GenAI endpoints exclude labels even when explicitly provided - Test Vertex AI endpoints include labels when provided - Cover provider detection logic for different endpoint URLs - Verify metadata-to-labels conversion only happens for Vertex AI - Ensure edge cases are handled properly (null/empty api_base) * Fix Vertex AI Gemini labels field provider-aware filtering - Add _is_google_genai_endpoint() function to detect Google GenAI vs Vertex AI endpoints - Update _transform_request_body() to accept api_base parameter - Only include labels field for Vertex AI endpoints (not Google GenAI) - Pass api_base through sync/async transform functions - Maintain backward compatibility with existing usage - Fixes issue where Google GenAI requests failed with unsupported labels field * Refactor labels filtering to use custom_llm_provider instead of URL parsing Replace URL-based endpoint detection with custom_llm_provider parameter checking for cleaner, more reliable provider identification. Changes: - Remove _is_google_genai_endpoint() helper function - Update labels condition to use custom_llm_provider != "gemini" - Remove api_base parameter from _transform_request_body() - Simplify sync/async transform function signatures - Update tests to reflect new parameter structure - Remove obsolete test_provider_detection test This approach aligns with existing codebase patterns where custom_llm_provider="gemini" identifies Google AI Studio endpoints that don't support labels, while vertex_ai/vertex_ai_beta identify Vertex AI endpoints that do support labels. * Use LlmProviders.GEMINI constant instead of hardcoded string
mateo-di
added a commit
to CartoDB/litellm
that referenced
this pull request
Nov 12, 2025
The upstream cherry-pick removed CARTO's provider-specific labels logic from PR BerriAI#14563. Google AI Studio (gemini provider) should NOT include labels field. This commit preserves BOTH fixes: - Upstream metadata None check (from commit 944176f) - CARTO provider-aware filtering (from PR BerriAI#14563 / commit 5748d6d)
mateo-di
added a commit
to CartoDB/litellm
that referenced
this pull request
Nov 14, 2025
* Optional `labels` field in Vertex AI request If the client sets the `labels` field in the request to the LiteLLM: - pass the `labels` field to the Vertex AI backend If the client sets the `metadata` field in the request to the LiteLLM: - if the `labels` field is not set, fill it with `metadata` key/value pairs for all string values * fix: check if metadata is not none * fix: remove tests for function not yet in carto/main The check_if_part_exists_in_parts function exists in upstream-sync-resolver/24 but not in carto/main yet. Removing tests until that branch is merged. * fix: restore provider-aware labels filtering The upstream cherry-pick removed CARTO's provider-specific labels logic from PR BerriAI#14563. Google AI Studio (gemini provider) should NOT include labels field. This commit preserves BOTH fixes: - Upstream metadata None check (from commit 944176f) - CARTO provider-aware filtering (from PR BerriAI#14563 / commit 5748d6d) --------- Co-authored-by: Vedran Vidović <vvidovic@gmail.com> Co-authored-by: Krrish Dholakia <krrishdholakia@gmail.com>
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…14563) * Add comprehensive tests for Vertex AI Gemini labels provider filtering - Test Google GenAI endpoints exclude labels even when explicitly provided - Test Vertex AI endpoints include labels when provided - Cover provider detection logic for different endpoint URLs - Verify metadata-to-labels conversion only happens for Vertex AI - Ensure edge cases are handled properly (null/empty api_base) * Fix Vertex AI Gemini labels field provider-aware filtering - Add _is_google_genai_endpoint() function to detect Google GenAI vs Vertex AI endpoints - Update _transform_request_body() to accept api_base parameter - Only include labels field for Vertex AI endpoints (not Google GenAI) - Pass api_base through sync/async transform functions - Maintain backward compatibility with existing usage - Fixes issue where Google GenAI requests failed with unsupported labels field * Refactor labels filtering to use custom_llm_provider instead of URL parsing Replace URL-based endpoint detection with custom_llm_provider parameter checking for cleaner, more reliable provider identification. Changes: - Remove _is_google_genai_endpoint() helper function - Update labels condition to use custom_llm_provider != "gemini" - Remove api_base parameter from _transform_request_body() - Simplify sync/async transform function signatures - Update tests to reflect new parameter structure - Remove obsolete test_provider_detection test This approach aligns with existing codebase patterns where custom_llm_provider="gemini" identifies Google AI Studio endpoints that don't support labels, while vertex_ai/vertex_ai_beta identify Vertex AI endpoints that do support labels. * Use LlmProviders.GEMINI constant instead of hardcoded string
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.
Title
Fix: Vertex AI Gemini labels field provider-aware filtering
Relevant issues
Fixes #14556
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🐛 Bug Fix
Changes
What this PR does
This PR fixes a critical issue where Google GenAI endpoints (generativelanguage.googleapis.com) failed when receiving requests with the
labelsfield, which is only supported by Vertex AI endpoints (aiplatform.googleapis.com). The fix implements provider-aware filtering to include labels only for Vertex AI endpoints while excluding them for Google GenAI endpoints.Problem being solved
Issue #14556 reported that when using LiteLLM with Google GenAI endpoints, requests would fail because the
labelsfield was being included in the request payload. Google GenAI's API doesn't support thelabelsfield (which is a Vertex AI specific feature), causing API errors and request failures.Core Implementation Changes
litellm/llms/vertex_ai/gemini/transformation.py:408-420: Added_is_google_genai_endpoint()helper function to detect Google GenAI vs Vertex AI endpoints based on the API base URLlitellm/llms/vertex_ai/gemini/transformation.py:427: Updated_transform_request_body()to acceptapi_baseparameter for provider detectionlitellm/llms/vertex_ai/gemini/transformation.py:508-509: Modified labels inclusion logic to only add labels for Vertex AI endpoints (not Google GenAI)litellm/llms/vertex_ai/gemini/transformation.py:561,609: Updated sync and async transform functions to passapi_baseparameter through the transformation chainTesting Changes
Added comprehensive test coverage in
tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py:test_google_genai_excludes_labels(): Verifies Google GenAI endpoints exclude labels even when explicitly providedtest_vertex_ai_includes_labels(): Confirms Vertex AI endpoints include labels when providedtest_provider_detection(): Tests the endpoint detection logic for various URL patternstest_metadata_to_labels_vertex_only(): Ensures metadata-to-labels conversion only happens for Vertex AIHow to verify it
Automated Verification
poetry run pytest tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py -vruff check litellm/llms/vertex_ai/gemini/transformation.pymypy litellm/llms/vertex_ai/gemini/transformation.pypoetry run pytest tests/test_litellm/test_completion.py -k vertex_ai -vManual Verification
Breaking changes
None - this is a backward-compatible bug fix that maintains existing functionality while fixing the Google GenAI compatibility issue.
Migration required
None - existing code will continue to work without changes.
Related issues/PRs