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
Support for is_streamed_request widh datadog (#14673)
katsuhiro mutoec61a7152adf
diff --git a/litellm/integrations/datadog/datadog_llm_obs.py b/litellm/integrations/datadog/datadog_llm_obs.pyindex 7ab82eb7847..2702192f637 100644--- a/litellm/integrations/datadog/datadog_llm_obs.py+++ b/litellm/integrations/datadog/datadog_llm_obs.py@@ -498,6 +498,7 @@ class DataDogLLMObsLogger(DataDogLogger, CustomBatchLogger):"guardrail_information": standard_logging_payload.get("guardrail_information", None),+ "is_streamed_request": self._get_stream_value_from_payload(standard_logging_payload),}#########################################################@@ -561,6 +562,31 @@ class DataDogLLMObsLogger(DataDogLogger, CustomBatchLogger):return latency_metrics+ def _get_stream_value_from_payload(self, standard_logging_payload: StandardLoggingPayload) -> bool:+ """+ Extract the stream value from standard logging payload.++ The stream field in StandardLoggingPayload is only set to True for completed streaming responses.+ For non-streaming requests, it's None. The original stream parameter is in model_parameters.++ Returns:+ bool: True if this was a streaming request, False otherwise+ """+ # Check top-level stream field first (only True for completed streaming)+ stream_value = standard_logging_payload.get("stream")+ if stream_value is True:+ return True++ # Fallback to model_parameters.stream for original request parameters+ model_params = standard_logging_payload.get("model_parameters", {})+ if isinstance(model_params, dict):+ stream_value = model_params.get("stream")+ if stream_value is True:+ return True++ # Default to False for non-streaming requests+ return False+def _get_spend_metrics(self, standard_logging_payload: StandardLoggingPayload) -> DDLLMObsSpendMetrics:diff --git a/tests/test_litellm/integrations/datadog/test_datadog_llm_observability.py b/tests/test_litellm/integrations/datadog/test_datadog_llm_observability.pyindex e715fec4ffd..d7db5ef00a0 100644--- a/tests/test_litellm/integrations/datadog/test_datadog_llm_observability.py+++ b/tests/test_litellm/integrations/datadog/test_datadog_llm_observability.py@@ -203,6 +203,9 @@ class TestDataDogLLMObsLogger:assert metadata["cache_hit"] is Trueassert metadata["cache_key"] == "test-cache-key-789"+ # Test 4: Verify is_streamed_request is in metadata+ assert metadata["is_streamed_request"] is True+def test_cache_metadata_fields(self, mock_env_vars, mock_response_obj):"""Test that cache-related metadata fields are correctly tracked"""with patch(