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) }