fix: 🐛 forward labels parameter to Vertex AI API requests #15977
+5
−0
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.
Problem
The
labelsparameter was not being forwarded to Vertex AI API requests, preventing proper tracking of Google partnership labels for billing and analytics purposes.This issue prevented users from passing custom labels through the LiteLLM proxy to Vertex AI, which is important for resource tracking and billing attribution in Google Cloud environments.
Solution
This PR adds support for forwarding the
labelsparameter to Vertex AI API requests:Type Definition: Added
labelsfield to theRequestBodyTypedDict inlitellm/types/llms/vertex_ai.pyRequest Transformation: Modified
_transform_request_bodyinlitellm/llms/vertex_ai/gemini/transformation.pyto:labelsparameter and conversion from OpenAI-stylemetadata.requester_metadataTesting
The changes have been tested locally with Docker, verifying that:
"labels": {"goog-sample": "test-value"}Usage Example
Configuration
Expected Output
When using this configuration, labels are correctly forwarded to Vertex AI:
Note: The
labelsparameter is now successfully included in the request body.Changes
Modified Files
litellm/types/llms/vertex_ai.py- Added labels field to RequestBody typelitellm/llms/vertex_ai/gemini/transformation.py- Added labels extraction and forwarding logicRelated Issues
Fixes #13692
Additional Context
This implementation follows Google Cloud's labels specification and ensures backward compatibility by: