From 44961d82d2eaec97158efabb5e613763f295bc60 Mon Sep 17 00:00:00 2001 From: Inoki Date: Mon, 21 Jul 2025 15:32:26 +0200 Subject: [PATCH] fix(provider-cloud): set apiKey in Azure AI Foundry endpoint (#195) * fix(providers-cloud): set string-type API key for Azure AI * Check apiKey anyway * Remove the unnecessary null check --- .../providers-cloud/src/providers/azure.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages-ext/providers-cloud/src/providers/azure.ts b/packages-ext/providers-cloud/src/providers/azure.ts index 3191bf7..186d387 100644 --- a/packages-ext/providers-cloud/src/providers/azure.ts +++ b/packages-ext/providers-cloud/src/providers/azure.ts @@ -73,18 +73,15 @@ export const createAzure = async (options: CreateAzureOptions) => { // For the extra steps to obtain the bearer token, please refer to the following links: // https://learn.microsoft.com/en-us/azure/api-management/api-management-authenticate-authorize-azure-openai // https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#authentication - if (typeof options.apiKey === 'function') { - init.headers ??= {} + const token = `Bearer ${typeof options.apiKey === 'function' ? await options.apiKey() : options.apiKey}` - const token = `Bearer ${await options.apiKey()}` - - if (Array.isArray(init.headers)) - init.headers.push(['Authorization', token]) - else if (init.headers instanceof Headers) - init.headers.append('Authorization', token) - else - init.headers.Authorization = token - } + init.headers ??= {} + if (Array.isArray(init.headers)) + init.headers.push(['Authorization', token]) + else if (init.headers instanceof Headers) + init.headers.append('Authorization', token) + else + init.headers.Authorization = token return globalThis.fetch(input, init) }