fix _update_metadata_with_tags_in_header

This commit is contained in:
Ishaan Jaffer 2025-12-05 17:19:11 -08:00
parent 83291d394e
commit 96e4c9e078

View File

@ -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