in mod.ts [524:546]
protected override async prepareOptions(
opts: Core.FinalRequestOptions<unknown>,
): Promise<void> {
/**
* The user should provide a bearer token provider if they want
* to use Azure AD authentication. The user shouldn't set the
* Authorization header manually because the header is overwritten
* with the Azure AD token if a bearer token provider is provided.
*/
if (opts.headers?.["api-key"]) {
return super.prepareOptions(opts);
}
const token = await this._getAzureADToken();
opts.headers ??= {};
if (token) {
opts.headers["Authorization"] = `Bearer ${token}`;
} else if (this.apiKey !== API_KEY_SENTINEL) {
opts.headers["api-key"] = this.apiKey;
} else {
throw new Errors.OpenAIError("Unable to handle auth");
}
return super.prepareOptions(opts);
}