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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat: forward-port dd user_email span tag and model hub description from internal staging (#42749)
devin-ai-integration[bot]31e2ce142776
diff --git a/litellm/proxy/dd_span_tagger.py b/litellm/proxy/dd_span_tagger.pyindex 55f3ecf4da3..08a99e363cd 100644--- a/litellm/proxy/dd_span_tagger.py+++ b/litellm/proxy/dd_span_tagger.py@@ -36,11 +36,15 @@ class DDSpanTagger:- ``litellm.key_alias`` — human-readable alias for the API key- ``litellm.key_hash`` — hashed API key (safe to log; never the raw secret)- ``litellm.requested_model``— model name as sent by the client+ - ``litellm.user_email`` — email of the authenticated userUse cases:- Trace all requests from a specific user/key: filter by ``litellm.key_alias`` or``litellm.key_hash``.- Trace all requests for a specific model: filter by ``litellm.requested_model``.+ - Trace all requests from a specific person under JWT auth, where there is no key_alias:+ filter by ``@litellm.user_email:"[email protected]"``. The value comes from the JWT claim+ mapped by ``litellm_jwtauth.user_email_jwt_field``, or from the user row for virtual keys.Note: key_alias / key_hash are not available for unauthenticated (e.g. 401) requests."""@@ -51,8 +55,10 @@ class DDSpanTagger:set_active_span_tag("litellm.key_hash", str(user_api_key_dict.token))if requested_model:set_active_span_tag("litellm.requested_model", str(requested_model))+ if user_api_key_dict.user_email:+ set_active_span_tag("litellm.user_email", str(user_api_key_dict.user_email))except Exception:verbose_proxy_logger.debug(- "Failed to tag active ddtrace span with key/model tags",+ "Failed to tag active ddtrace span with key/model/user tags",exc_info=True,)diff --git a/litellm/router.py b/litellm/router.pyindex fd16c289b0d..cdede46ef5c 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -11396,6 +11396,10 @@ class Router:reasoning_efforts_initialized = Falsereasoning_efforts_unknown = Falsemodel_list: Final = self.get_model_list_of_routed_group(model_group)+ model_group_description: Final[str | None] = next(+ (d for d in (_configured_model_info(m).get("description") for m in model_list) if isinstance(d, str)),+ None,+ )for model in model_list:is_match = Falseif (@@ -11501,6 +11505,7 @@ class Router:**{"model_group": user_facing_model_group_name,"providers": [llm_provider],+ "description": model_group_description,**model_info,"supports_fast_mode": True,"supported_reasoning_efforts": None,diff --git a/litellm/types/router.py b/litellm/types/router.pyindex cbe332dab12..273edf0f913 100644--- a/litellm/types/router.py+++ b/litellm/types/router.py@@ -926,6 +926,7 @@ class ModelGroupInfo(LiteLLMBaseModel):supported_reasoning_efforts: tuple[str, ...] | None = Field(default=None)supported_openai_params: list[str] | None = Field(default=[])configurable_clientside_auth_params: CONFIGURABLE_CLIENTSIDE_AUTH_PARAMS = None+ description: str | None = Nonedef __init__(self, **data) -> None:for field_name, field_type in _resolved_annotations(self.__class__).items():diff --git a/tests/unit/proxy/test_common_request_processing.py b/tests/unit/proxy/test_common_request_processing.pyindex 0f66674daf9..3eb542f223e 100644--- a/tests/unit/proxy/test_common_request_processing.py+++ b/tests/unit/proxy/test_common_request_processing.py@@ -3890,14 +3890,19 @@ class TestStreamingOverheadHeader:class TestDDSpanTaggerTagRequest:"""Tests for DDSpanTagger.tag_request - key/model DD span tagging."""- def _make_user_api_key_dict(self, key_alias=None, token=None):+ def _make_user_api_key_dict(self, key_alias=None, token=None, user_email=None):from litellm.proxy._types import UserAPIKeyAuthd = UserAPIKeyAuth()d.key_alias = key_aliasd.token = token+ d.user_email = user_emailreturn d+ def _tracer_with_active_span_writing_to(self, tags: dict[str, str]) -> SimpleNamespace:+ span = SimpleNamespace(set_tag_str=tags.__setitem__)+ return SimpleNamespace(current_span=lambda: span)+def test_tags_key_alias_and_model(self):"""key_alias and requested_model are set on the span when present."""user_key = self._make_user_api_key_dict(key_alias="my-prod-key", token="hashed123")@@ -3936,6 +3941,32 @@ class TestDDSpanTaggerTagRequest:mock_set_tag.assert_called_once_with("litellm.requested_model", "claude-3-5-sonnet")+ def test_tags_user_email(self):+ """user_email is tagged so JWT-authenticated requests are traceable per person."""+ user_key = self._make_user_api_key_dict(user_email="[email protected]")+ tags: dict[str, str] = {}++ with patch("litellm.litellm_core_utils.dd_tracing.tracer", self._tracer_with_active_span_writing_to(tags)):+ DDSpanTagger.tag_request(+ user_api_key_dict=user_key,+ requested_model=None,+ )++ assert tags == {"litellm.user_email": "[email protected]"}++ def test_no_user_email_tag_when_absent(self):+ """No user email tag when the authenticated identity has no email."""+ user_key = self._make_user_api_key_dict(key_alias="my-prod-key", user_email=None)+ tags: dict[str, str] = {}++ with patch("litellm.litellm_core_utils.dd_tracing.tracer", self._tracer_with_active_span_writing_to(tags)):+ DDSpanTagger.tag_request(+ user_api_key_dict=user_key,+ requested_model="gpt-4o",+ )++ assert tags == {"litellm.key_alias": "my-prod-key", "litellm.requested_model": "gpt-4o"}+class TestHasAttributeErrorInChain:"""Tests for _has_attribute_error_in_chain helper."""diff --git a/tests/unit/test_router/test_router.py b/tests/unit/test_router/test_router.pyindex 3f5450ea36b..8c9d1b5642d 100644--- a/tests/unit/test_router/test_router.py+++ b/tests/unit/test_router/test_router.py@@ -2318,6 +2318,31 @@ def test_model_group_info_cost_none_for_unpriced_deployment_but_zero_when_declarassert priced.output_cost_per_token is not None and priced.output_cost_per_token > 0+def test_model_group_info_description_from_model_info():+ """+ model_info.description set in the config should surface on ModelGroupInfo,+ including when only a later deployment in the group carries it.+ """+ router = litellm.Router(+ model_list=[+ {+ "model_name": "gpt-4",+ "litellm_params": {"model": "gpt-4", "api_key": "fake"},+ "model_info": {},+ },+ {+ "model_name": "gpt-4",+ "litellm_params": {"model": "gpt-4", "api_key": "fake2"},+ "model_info": {"description": "State-of-the-art language model."},+ },+ ]+ )++ result = router.get_model_group_info("gpt-4")+ assert result is not None+ assert result.description == "State-of-the-art language model."++def _alias_cost_router() -> Router:return Router(model_list=[diff --git a/ui/litellm-dashboard/src/components/AIHub/ModelHubTable.tsx b/ui/litellm-dashboard/src/components/AIHub/ModelHubTable.tsxindex e5dcb8ebc73..41b57a78eef 100644--- a/ui/litellm-dashboard/src/components/AIHub/ModelHubTable.tsx+++ b/ui/litellm-dashboard/src/components/AIHub/ModelHubTable.tsx@@ -684,6 +684,12 @@ const ModelHubTable: React.FC<ModelHubTableProps> = ({))}</div></div>+ {selectedModel.description && (+ <div className="col-span-2">+ <p className="font-medium">Description:</p>+ <p className="mt-1">{selectedModel.description}</p>+ </div>+ )}</div></div>diff --git a/ui/litellm-dashboard/src/components/AIHub/ModelHubTableColumns.tsx b/ui/litellm-dashboard/src/components/AIHub/ModelHubTableColumns.tsxindex fc71a9340ac..3d6423f2d44 100644--- a/ui/litellm-dashboard/src/components/AIHub/ModelHubTableColumns.tsx+++ b/ui/litellm-dashboard/src/components/AIHub/ModelHubTableColumns.tsx@@ -31,6 +31,7 @@ export interface ModelHubData {supports_function_calling: boolean;supported_openai_params?: string[];is_public_model_group: boolean;+ description?: string;[key: string]: any;}diff --git a/ui/litellm-dashboard/src/components/PublicModelHubTableColumns.tsx b/ui/litellm-dashboard/src/components/PublicModelHubTableColumns.tsxindex de987360791..2fae8044d6b 100644--- a/ui/litellm-dashboard/src/components/PublicModelHubTableColumns.tsx+++ b/ui/litellm-dashboard/src/components/PublicModelHubTableColumns.tsx@@ -25,6 +25,7 @@ export interface ModelGroupInfo {health_status?: string;health_response_time?: number;health_checked_at?: string;+ description?: string;[key: string]: any;}diff --git a/ui/litellm-dashboard/src/components/public_model_hub.tsx b/ui/litellm-dashboard/src/components/public_model_hub.tsxindex 6102ed9556a..20daee4d006 100644--- a/ui/litellm-dashboard/src/components/public_model_hub.tsx+++ b/ui/litellm-dashboard/src/components/public_model_hub.tsx@@ -714,6 +714,12 @@ const PublicModelHub: React.FC<PublicModelHubProps> = ({ accessToken, isEmbedded})}</div></div>+ {selectedModel.description && (+ <div className="col-span-2">+ <p className="font-medium">Description:</p>+ <p className="mt-1">{selectedModel.description}</p>+ </div>+ )}</div>{/* Wildcard Routing Note */}diff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.tsindex f78cd23bc96..9853a71a2ed 100644--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts@@ -37726,6 +37726,8 @@ export interface components {ModelGroupInfoProxy: {/** Configurable Clientside Auth Params */configurable_clientside_auth_params?: (string | components["schemas"]["ConfigurableClientsideParamsCustomAuth-Output"])[] | null;+ /** Description */+ description?: string | null;/** Health Checked At */health_checked_at?: string | null;/** Health Response Time */