mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
Merge pull request #21715 from BerriAI/litellm_credential_tag_usage
[Feature] Inject Credential Name as Tag for Usage Page Filtering
This commit is contained in:
commit
5084fe9538
4 changed files with 90 additions and 0 deletions
|
|
@ -2019,6 +2019,16 @@ class Router:
|
|||
merged_tags.append(tag)
|
||||
kwargs[metadata_variable_name]["tags"] = merged_tags
|
||||
|
||||
## CREDENTIAL NAME AS TAG
|
||||
credential_name = deployment.get("litellm_params", {}).get(
|
||||
"litellm_credential_name"
|
||||
)
|
||||
if credential_name:
|
||||
existing_tags = kwargs[metadata_variable_name].get("tags") or []
|
||||
if credential_name not in existing_tags:
|
||||
existing_tags.append(credential_name)
|
||||
kwargs[metadata_variable_name]["tags"] = existing_tags
|
||||
|
||||
kwargs["model_info"] = model_info
|
||||
|
||||
kwargs["timeout"] = self._get_timeout(
|
||||
|
|
|
|||
|
|
@ -125,3 +125,4 @@ class TestGetLitellmParamsExplicitFields:
|
|||
def test_no_log_from_explicit_param(self):
|
||||
result = get_litellm_params(no_log=True)
|
||||
assert result["no-log"] is True
|
||||
|
||||
|
|
|
|||
|
|
@ -1355,3 +1355,5 @@ def test_get_error_information_error_code_priority():
|
|||
result = StandardLoggingPayloadSetup.get_error_information(no_code_exception)
|
||||
assert result["error_code"] == ""
|
||||
assert result["error_class"] == "NoCodeException"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2186,3 +2186,80 @@ def test_update_kwargs_with_deployment_merge_tools_request_overrides_tool_choice
|
|||
|
||||
# Request tool_choice should be preserved (merged tools still applied)
|
||||
assert kwargs["tool_choice"] == "none"
|
||||
|
||||
|
||||
def test_credential_name_injected_as_tag():
|
||||
"""
|
||||
Test that litellm_credential_name from deployment litellm_params
|
||||
is injected as a tag into metadata during _update_kwargs_with_deployment.
|
||||
"""
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "xai-model",
|
||||
"litellm_params": {
|
||||
"model": "xai/grok-4-1-fast",
|
||||
"litellm_credential_name": "xAI",
|
||||
},
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
kwargs: dict = {"metadata": {"tags": ["A.101"]}}
|
||||
deployment = router.get_deployment_by_model_group_name(
|
||||
model_group_name="xai-model"
|
||||
)
|
||||
router._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs)
|
||||
|
||||
assert "xAI" in kwargs["metadata"]["tags"]
|
||||
assert "A.101" in kwargs["metadata"]["tags"]
|
||||
|
||||
|
||||
def test_credential_name_not_duplicated_in_tags():
|
||||
"""
|
||||
Test that if the credential name already exists in the tags list,
|
||||
it is not duplicated.
|
||||
"""
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "xai-model",
|
||||
"litellm_params": {
|
||||
"model": "xai/grok-4-1-fast",
|
||||
"litellm_credential_name": "xAI",
|
||||
},
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
kwargs: dict = {"metadata": {"tags": ["xAI", "A.101"]}}
|
||||
deployment = router.get_deployment_by_model_group_name(
|
||||
model_group_name="xai-model"
|
||||
)
|
||||
router._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs)
|
||||
|
||||
assert kwargs["metadata"]["tags"].count("xAI") == 1
|
||||
|
||||
|
||||
def test_credential_name_not_injected_when_absent():
|
||||
"""
|
||||
Test that when no litellm_credential_name is set, tags are unchanged.
|
||||
"""
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "gpt-model",
|
||||
"litellm_params": {
|
||||
"model": "gpt-4o",
|
||||
},
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
kwargs: dict = {"metadata": {"tags": ["A.101"]}}
|
||||
deployment = router.get_deployment_by_model_group_name(
|
||||
model_group_name="gpt-model"
|
||||
)
|
||||
router._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs)
|
||||
|
||||
assert kwargs["metadata"]["tags"] == ["A.101"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue