Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: reject echo, suffix and best_of on /v1/completions that llama-server ignores (#11964)

Nilay46978653ff0c
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 71fe484df3e..c0e0a2b886b 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -30957,6 +30957,15 @@ def _completions_prompt_present(body: dict) -> bool:
return prompt is not None
+def _raise_ignored_completions_params(body: dict) -> None:
+ if body.get("echo"):
+ _raise_unsupported_openai_parameter("echo", "echo is not supported for completions.")
+ if body.get("suffix"):
+ _raise_unsupported_openai_parameter("suffix", "suffix is not supported for completions.")
+ if body.get("best_of") not in (None, 1, body.get("n")):
+ _raise_unsupported_openai_parameter("best_of", "best_of is not supported for completions.")
+
+
@router.post("/completions")
@account_access.gpu_busy_route
async def openai_completions(request: Request, current_subject: str = Depends(get_current_subject)):
@@ -30986,6 +30995,7 @@ async def openai_completions(request: Request, current_subject: str = Depends(ge
raise HTTPException(status_code = 400, detail = "'prompt' must be a string or array.")
if not _completions_prompt_present(_pre):
raise HTTPException(status_code = 400, detail = "'prompt' is required for completions.")
+ _raise_ignored_completions_params(_pre)
elif _pre is not _UNPARSEABLE_BODY:
# A valid JSON body that is not an object (e.g. [] or null) is rejected below as
# "Request body must be a JSON object"; reject it here, before the switch, so the
@@ -31009,6 +31019,7 @@ async def openai_completions(request: Request, current_subject: str = Depends(ge
body = await request.json()
if not isinstance(body, dict):
raise HTTPException(status_code = 400, detail = "Request body must be a JSON object")
+ _raise_ignored_completions_params(body)
# GGUF is loaded and the body is valid. The middleware claims the slot on a successful
# 2xx, so no claim here: llama-server can still return a non-2xx for a valid body (e.g. a
diff --git a/studio/backend/tests/test_openai_auto_switch.py b/studio/backend/tests/test_openai_auto_switch.py
index 8eb32b16b20..81fce22219b 100644
--- a/studio/backend/tests/test_openai_auto_switch.py
+++ b/studio/backend/tests/test_openai_auto_switch.py
@@ -4496,6 +4496,58 @@ def test_completions_rejects_object_prompt_before_switch(monkeypatch):
assert rec.calls == [] # no switch before rejection
+def _raise_reached(*_args, **_kwargs):
+ raise _Reached()
+
+
+_IGNORED_COMPLETIONS_PARAMS = [
+ ({"echo": True}, "echo"),
+ ({"suffix": " the end."}, "suffix"),
+ ({"best_of": 3}, "best_of"),
+ ({"best_of": 3, "n": 2}, "best_of"),
+ ({"best_of": 2, "stream": True}, "best_of"),
+]
+
+
[email protected]("extra, param", _IGNORED_COMPLETIONS_PARAMS)
+def test_completions_rejects_ignored_params_before_switch(monkeypatch, extra, param):
+ backend, rec = _wired(monkeypatch, _FakeBackend("org/A-GGUF"), ("/p/B", "Q8_0", "org/B-GGUF"))
+ body = {"model": "org/B-GGUF", "prompt": "hi", **extra}
+ with pytest.raises(HTTPException) as exc:
+ asyncio.run(inference_route.openai_completions(_json_body_request(body), "tester"))
+ assert exc.value.status_code == 400
+ assert exc.value.detail["error"]["code"] == "unsupported_parameter"
+ assert exc.value.detail["error"]["param"] == param
+ assert rec.calls == []
+
+
[email protected]("extra, param", _IGNORED_COMPLETIONS_PARAMS)
+def test_completions_rejects_ignored_params_without_switch(monkeypatch, extra, param):
+ backend, rec = _wired(monkeypatch, _FakeBackend("org/A-GGUF"), None, enabled = False)
+ monkeypatch.setattr(inference_route, "_fill_recommended_sampling_completions", _raise_reached)
+ body = {"prompt": "hi", "max_tokens": 8, **extra}
+ with pytest.raises(HTTPException) as exc:
+ asyncio.run(inference_route.openai_completions(_json_body_request(body), "tester"))
+ assert exc.value.status_code == 400
+ assert exc.value.detail["error"]["param"] == param
+
+
+ "extra",
+ [
+ {"echo": False, "suffix": "", "best_of": 1},
+ {"echo": None, "suffix": None, "best_of": None},
+ {"best_of": 2, "n": 2},
+ ],
+)
+def test_completions_default_ignored_params_still_proxy(monkeypatch, extra):
+ backend, rec = _wired(monkeypatch, _FakeBackend("org/A-GGUF"), None, enabled = False)
+ monkeypatch.setattr(inference_route, "_fill_recommended_sampling_completions", _raise_reached)
+ body = {"prompt": "hi", "max_tokens": 8, **extra}
+ with pytest.raises(_Reached):
+ asyncio.run(inference_route.openai_completions(_json_body_request(body), "tester"))
+
+
def test_embeddings_rejects_object_input_before_switch(monkeypatch):
# Codex P2: an object input like {"input": {}} is a deterministic client error
# (only a string or array is valid); reject before the switch, like completions.