diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py index a447dad0b1..b2eda5a8d3 100644 --- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py @@ -971,18 +971,23 @@ def _update_metadata_with_tags_in_header(request: Request, metadata: dict) -> di Used for google and vertex JS SDKs, and Azure passthrough Checks both 'tags' and 'x-litellm-tags' headers """ - # Initialize tags list if it doesn't exist - if "tags" not in metadata: - metadata["tags"] = [] - + tags_to_add = [] + # Check for 'tags' header first _tags = request.headers.get("tags") if _tags: - metadata["tags"].extend([tag.strip() for tag in _tags.split(",")]) + tags_to_add.extend([tag.strip() for tag in _tags.split(",")]) _tags = request.headers.get("x-litellm-tags") if _tags: - metadata["tags"].extend([tag.strip() for tag in _tags.split(",")]) + tags_to_add.extend([tag.strip() for tag in _tags.split(",")]) + + # Only add tags key if there are tags to add + if tags_to_add: + if "tags" not in metadata: + metadata["tags"] = [] + metadata["tags"].extend(tags_to_add) + return metadata