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
[Fix] DD logging - ensure key's metadata + guardrail is logged on DD (#15980)
Ishaan Jaff02df4c6b30ed
diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.pyindex 3534695d9f8..1e53655dd0b 100644--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@ -585,7 +585,8 @@ class LiteLLMProxyRequestSetup:if user_api_key_dict.budget_reset_atelse None),- user_api_key_auth_metadata=None,++ user_api_key_auth_metadata=user_api_key_dict.metadata,)return user_api_key_logged_metadatadiff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yamlindex c727d14dc99..f28af41c26a 100644--- a/litellm/proxy/proxy_config.yaml+++ b/litellm/proxy/proxy_config.yaml@@ -21,3 +21,6 @@ search_tools:litellm_params:search_provider: exa_aiapi_key: os.environ/EXA_API_KEY++litellm_settings:+ callbacks: ["datadog"]\ No newline at end of filediff --git a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py b/tests/test_litellm/proxy/test_litellm_pre_call_utils.pyindex bb95bd4109a..bcc0e5ac2d6 100644--- a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py+++ b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py@@ -1119,3 +1119,24 @@ def test_add_internal_user_from_user_mapping_no_header_or_mapping_returns_unchan)assert result is user_api_key_dictassert user_api_key_dict.user_id is None+++def test_get_sanitized_user_information_from_key_includes_guardrails_metadata():+ """+ Test that get_sanitized_user_information_from_key includes guardrails field from key metadata in the returned payload+ """+ user_api_key_dict = UserAPIKeyAuth(+ api_key="test-key-hash",+ key_alias="test-alias",+ user_id="test-user",+ metadata={"guardrails": ["presidio", "aporia"], "other_field": "value"},+ )++ result = LiteLLMProxyRequestSetup.get_sanitized_user_information_from_key(+ user_api_key_dict=user_api_key_dict+ )++ assert result["user_api_key_auth_metadata"] is not None+ assert "guardrails" in result["user_api_key_auth_metadata"]+ assert result["user_api_key_auth_metadata"]["guardrails"] == ["presidio", "aporia"]+ assert result["user_api_key_auth_metadata"]["other_field"] == "value"