Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

serve: a chat request with no message is a 400 (messages must be a non-empty list), as OpenAI answers it; test

Niko12218a3ca07c4ec1
diff --git a/serve/frontend.py b/serve/frontend.py
index 53f2b4599..a70494f08 100644
--- a/serve/frontend.py
+++ b/serve/frontend.py
@@ -539,6 +539,13 @@ def tool_arguments(raw) -> dict:
return {"arguments": json.dumps(raw, ensure_ascii=False)}
+def require_messages(messages: list) -> None:
+ """A chat request with no message at all is a 400 (OpenAI: "empty array. Expected an array with minimum length 1"); the
+ template would otherwise render just the assistant turn and the model would answer nothing."""
+ if not messages:
+ raise ValueError("messages must be a non-empty list: send at least one message")
+
+
def openai_to_messages(req: dict) -> tuple[list[dict], list[dict] | None, dict]:
"""OpenAI Chat Completions -> (template messages, template tools, template kwargs)."""
messages = []
diff --git a/serve/server.py b/serve/server.py
index 71a55e1f0..3ed46d37b 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -61,7 +61,7 @@ ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tools"))
sys.path.insert(0, str(ROOT)) # run as a script (run-<model>.bat) as well as a module
from serve.frontend import (THINK_END, ChatTemplate, Event, OutputParser, anthropic_to_messages, # noqa: E402
- forced_call, images_of, literal_tags, mark_think_literals, openai_to_messages,
+ forced_call, images_of, literal_tags, mark_think_literals, openai_to_messages, require_messages,
tool_choice_of, unmark_think_literals)
from serve.mcp import McpCancelled, hub_from_config # noqa: E402
from serve import runconfig # noqa: E402
@@ -7136,6 +7136,7 @@ def make_handler(svc: Service):
req = svc.with_shared(req, "openai")
bias_api.normalize(req.get("logit_bias"), len(getattr(svc.tok, "tokens", ())) or None)
messages, tools, kw = openai_to_messages(req)
+ require_messages(messages) # an empty conversation is a 400, as OpenAI answers it, not a reply to nothing
self._no_local_images(messages)
if tool_choice_of(req.get("tool_choice"))[0] == "none": # as the Responses route: no tools are offered
tools = None
diff --git a/serve/test_frontend.py b/serve/test_frontend.py
index 676f23f17..24412ce37 100644
--- a/serve/test_frontend.py
+++ b/serve/test_frontend.py
@@ -3,7 +3,7 @@ import copy
from pathlib import Path
import unittest
-from serve.frontend import ChatTemplate, anthropic_to_messages, openai_to_messages
+from serve.frontend import ChatTemplate, anthropic_to_messages, openai_to_messages, require_messages
from serve.server import ByteTokenizer, MockEngine, Service
@@ -340,3 +340,12 @@ class FencedJsonCallInWrapper(unittest.TestCase):
other = [{"name": "other", "parameters": {}}]
calls, text = self.run_parser(raw, len(raw), False, tools=other)
self.assertEqual((calls, text), ([], raw))
+
+
+class EmptyConversation(unittest.TestCase):
+ def test_no_message_is_an_error_a_message_is_not(self):
+ with self.assertRaises(ValueError):
+ require_messages(openai_to_messages({"messages": []})[0])
+ with self.assertRaises(ValueError):
+ require_messages(openai_to_messages({})[0])
+ require_messages(openai_to_messages({"messages": [{"role": "user", "content": "hi"}]})[0])