From c894fa838d035ecd9a160339342371042697c327 Mon Sep 17 00:00:00 2001 From: kundeng Date: Mon, 20 Apr 2026 01:45:13 -0400 Subject: [PATCH] fix: persist Azure providerSpecificData and add connection test - Read body.providerSpecificData in POST /api/providers so Azure fields (endpoint, deployment, apiVersion, organization) are actually stored - Add azure case to testApiKeyConnection so the Test button works correctly instead of falling through to "not supported" Co-Authored-By: Claude Opus 4.6 --- src/app/api/providers/[id]/test/testUtils.js | 15 +++++++++++++++ src/app/api/providers/route.js | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/api/providers/[id]/test/testUtils.js b/src/app/api/providers/[id]/test/testUtils.js index c50abe34..8d4f94fb 100644 --- a/src/app/api/providers/[id]/test/testUtils.js +++ b/src/app/api/providers/[id]/test/testUtils.js @@ -365,6 +365,21 @@ async function testApiKeyConnection(connection, effectiveProxy = null) { try { switch (connection.provider) { + case "azure": { + const psd = connection.providerSpecificData || {}; + const endpoint = (psd.azureEndpoint || "").replace(/\/$/, ""); + const deployment = psd.deployment || "gpt-4"; + const apiVersion = psd.apiVersion || "2024-10-01-preview"; + const url = `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`; + const headers = { "api-key": connection.apiKey, "Content-Type": "application/json" }; + if (psd.organization) headers["OpenAI-Organization"] = psd.organization; + const res = await fetchWithConnectionProxy(url, { + method: "POST", headers, + body: JSON.stringify({ messages: [{ role: "user", content: "test" }], max_completion_tokens: 1 }), + }, effectiveProxy); + const valid = res.status !== 401 && res.status !== 403; + return { valid, error: valid ? null : "Invalid API key or Azure configuration" }; + } case "openai": { const res = await fetchWithConnectionProxy("https://api.openai.com/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy); return { valid: res.ok, error: res.ok ? null : "Invalid API key" }; diff --git a/src/app/api/providers/route.js b/src/app/api/providers/route.js index 639977c6..5e6b879c 100644 --- a/src/app/api/providers/route.js +++ b/src/app/api/providers/route.js @@ -114,7 +114,7 @@ export async function POST(request) { return NextResponse.json({ error: "Name is required" }, { status: 400 }); } - let providerSpecificData = null; + let providerSpecificData = body.providerSpecificData || null; if (isOpenAICompatibleProvider(provider)) { const node = await getProviderNodeById(provider);