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] Pass through - Langfuse don't log request to Langfuse passthrough on Langfuse (#11768)

Ishaan Jaff35d74af5a0ab
diff --git a/litellm/proxy/pass_through_endpoints/success_handler.py b/litellm/proxy/pass_through_endpoints/success_handler.py
index 4b098a818d7..b1908acdf87 100644
--- a/litellm/proxy/pass_through_endpoints/success_handler.py
+++ b/litellm/proxy/pass_through_endpoints/success_handler.py
@@ -48,6 +48,9 @@ class PassThroughEndpointLogging:
AssemblyAIPassthroughLoggingHandler()
)
+ # Langfuse
+ self.TRACKED_LANGFUSE_ROUTES = ["/langfuse/"]
+
async def _handle_logging(
self,
logging_obj: LiteLLMLoggingObj,
@@ -103,9 +106,9 @@ class PassThroughEndpointLogging:
standard_logging_response_object: Optional[
PassThroughEndpointLoggingResultValues
] = None
- logging_obj.model_call_details[
- "passthrough_logging_payload"
- ] = passthrough_logging_payload
+ logging_obj.model_call_details["passthrough_logging_payload"] = (
+ passthrough_logging_payload
+ )
if self.is_vertex_route(url_route):
vertex_passthrough_logging_handler_result = (
VertexPassthroughLoggingHandler.vertex_passthrough_handler(
@@ -181,6 +184,9 @@ class PassThroughEndpointLogging:
**kwargs,
)
return
+ elif self.is_langfuse_route(url_route):
+ # Don't log langfuse pass-through requests
+ return
if standard_logging_response_object is None:
standard_logging_response_object = StandardPassThroughResponseObject(
@@ -221,3 +227,10 @@ class PassThroughEndpointLogging:
elif "/transcript" in parsed_url.path:
return True
return False
+
+ def is_langfuse_route(self, url_route: str):
+ parsed_url = urlparse(url_route)
+ for route in self.TRACKED_LANGFUSE_ROUTES:
+ if route in parsed_url.path:
+ return True
+ return False
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py
index 3aa5240eaea..d5ffcd30f4d 100644
--- a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py
+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py
@@ -19,6 +19,9 @@ from litellm.proxy.pass_through_endpoints.pass_through_endpoints import (
HttpPassThroughEndpointHelpers,
pass_through_request,
)
+from litellm.proxy.pass_through_endpoints.success_handler import (
+ PassThroughEndpointLogging,
+)
# Test is_multipart
@@ -178,3 +181,90 @@ async def test_pass_through_request_failure_handler():
call_args["original_exception"], TypeError
) # Now expecting TypeError
assert "traceback_str" in call_args
+
+
+def test_is_langfuse_route():
+ """
+ Test that the is_langfuse_route method correctly identifies Langfuse routes
+ """
+ handler = PassThroughEndpointLogging()
+
+ # Test positive cases
+ assert (
+ handler.is_langfuse_route("http://localhost:4000/langfuse/api/public/traces")
+ == True
+ )
+ assert (
+ handler.is_langfuse_route(
+ "https://proxy.example.com/langfuse/api/public/sessions"
+ )
+ == True
+ )
+ assert handler.is_langfuse_route("/langfuse/api/public/ingestion") == True
+ assert handler.is_langfuse_route("http://localhost:4000/langfuse/") == True
+
+ # Test negative cases
+ assert (
+ handler.is_langfuse_route("https://api.openai.com/v1/chat/completions") == False
+ )
+ assert (
+ handler.is_langfuse_route("http://localhost:4000/anthropic/v1/messages")
+ == False
+ )
+ assert handler.is_langfuse_route("https://example.com/other") == False
+ assert handler.is_langfuse_route("") == False
+
+
+async def test_langfuse_passthrough_no_logging():
+ """
+ Test that langfuse pass-through requests skip logging by returning early
+ """
+ from datetime import datetime
+
+ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
+ from litellm.types.passthrough_endpoints.pass_through_endpoints import (
+ PassthroughStandardLoggingPayload,
+ )
+
+ handler = PassThroughEndpointLogging()
+
+ # Mock the logging object
+ mock_logging_obj = MagicMock(spec=LiteLLMLoggingObj)
+ mock_logging_obj.model_call_details = {}
+
+ # Mock httpx response for langfuse request
+ mock_response = MagicMock(spec=httpx.Response)
+ mock_response.text = '{"status": "success"}'
+
+ # Create langfuse URL
+ langfuse_url = "http://localhost:4000/langfuse/api/public/traces"
+
+ passthrough_logging_payload = PassthroughStandardLoggingPayload(
+ url=langfuse_url,
+ request_body={"test": "data"},
+ request_method="POST",
+ )
+
+ # Call the success handler with langfuse route
+ result = await handler.pass_through_async_success_handler(
+ httpx_response=mock_response,
+ response_body={"status": "success"},
+ logging_obj=mock_logging_obj,
+ url_route=langfuse_url,
+ result="",
+ start_time=datetime.now(),
+ end_time=datetime.now(),
+ cache_hit=False,
+ request_body={"test": "data"},
+ passthrough_logging_payload=passthrough_logging_payload,
+ )
+
+ # Should return None (early return) and not proceed with logging
+ assert result is None
+
+ # Verify that the passthrough_logging_payload was still set (this happens before the langfuse check)
+ assert (
+ mock_logging_obj.model_call_details["passthrough_logging_payload"]
+ == passthrough_logging_payload
+ )