diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index d959351d4c..81b47fcd26 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1833,7 +1833,7 @@ async def chat_completion( finally: raise # re-raise to ensure proper task cancellation handling except Exception as e: - log.debug(f'Error processing chat payload: {e}') + log.exception('Error processing chat payload: %s', e) if metadata.get('chat_id') and metadata.get('message_id'): # Update the chat message with the error try: diff --git a/backend/open_webui/routers/openai.py b/backend/open_webui/routers/openai.py index 51d4267c38..ce290d09b2 100644 --- a/backend/open_webui/routers/openai.py +++ b/backend/open_webui/routers/openai.py @@ -1192,6 +1192,22 @@ async def generate_chat_completion( # Check if response is SSE if 'text/event-stream' in r.headers.get('Content-Type', ''): + # If the provider returned an error status with SSE content-type, + # read the body and return a proper error response instead of + # streaming the error back (which hides the error from logs). + if r.status >= 400: + error_body = await r.text() + log.error( + 'Provider returned HTTP %d with SSE content-type: %s', + r.status, + error_body[:1000], + ) + try: + error_json = json.loads(error_body) + return JSONResponse(status_code=r.status, content=error_json) + except json.JSONDecodeError: + return PlainTextResponse(status_code=r.status, content=error_body) + streaming = True return StreamingResponse( stream_wrapper(r, session, stream_chunks_handler), diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index fb4912bef5..b9df0352c4 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -3077,6 +3077,8 @@ async def non_streaming_chat_response_handler(response, ctx): else: error = str(error) + log.error('Provider returned error (non-streaming): %s', error) + await Chats.upsert_message_to_chat_by_id_and_message_id( metadata['chat_id'], metadata['message_id'], @@ -3645,6 +3647,7 @@ async def streaming_chat_response_handler(response, ctx): if not choices: error = data.get('error', {}) if error: + log.error('Provider returned error (streaming): %s', error) try: await Chats.upsert_message_to_chat_by_id_and_message_id( metadata['chat_id'],