From a2fd56c31398dd375b3815e3be75968804fd0a01 Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com> Date: Thu, 4 Jun 2026 16:57:45 -0300 Subject: [PATCH] fix(llama-cpp): route to configured local baseUrl instead of OpenAI (#3136) (#3161) llama-cpp was missing from the local-provider group in buildUrl(), so it fell through to the OpenAI baseUrl and returned an OpenAI 401. Add the case to resolve the connection's providerSpecificData.baseUrl. Co-authored-by: tjengbudi --- open-sse/executors/default.ts | 1 + tests/unit/llama-cpp-local-url.test.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/unit/llama-cpp-local-url.test.ts diff --git a/open-sse/executors/default.ts b/open-sse/executors/default.ts index 91cfe9df6f..0d0e9989b0 100644 --- a/open-sse/executors/default.ts +++ b/open-sse/executors/default.ts @@ -205,6 +205,7 @@ export class DefaultExecutor extends BaseExecutor { const baseUrl = credentials?.providerSpecificData?.baseUrl || this.config.baseUrl; return normalizeOpenAIChatUrl(baseUrl); } + case "llama-cpp": case "lm-studio": case "modal": case "reka": diff --git a/tests/unit/llama-cpp-local-url.test.ts b/tests/unit/llama-cpp-local-url.test.ts new file mode 100644 index 0000000000..234bea1ae9 --- /dev/null +++ b/tests/unit/llama-cpp-local-url.test.ts @@ -0,0 +1,20 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { DefaultExecutor } from "@omniroute/open-sse/executors/default.ts"; + +// Regression for issue #3136: a `llama-cpp` local provider connection must send +// requests to the user's configured local baseUrl, not OpenAI's API. Before the +// fix, `llama-cpp` was missing from the local-provider case group in buildUrl(), +// so it fell through to the registry/default path and (because llama-cpp is not +// in the registry → DefaultExecutor falls back to PROVIDERS.openai) resolved to +// https://api.openai.com/v1/... — producing OpenAI-worded 401 "no api key" errors. +test("llama-cpp buildUrl routes to the configured local baseUrl, not OpenAI", () => { + const executor = new DefaultExecutor("llama-cpp"); + const url = executor.buildUrl("some-model", true, 0, { + providerSpecificData: { baseUrl: "http://127.0.0.1:8080/v1" }, + }); + + assert.equal(url, "http://127.0.0.1:8080/v1/chat/completions"); + assert.ok(!url.includes("api.openai.com"), `expected local URL, got ${url}`); +});