Skip to content

Upgrade to @langchain/openai 0.6.2 breaks AzureChatOpenAI (missing OPENAI_API_VERSION) #8547

@Legiew

Description

@Legiew

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

No need to put in valid values, the error happens before invoking the final call.

await new AzureChatOpenAI({
  model: 'modelName',
  azureOpenAIBasePath: 'azureOpenAIBasePath',
  azureOpenAIApiDeploymentName: 'azureOpenAIApiDeploymentName',
  azureOpenAIApiVersion: 'azureOpenAIApiVersion',
  azureADTokenProvider: () => {
    return Promise.resolve('token');
  },
}).invoke([]);

Error Message and Stack Trace (if applicable)

Error: The OPENAI_API_VERSION environment variable is missing or empty; either provide it, or instantiate the AzureOpenAI client with an apiVersion option, like new AzureOpenAI({ apiVersion: 'My API Version' }).
at new AzureOpenAI (foo/node_modules/openai/src/azure.ts:72:13)
at ChatOpenAICompletions._getClientOptions (file://foo/node_modules/@langchain/openai/dist/azure/chat_models.js:567:27)
at ChatOpenAICompletions.completionWithRetry (file://foo/node_modules/@langchain/openai/dist/chat_models.js:1910:36)
at ChatOpenAICompletions._generate (file://foo/node_modules/@langchain/openai/dist/chat_models.js:1737:37)
at AzureChatOpenAI._generate (file://foo/node_modules/@langchain/openai/dist/chat_models.js:2664:33)
at file://foo/node_modules/@langchain/core/dist/language_models/chat_models.js:250:96
at Array.map ()
at AzureChatOpenAI._generateUncached (file://foo/node_modules/@langchain/core/dist/language_models/chat_models.js:250:67)
at async AzureChatOpenAI.invoke (file://foo/node_modules/@langchain/core/dist/language_models/chat_models.js:88:24)

Description

Follow up of #8519. After updating to "@langchain/openai": "0.6.2" the error changed from missing api key to missing api version.

System Info

"@langchain/core": "0.3.66",
"@langchain/textsplitters": "0.1.0",
"langchain": "0.3.30",

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions