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(team-callbacks): actually stop logging when disable_logging is called (#35520)

yucheng-berri7c8364c991b5
diff --git a/litellm/proxy/management_endpoints/team_callback_endpoints.py b/litellm/proxy/management_endpoints/team_callback_endpoints.py
index 8fab485cc7a..bdd8244427a 100644
--- a/litellm/proxy/management_endpoints/team_callback_endpoints.py
+++ b/litellm/proxy/management_endpoints/team_callback_endpoints.py
@@ -37,7 +37,10 @@ from litellm.proxy.litellm_pre_call_utils import (
_get_validated_callback_metadata,
convert_key_logging_metadata_to_callback,
)
-from litellm.proxy.management_endpoints.team_endpoints import _verify_team_access
+from litellm.proxy.management_endpoints.team_endpoints import (
+ _refresh_cached_team,
+ _verify_team_access,
+)
from litellm.proxy.management_helpers.utils import management_endpoint_wrapper
from litellm.repositories.team_repository import TeamRepository
@@ -262,7 +265,11 @@ async def add_team_callbacks(
"""
try:
from litellm.proxy._types import CommonProxyErrors
- from litellm.proxy.proxy_server import prisma_client
+ from litellm.proxy.proxy_server import (
+ prisma_client,
+ proxy_logging_obj,
+ user_api_key_cache,
+ )
if prisma_client is None:
raise HTTPException(
@@ -316,6 +323,17 @@ async def add_team_callbacks(
new_team_row = await TeamRepository(prisma_client).table.update(
where={"team_id": team_id},
data={"metadata": team_metadata_json}, # type: ignore
+ # `object_permission` is included so `_refresh_cached_team` doesn't
+ # write a cached team with the relation nulled out — see
+ # team_model_add for the full rationale.
+ include={"object_permission": True}, # mutable-ok: prisma include takes a dict literal
+ )
+
+ # Without this a newly registered callback stays dormant for existing keys.
+ await _refresh_cached_team(
+ team_row=new_team_row,
+ user_api_key_cache=user_api_key_cache,
+ proxy_logging_obj=proxy_logging_obj,
)
await _emit_team_callback_audit_log(
@@ -363,6 +381,9 @@ async def disable_team_logging(
"""
Disable all logging callbacks for a team
+ Callbacks registered through POST /team/{team_id}/callback and the Admin UI are cleared, so
+ re-enabling logging means registering them again with their callback_vars
+
Parameters:
- team_id (str, required): The unique identifier for the team
@@ -375,7 +396,11 @@ async def disable_team_logging(
"""
try:
- from litellm.proxy.proxy_server import prisma_client
+ from litellm.proxy.proxy_server import (
+ prisma_client,
+ proxy_logging_obj,
+ user_api_key_cache,
+ )
if prisma_client is None:
raise HTTPException(status_code=500, detail={"error": "No db connected"})
@@ -408,6 +433,9 @@ async def disable_team_logging(
# Update metadata
team_metadata["callback_settings"] = team_callback_settings_obj.model_dump()
+ # _get_dynamic_logging_metadata stops at metadata["logging"], where the API
+ # and Admin UI register callbacks, without ever reading callback_settings.
+ team_metadata["logging"] = [] # mutable-ok: the disabled state is persisted as an empty JSON array
team_metadata = encrypt_callback_vars(team_metadata)
team_metadata_json = json.dumps(team_metadata)
@@ -415,6 +443,10 @@ async def disable_team_logging(
updated_team = await TeamRepository(prisma_client).table.update(
where={"team_id": team_id},
data={"metadata": team_metadata_json}, # type: ignore
+ # `object_permission` is included so `_refresh_cached_team` doesn't
+ # write a cached team with the relation nulled out — see
+ # team_model_add for the full rationale.
+ include={"object_permission": True}, # mutable-ok: prisma include takes a dict literal
)
if updated_team is None:
@@ -423,6 +455,14 @@ async def disable_team_logging(
detail={"error": f"Team id = {team_id} does not exist. Error updating team logging"},
)
+ # Request-time callback resolution reads the cached team, so without this
+ # the DB says logging is off while live keys keep sending until it expires.
+ await _refresh_cached_team(
+ team_row=updated_team,
+ user_api_key_cache=user_api_key_cache,
+ proxy_logging_obj=proxy_logging_obj,
+ )
+
# Disabling a team's logging callbacks is itself a logging-control
# action — emit an audit-log row so the action remains traceable
# even though the team's own observability is now off.
diff --git a/tests/test_litellm/proxy/management_endpoints/test_team_callback_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_team_callback_endpoints.py
index 3b2b1ccb793..21e25d30b82 100644
--- a/tests/test_litellm/proxy/management_endpoints/test_team_callback_endpoints.py
+++ b/tests/test_litellm/proxy/management_endpoints/test_team_callback_endpoints.py
@@ -66,6 +66,23 @@ def _admin_auth() -> UserAPIKeyAuth:
)
[email protected](autouse=True)
+def stub_team_cache_refresh():
+ """Keep the cached-team refresh out of the way of the mocked prisma rows.
+
+ The endpoints under test now refresh the auth cache after their DB write.
+ That helper validates a real Prisma row into LiteLLM_TeamTableCachedObj,
+ which the MagicMock rows these tests use cannot satisfy. The refresh being
+ called at all is asserted explicitly in
+ test_disable_team_logging_refreshes_cached_team.
+ """
+ with patch(
+ "litellm.proxy.management_endpoints.team_callback_endpoints._refresh_cached_team",
+ new_callable=AsyncMock,
+ ) as refresh:
+ yield refresh
+
+
@pytest.fixture
def unauthorized_caller():
return UserAPIKeyAuth(
@@ -238,6 +255,9 @@ async def test_disable_team_logging_emits_audit_log_when_enabled(monkeypatch):
assert before["metadata"]["callback_settings"]["success_callback"] == ["langfuse"]
assert after["metadata"]["callback_settings"]["success_callback"] == []
assert after["metadata"]["callback_settings"]["failure_callback"] == []
+ # The audit row has to show the slot the callbacks actually live in, so a
+ # disable of a logging-configured team does not record an empty diff.
+ assert after["metadata"]["logging"] == []
@pytest.mark.asyncio
@@ -718,3 +738,207 @@ async def test_get_team_callbacks_reports_empty_for_team_without_callbacks():
"failure_callbacks": [],
"callback_vars": {},
}
+
+
+async def test_disable_team_logging_stops_callbacks_registered_via_api():
+ """Disabling logging must stop the callbacks that are actually running.
+
+ Callbacks registered through the API or the Admin UI live in
+ metadata["logging"], and request-time resolution stops at that slot without
+ reading callback_settings. Clearing only callback_settings therefore reports
+ success while the team keeps sending to its logging destination. This drives
+ the endpoint and then asks the real request-time resolver what the written
+ row would do.
+ """
+ from litellm.proxy.litellm_pre_call_utils import _get_dynamic_logging_metadata
+
+ metadata = {
+ "logging": [
+ {
+ "callback_name": "langsmith",
+ "callback_type": "success",
+ "callback_vars": {"langsmith_project": "tenant-project"},
+ }
+ ]
+ }
+ mock_prisma = _patch_prisma(_team_row(team_id="team-1", metadata=metadata))
+
+ with (
+ patch("litellm.proxy.proxy_server.prisma_client", mock_prisma),
+ patch("litellm.proxy.proxy_server.master_key", None),
+ ):
+ response = await disable_team_logging(
+ http_request=MagicMock(spec=Request),
+ team_id="team-1",
+ user_api_key_dict=_admin_auth(),
+ litellm_changed_by=None,
+ )
+
+ assert response["status"] == "success"
+ written = json.loads(mock_prisma.db.litellm_teamtable.update.await_args.kwargs["data"]["metadata"])
+ assert written["logging"] == []
+
+ resolved = _get_dynamic_logging_metadata(
+ UserAPIKeyAuth(api_key="hashed", team_id="team-1", team_metadata=written),
+ proxy_config=MagicMock(**{"load_team_config.return_value": {}}),
+ )
+ assert not (resolved.success_callback if resolved else None)
+ assert not (resolved.failure_callback if resolved else None)
+
+
+async def test_disable_team_logging_refreshes_cached_team(stub_team_cache_refresh):
+ """The DB write alone does not stop delivery.
+
+ Auth serves a cached team object and request-time callback resolution reads
+ the metadata off it, so without this refresh a key that is already in flight
+ keeps sending to the destination until the cache entry expires.
+ """
+ metadata = {
+ "logging": [
+ {
+ "callback_name": "langsmith",
+ "callback_type": "success",
+ "callback_vars": {"langsmith_project": "tenant-project"},
+ }
+ ]
+ }
+ mock_prisma = _patch_prisma(_team_row(team_id="team-1", metadata=metadata))
+
+ with (
+ patch("litellm.proxy.proxy_server.prisma_client", mock_prisma),
+ patch("litellm.proxy.proxy_server.master_key", None),
+ ):
+ await disable_team_logging(
+ http_request=MagicMock(spec=Request),
+ team_id="team-1",
+ user_api_key_dict=_admin_auth(),
+ litellm_changed_by=None,
+ )
+
+ stub_team_cache_refresh.assert_awaited_once()
+ refreshed = stub_team_cache_refresh.await_args.kwargs["team_row"]
+ assert refreshed is mock_prisma.db.litellm_teamtable.update.return_value
+ # The row fed to the cache has to carry object_permission, or the refresh
+ # publishes a team whose tool allowlists look empty, which reads as
+ # unrestricted on the search-tool and MCP-tool checks.
+ update_kwargs = mock_prisma.db.litellm_teamtable.update.await_args.kwargs
+ assert update_kwargs["include"]["object_permission"] is True
+
+
+async def test_add_team_callbacks_refreshes_cached_team(stub_team_cache_refresh):
+ """Registering a callback must take effect for keys that are already live."""
+ mock_prisma = _patch_prisma(_team_row(team_id="team-1", metadata={"logging": []}))
+
+ with (
+ patch("litellm.proxy.proxy_server.prisma_client", mock_prisma),
+ patch("litellm.proxy.proxy_server.master_key", None),
+ ):
+ await add_team_callbacks(
+ data=AddTeamCallback(
+ callback_name="langsmith",
+ callback_type="success",
+ callback_vars={"langsmith_project": "tenant-project"},
+ ),
+ http_request=MagicMock(spec=Request),
+ team_id="team-1",
+ user_api_key_dict=_admin_auth(),
+ litellm_changed_by=None,
+ )
+
+ stub_team_cache_refresh.assert_awaited_once()
+ refreshed = stub_team_cache_refresh.await_args.kwargs["team_row"]
+ assert refreshed is mock_prisma.db.litellm_teamtable.update.return_value
+ update_kwargs = mock_prisma.db.litellm_teamtable.update.await_args.kwargs
+ assert update_kwargs["include"]["object_permission"] is True
+
+
+async def test_disable_team_logging_clears_both_metadata_shapes():
+ """A team carrying both shapes ends up with neither active."""
+ from litellm.proxy.litellm_pre_call_utils import _get_dynamic_logging_metadata
+
+ metadata = {
+ "logging": [
+ {
+ "callback_name": "langsmith",
+ "callback_type": "success_and_failure",
+ "callback_vars": {"langsmith_project": "tenant-project"},
+ }
+ ],
+ "callback_settings": {
+ "success_callback": ["gcs_bucket"],
+ "failure_callback": ["langfuse"],
+ "callback_vars": {"gcs_bucket_name": "legacy-bucket"},
+ },
+ }
+ mock_prisma = _patch_prisma(_team_row(team_id="team-1", metadata=metadata))
+
+ with (
+ patch("litellm.proxy.proxy_server.prisma_client", mock_prisma),
+ patch("litellm.proxy.proxy_server.master_key", None),
+ ):
+ await disable_team_logging(
+ http_request=MagicMock(spec=Request),
+ team_id="team-1",
+ user_api_key_dict=_admin_auth(),
+ litellm_changed_by=None,
+ )
+
+ written = json.loads(mock_prisma.db.litellm_teamtable.update.await_args.kwargs["data"]["metadata"])
+ assert written["logging"] == []
+ assert written["callback_settings"]["success_callback"] == []
+ assert written["callback_settings"]["failure_callback"] == []
+
+ resolved = _get_dynamic_logging_metadata(
+ UserAPIKeyAuth(api_key="hashed", team_id="team-1", team_metadata=written),
+ proxy_config=MagicMock(**{"load_team_config.return_value": {}}),
+ )
+ assert not (resolved.success_callback if resolved else None)
+ assert not (resolved.failure_callback if resolved else None)
+
+
+async def test_disable_team_logging_leaves_team_re_enablable():
+ """The emptied slot must still accept a fresh registration afterwards."""
+ metadata = {
+ "logging": [
+ {
+ "callback_name": "langsmith",
+ "callback_type": "success",
+ "callback_vars": {"langsmith_project": "tenant-project"},
+ }
+ ]
+ }
+ row = _team_row(team_id="team-1", metadata=metadata)
+ mock_prisma = _patch_prisma(row)
+
+ with (
+ patch("litellm.proxy.proxy_server.prisma_client", mock_prisma),
+ patch("litellm.proxy.proxy_server.master_key", None),
+ ):
+ await disable_team_logging(
+ http_request=MagicMock(spec=Request),
+ team_id="team-1",
+ user_api_key_dict=_admin_auth(),
+ litellm_changed_by=None,
+ )
+ row.metadata = json.loads(mock_prisma.db.litellm_teamtable.update.await_args.kwargs["data"]["metadata"])
+ row.model_dump.return_value["metadata"] = row.metadata
+
+ await add_team_callbacks(
+ data=AddTeamCallback(
+ callback_name="langfuse",
+ callback_type="success",
+ callback_vars={"langfuse_public_key": "pk-lf-new"},
+ ),
+ http_request=MagicMock(spec=Request),
+ team_id="team-1",
+ user_api_key_dict=_admin_auth(),
+ litellm_changed_by=None,
+ )
+
+ written = json.loads(mock_prisma.db.litellm_teamtable.update.await_args.kwargs["data"]["metadata"])
+ assert [entry["callback_name"] for entry in written["logging"]] == ["langfuse"]
diff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.ts
index d24937fd672..58855f80b42 100644
--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts
+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts
@@ -14092,6 +14092,9 @@ export interface paths {
* Disable Team Logging
* @description Disable all logging callbacks for a team
*
+ * Callbacks registered through POST /team/{team_id}/callback and the Admin UI are cleared, so
+ * re-enabling logging means registering them again with their callback_vars
+ *
* Parameters:
* - team_id (str, required): The unique identifier for the team
*