From 7ed61b48238df977ab75d74a22ad5003abfc85e8 Mon Sep 17 00:00:00 2001 From: jenstandstad Date: Tue, 21 Apr 2026 19:45:46 +0200 Subject: [PATCH] Fix double /v1 path when routing to LM Studio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit call_openai() (httpx-based) appends /v1/chat/completions to the upstream URL. But base_url in the models table typically ends in /v1 (matching the OpenAI SDK convention used by the resolution job). Combining them produced /v1/v1/chat/completions → 404 from LM Studio. Strip a trailing /v1 from the stored base_url before passing it to call_openai() in the agent routing path. Co-Authored-By: Claude Sonnet 4.6 --- plugins/festinger/festinger/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/festinger/festinger/main.py b/plugins/festinger/festinger/main.py index c4fce01..1362650 100644 --- a/plugins/festinger/festinger/main.py +++ b/plugins/festinger/festinger/main.py @@ -727,7 +727,13 @@ async def _route_agent_chat( "content-type": "application/json", } else: - oai_upstream = agent_model.base_url or cfg.get("upstream_openai", "https://api.openai.com") + # call_openai() appends /v1/chat/completions to whatever upstream it gets. + # DB base_url often ends in /v1 (correct for the OpenAI SDK used by the + # resolution job), so strip that suffix to avoid /v1/v1/chat/completions. + raw_base = agent_model.base_url or cfg.get("upstream_openai", "https://api.openai.com") + oai_upstream = raw_base.rstrip("/") + if oai_upstream.endswith("/v1"): + oai_upstream = oai_upstream[:-3] oai_headers = { "authorization": f"Bearer {agent_model.api_key or 'lm-studio'}", "content-type": "application/json",