diff --git a/litellm/integrations/otel/model/payloads.py b/litellm/integrations/otel/model/payloads.py index 5bca8e01aec..91343c551e1 100644 --- a/litellm/integrations/otel/model/payloads.py +++ b/litellm/integrations/otel/model/payloads.py @@ -815,6 +815,7 @@ def _output_choices(response: Mapping[str, object]) -> tuple[Mapping[str, object or _search_choices(response) or _image_choices(response) or _binary_choices(response) + or _passthrough_choices(response) ) @@ -924,6 +925,13 @@ def _image_location(item: Mapping[str, object]) -> str | None: return f"b64_json image ({len(encoded) * 3 // 4 - encoded[-2:].count('=')} bytes)" +def _passthrough_choices(response: Mapping[str, object]) -> tuple[_Choice, ...]: + body: Final = response.get("response") + mapping: Final = as_str_mapping(body) + text: Final = json.dumps(dict(mapping)) if mapping is not None else as_str(body) + return (_text_choice(text),) if text else () + + def _binary_choices(response: Mapping[str, object]) -> tuple[_Choice, ...]: size: Final = as_int(response.get("num_bytes")) if size is None: diff --git a/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py b/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py index ca7a9b424ad..a8938678858 100644 --- a/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py +++ b/tests/unit/integrations/otel/test_otel_v2_vendor_mappers.py @@ -702,6 +702,8 @@ def test_langfuse_mapper_renders_an_ocr_call_with_the_page_markdown_as_output(): ("amoderation", {"results": [{"flagged": True, "categories": {"violence": True}}]}, "flagged: violence"), ("aimage_generation", {"data": [{"b64_json": "QUJDRA=="}]}, "b64_json image (4 bytes)"), ("aspeech", {"object": "binary", "content_type": "audio/mpeg", "num_bytes": 9}, "audio/mpeg (9 bytes)"), + ("pass_through_endpoint", {"response": '{"answers": {"q": 0.9}}'}, '{"answers": {"q": 0.9}}'), + ("pass_through_endpoint", {"response": {"answers": {"q": 0.9}}}, '{"answers": {"q": 0.9}}'), ], ) def test_langfuse_mapper_renders_every_non_chat_route_output_as_an_assistant_message(