mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
fix(responses): raise on failed chat streams
This commit is contained in:
parent
09889e1986
commit
23f8466418
2 changed files with 43 additions and 0 deletions
|
|
@ -1444,6 +1444,18 @@ class OpenAiResponsesToChatCompletionStreamIterator(BaseModelResponseIterator):
|
|||
],
|
||||
usage=usage,
|
||||
)
|
||||
elif event_type in ("response.failed", "error"):
|
||||
response_data = parsed_chunk.get("response") or {}
|
||||
if not isinstance(response_data, dict):
|
||||
response_data = {}
|
||||
error_data = response_data.get("error") or parsed_chunk.get("error") or parsed_chunk
|
||||
error_message = error_data.get("message") if isinstance(error_data, dict) else None
|
||||
raise litellm.APIError(
|
||||
status_code=500,
|
||||
message=error_message or "Responses API stream failed",
|
||||
llm_provider="",
|
||||
model=response_data.get("model", ""),
|
||||
)
|
||||
else:
|
||||
pass
|
||||
# For any unhandled event types, create a minimal valid chunk or skip
|
||||
|
|
|
|||
|
|
@ -18,6 +18,37 @@ from litellm.completion_extras.litellm_responses_transformation.transformation i
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("chunk", "message"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"type": "response.failed",
|
||||
"response": {
|
||||
"model": "gpt-5.6-luna",
|
||||
"error": {"code": "server_error", "message": "upstream failed"},
|
||||
},
|
||||
},
|
||||
"upstream failed",
|
||||
),
|
||||
({"type": "error", "code": "server_error", "message": "stream failed"}, "stream failed"),
|
||||
(
|
||||
{"type": "response.failed", "response": "invalid", "error": {"message": "malformed failure"}},
|
||||
"malformed failure",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_response_stream_failure_raises_api_error(chunk, message):
|
||||
from litellm.completion_extras.litellm_responses_transformation.transformation import (
|
||||
OpenAiResponsesToChatCompletionStreamIterator,
|
||||
)
|
||||
|
||||
with pytest.raises(litellm.APIError, match=message) as exc_info:
|
||||
OpenAiResponsesToChatCompletionStreamIterator.translate_responses_chunk_to_openai_stream(chunk)
|
||||
|
||||
assert exc_info.value.status_code == 500
|
||||
|
||||
|
||||
def test_convert_chat_completion_messages_to_responses_api_image_input():
|
||||
from litellm.completion_extras.litellm_responses_transformation.transformation import (
|
||||
LiteLLMResponsesTransformationHandler,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue