microsoft / teams-ai

SDK focused on building AI based applications and extensions for Microsoft Teams and other Bot Framework channels
MIT License
349 stars 142 forks source link

[Bug]: 401(Unauthorized) when calling Azure OpenAI #1746

Closed swatDong closed 1 week ago

swatDong commented 2 weeks ago

Language

Javascript/Typescript

Version

1.3.0

Description

Calling Azure OpenAI with API Key, the code to create OpenAIModel:

    const model = new OpenAIModel({
        azureEndpoint: "https://my-aoai.openai.azure.com/",
        azureDefaultDeployment: "gpt-35-turbo",
        azureApiKey: "xxx...."
    });

But get 401 response from AOAI:

{"statusCode":401,"message":"Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired."}

Also found that, the request header has "Authorization":"Bearer xxx...". But according to the Azure OpenAI doc, to use API Key, should use api-key header.

Reproduction Steps

  1. Use @microsoft/teams-ai 1.3.0
  2. Create OpenAIModel with azure settings
    const model = new OpenAIModel({
        azureEndpoint: "https://my-aoai.openai.azure.com/",
        azureDefaultDeployment: "gpt-35-turbo",
        azureApiKey: "xxx...."
    });
  3. Run the code / app.
swatDong commented 2 weeks ago

Looked into code and it seems to be caused by here

Created PR for my proposed fix. Feel free to create other fixes if I missed any scenario.

rgudic commented 1 week ago

Having same problems

vvvvvvvesna commented 1 week ago

also have such problem, looking for any solution. hope fix will be soon