Fix double /v1 path when routing to LM Studio
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 <noreply@anthropic.com>
This commit is contained in:
@@ -727,7 +727,13 @@ async def _route_agent_chat(
|
|||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
}
|
}
|
||||||
else:
|
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 = {
|
oai_headers = {
|
||||||
"authorization": f"Bearer {agent_model.api_key or 'lm-studio'}",
|
"authorization": f"Bearer {agent_model.api_key or 'lm-studio'}",
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
|||||||
Reference in New Issue
Block a user