From 91b9f7fef824a1658ab26242e1961236e6c7bc96 Mon Sep 17 00:00:00 2001 From: ghost <49853598+JSONbored@users.noreply.github.com> Date: Thu, 9 Jul 2026 01:39:35 -0700 Subject: [PATCH] fix(selfhost): keep advisory AI key explicit --- src/server.ts | 2 +- test/unit/selfhost-ai.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index 934f35190c..859f780d65 100644 --- a/src/server.ts +++ b/src/server.ts @@ -518,7 +518,7 @@ async function main(): Promise { const advisoryAi = process.env.AI_ADVISORY_BASE_URL ? createOpenAiCompatibleAi({ baseUrl: process.env.AI_ADVISORY_BASE_URL, - apiKey: process.env.AI_ADVISORY_API_KEY ?? process.env.OPENAI_API_KEY, + apiKey: process.env.AI_ADVISORY_API_KEY, model: process.env.AI_ADVISORY_MODEL, }) : undefined; diff --git a/test/unit/selfhost-ai.test.ts b/test/unit/selfhost-ai.test.ts index 50820780b3..661ec61810 100644 --- a/test/unit/selfhost-ai.test.ts +++ b/test/unit/selfhost-ai.test.ts @@ -117,6 +117,19 @@ describe("createOpenAiCompatibleAi (#979)", () => { expect(first?.body.model).toBe("llama3.1"); }); + it("only sends an Authorization header when this OpenAI-compatible provider has its own apiKey", async () => { + const authHeaders: Array = []; + vi.stubGlobal("fetch", vi.fn(async (_u: string, init?: RequestInit) => { + authHeaders.push(new Headers(init?.headers).get("authorization")); + return new Response(JSON.stringify({ choices: [{ message: { content: "ok" } }] }), { status: 200 }); + })); + + await createOpenAiCompatibleAi({ baseUrl: "http://advisory.local/v1" }).run("m", { prompt: "x" }); + await createOpenAiCompatibleAi({ baseUrl: "http://advisory.local/v1", apiKey: "sk-advisory" }).run("m", { prompt: "x" }); + + expect(authHeaders).toEqual([null, "Bearer sk-advisory"]); + }); + it("forwards providerOptions verbatim as the request's `options` field (#4327/#4335 num_ctx capping)", async () => { let body: Record | undefined; vi.stubGlobal("fetch", vi.fn(async (_u: string, init: { body: string }) => {