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
test(newrelic): cover static default_team_settings per-team routing (#38857)
yucheng-berri30f32285103c
diff --git a/litellm/proxy/management_endpoints/team_callback_endpoints.py b/litellm/proxy/management_endpoints/team_callback_endpoints.pyindex 08346983f32..c2f5dbb4032 100644--- a/litellm/proxy/management_endpoints/team_callback_endpoints.py+++ b/litellm/proxy/management_endpoints/team_callback_endpoints.py@@ -252,7 +252,7 @@ async def add_team_callbacks(Use this if if you want different teams to have different success/failure callbacksParameters:- - callback_name (Literal["langfuse", "langsmith", "gcs"], required): The name of the callback to add+ - callback_name (str, required): The name of the callback to add, e.g. "langfuse", "langsmith", "gcs", "newrelic". The value is validated against the callbacks that support team-scoped credentials- callback_type (Literal["success", "failure", "success_and_failure"], required): The type of callback to add. One of:- "success": Callback for successful LLM calls- "failure": Callback for failed LLM calls@@ -268,6 +268,8 @@ async def add_team_callbacks(- langsmith_api_key: The API key for the Langsmith callback- langsmith_project: The project for the Langsmith callback- langsmith_base_url: The base URL for the Langsmith callback+ - newrelic_api_key: The ingest license key for the team's New Relic account; routes both LLM/agent traces and cost metrics to that account. Requires the proxy to run with LITELLM_OTEL_V2=true, otherwise this callback is rejected with a 400+ - newrelic_region: The New Relic region for the team's account ("us" or "eu"), riding the team's own keyExample curl:```diff --git a/tests/proxy_unit_tests/test_proxy_utils.py b/tests/proxy_unit_tests/test_proxy_utils.pyindex 3bde72ccd49..35de9961054 100644--- a/tests/proxy_unit_tests/test_proxy_utils.py+++ b/tests/proxy_unit_tests/test_proxy_utils.py@@ -1317,6 +1317,62 @@ def test_proxy_config_state_post_init_callback_call(monkeypatch):assert config["litellm_settings"]["default_team_settings"][0]["team_id"] == "test"+async def test_default_team_settings_newrelic_resolves_traces_and_metrics():+ """Static `default_team_settings` is the config-file twin of POST /team/callback.++ A team pinned to New Relic through `default_team_settings` must reach the+ same two loggers the dynamic path does: the per-team metrics logger (cost+ and usage) and the trace logger (LLM/agent spans). This proves the static+ path resolves both, not just one, so the config-file customer gets the+ same per-team routing as the API customer.+ """+ from litellm.litellm_core_utils.litellm_logging import Logging+ from litellm.proxy.litellm_pre_call_utils import LiteLLMProxyRequestSetup+ from litellm.proxy.proxy_server import ProxyConfig++ pc = ProxyConfig()+ pc.config = {+ "litellm_settings": {+ "default_team_settings": [+ {+ "team_id": "team-a",+ "success_callback": ["newrelic"],+ "newrelic_api_key": "team-a-ingest-key",+ "newrelic_region": "eu",+ }+ ]+ }+ }++ callback_metadata = LiteLLMProxyRequestSetup.add_team_based_callbacks_from_config(+ team_id="team-a",+ proxy_config=pc,+ )++ assert callback_metadata is not None+ assert callback_metadata.success_callback == ["newrelic"]+ assert callback_metadata.callback_vars == {+ "newrelic_api_key": "team-a-ingest-key",+ "newrelic_region": "eu",+ }++ logging_obj = Logging(+ model="gpt-3.5-turbo",+ messages=[{"role": "user", "content": "hi"}],+ stream=False,+ call_type="completion",+ start_time=None,+ litellm_call_id="static-nr-1",+ function_id="static-nr-1",+ )+ logging_obj._trusted_callback_vars = tuple(callback_metadata.callback_vars.items())++ resolved = logging_obj._resolve_dynamic_callback_string("newrelic")+ resolved_names = {type(logger).__name__ for logger in resolved}+ assert resolved_names == {"NewRelicMetricsLogger", "NewRelicLogger"}++def test_proxy_config_state_get_config_state_error():"""Ensures that get_config_state does not raise an error when the config is not a valid dictionarydiff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.tsindex 8a564a07489..81a2fefe32e 100644--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts@@ -15505,7 +15505,7 @@ export interface paths {* Use this if if you want different teams to have different success/failure callbacks** Parameters:- * - callback_name (Literal["langfuse", "langsmith", "gcs"], required): The name of the callback to add+ * - callback_name (str, required): The name of the callback to add, e.g. "langfuse", "langsmith", "gcs", "newrelic". The value is validated against the callbacks that support team-scoped credentials* - callback_type (Literal["success", "failure", "success_and_failure"], required): The type of callback to add. One of:* - "success": Callback for successful LLM calls* - "failure": Callback for failed LLM calls@@ -15521,6 +15521,8 @@ export interface paths {* - langsmith_api_key: The API key for the Langsmith callback* - langsmith_project: The project for the Langsmith callback* - langsmith_base_url: The base URL for the Langsmith callback+ * - newrelic_api_key: The ingest license key for the team's New Relic account; routes both LLM/agent traces and cost metrics to that account. Requires the proxy to run with LITELLM_OTEL_V2=true, otherwise this callback is rejected with a 400+ * - newrelic_region: The New Relic region for the team's account ("us" or "eu"), riding the team's own key** Example curl:* ```