From a87129eb617b1f7f315995e74878dbf18834b6ae Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 24 Sep 2026 10:36:57 +0200 Subject: [PATCH] fix: return upstream errors to direct API callers instead of 200 null API clients calling /api/chat/completions with a message id and a chat_id (or parent_id null), but without a session_id, got HTTP 200 with a body of `null` whenever the upstream model failed. The error was saved into the chat, but the caller had nothing to branch on, so a failed request looked exactly like an empty answer. These requests are answered synchronously, so the error handler now raises the same 400 with the upstream message that plain API calls already get. The error is still written to the chat message first. Requests with a session_id keep running as background tasks and report errors over the socket, so the web UI, automations, channels and subagents are unchanged. Verified against a mock Ollama returning 400: plain calls, chat_id + id and new-chat requests now all return 400 with the provider message. Successful completions (streaming and non-streaming) and session-based requests return the same responses as before. Fixes #28938 --- backend/open_webui/main.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 3e0f9db89f..dc1498b577 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1709,11 +1709,8 @@ async def chat_completion( except Exception: pass - else: - # No chat_id/message_id → legacy/direct API path with no - # WebSocket error channel. We must surface the error as - # a proper HTTP response; without this the function would - # return None which FastAPI serializes as null. #23924 + # Legacy/direct callers await this response; returning None would send `null`. #23924 + if not (metadata.get('session_id') and metadata.get('chat_id')): raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail=error_detail,