diff --git a/src/commands/onboard-custom.ts b/src/commands/onboard-custom.ts index 2da4d9d8a61..20041dd9b90 100644 --- a/src/commands/onboard-custom.ts +++ b/src/commands/onboard-custom.ts @@ -211,7 +211,7 @@ function resolveAliasError(params: { return `Alias ${normalized} already points to ${existingKey}.`; } -function buildOpenAiHeaders(apiKey: string) { +function buildAzureOpenAiHeaders(apiKey: string) { const headers: Record = {}; if (apiKey) { headers["api-key"] = apiKey; @@ -219,6 +219,14 @@ function buildOpenAiHeaders(apiKey: string) { return headers; } +function buildOpenAiHeaders(apiKey: string) { + const headers: Record = {}; + if (apiKey) { + headers.Authorization = `Bearer ${apiKey}`; + } + return headers; +} + function buildAnthropicHeaders(apiKey: string) { const headers: Record = { "anthropic-version": "2023-06-01", @@ -311,16 +319,34 @@ async function requestOpenAiVerification(params: { modelId: params.modelId, endpointPath: "chat/completions", }); - return await requestVerification({ - endpoint, - headers: buildOpenAiHeaders(params.apiKey), - body: { - messages: [{ role: "user", content: "Hi" }], - temperature: 1, - max_completion_tokens: DEFAULT_MAX_TOKENS, - stream: false, - }, - }); + const isBaseUrlAzureUrl = isAzureUrl(params.baseUrl); + const headers = isBaseUrlAzureUrl + ? buildAzureOpenAiHeaders(params.apiKey) + : buildOpenAiHeaders(params.apiKey); + if (isBaseUrlAzureUrl) { + return await requestVerification({ + endpoint, + headers, + body: { + messages: [{ role: "user", content: "Hi" }], + temperature: 1, + max_completion_tokens: DEFAULT_MAX_TOKENS, + stream: false, + } + }); + } else { + return await requestVerification({ + endpoint, + headers, + body: { + model: params.modelId, + messages: [{ role: "user", content: "Hi" }], + temperature: 1, + max_tokens: 1, + stream: false, + } + }); + } } async function requestAnthropicVerification(params: {