The Langfuse OpenAI wrapper crashes when an OpenAI-compatible provider returns a chat completion response with choices: null.
Traceback:
File ".../langfuse/openai.py", line 1065, in _wrap
model, completion, usage = _get_langfuse_data_from_default_response(...)
File ".../langfuse/openai.py", line 784, in _get_langfuse_data_from_default_response
if len(choices) > 0:
TypeError: object of type 'NoneType' has no len()
Expected behavior:
The wrapper should handle choices is None gracefully, either treating it like an empty list or preserving the original provider/API error, instead of raising an internal TypeError.
Observed behavior:
The original LLM call fails with a Langfuse wrapper TypeError, which hides the underlying provider response/error.
Environment:
- Python 3.12
- langfuse 4.13.0
- OpenAI-compatible chat completions endpoint
The Langfuse OpenAI wrapper crashes when an OpenAI-compatible provider returns a chat completion response with
choices: null.Traceback:
Expected behavior:
The wrapper should handle choices is None gracefully, either treating it like an empty list or preserving the original provider/API error, instead of raising an internal TypeError.
Observed behavior:
The original LLM call fails with a Langfuse wrapper TypeError, which hides the underlying provider response/error.
Environment: