Pass router tags in request headers - x-litellm-tags (#8609)

* feat(litellm_pre_call_utils.py): support `x-litellm-tags` request header

allow tag based routing + spend tracking via request headers

* docs(request_headers.md): document new `x-litellm-tags` for tag based routing and spend tracking

* docs(tag_routing.md): add to docs

* fix(utils.py): only pass str values for openai metadata param

* fix(utils.py): drop non-str values for metadata param to openai

preview-feature, otel span was being sent in
This commit is contained in:
Krish Dholakia 2025-02-18 08:26:22 -08:00 committed by GitHub
parent 7bfd816d3b
commit 2340f1b31f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 122 additions and 22 deletions

View file

@ -1966,3 +1966,22 @@ def test_get_applied_guardrails(test_case):
# Assert
assert sorted(result) == sorted(test_case["expected"])
def test_add_openai_metadata():
from litellm.utils import add_openai_metadata
metadata = {
"user_api_key_end_user_id": "123",
"hidden_params": {"api_key": "123"},
"litellm_parent_otel_span": MagicMock(),
"none-val": None,
"int-val": 1,
"dict-val": {"a": 1, "b": 2},
}
result = add_openai_metadata(metadata)
assert result == {
"user_api_key_end_user_id": "123",
}