Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix _update_metadata_with_tags_in_header

Ishaan Jaffer96e4c9e078b4
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
index a447dad0b19..b2eda5a8d38 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