Skip to content

AzureChatOpenAI imported from @langchain/openai results in MODEL_NOT_FOUND error #8082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 tasks done
ruslany opened this issue Apr 27, 2025 · 0 comments
Open
5 tasks done
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@ruslany
Copy link

ruslany commented Apr 27, 2025

Checked other resources

  • 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

The following code results in MODULE_NOT_FOUND error:

// Import required dependencies
//const { AzureChatOpenAI } = require("@langchain/azure-openai");
const { AzureChatOpenAI } = require("@langchain/openai");
const { HumanMessage } = require("@langchain/core/messages");
require("dotenv").config();

async function main() {
  // Initialize the ChatOpenAI model with Azure configuration
  const model = new AzureChatOpenAI({
    azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
    azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,
    azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_DEPLOYMENT_NAME,
    azureOpenAIEndpoint: process.env.AZURE_OPENAI_ENDPOINT,
    temperature: 0,
    verbose: true,
  });

  // Create a simple message
  const message = new HumanMessage("Tell me a short joke");

  // Call the Azure OpenAI API
  const response = await model.invoke([message]);

  // Print the response
  console.log("Response: ", response.content);
}

Error Message and Stack Trace (if applicable)

[llm/error] [1:llm:AzureChatOpenAI] [346ms] LLM run errored with error: "404 Resource not found\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/MODEL_NOT_FOUND/\n\n\nError: 404 Resource not found\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/MODEL_NOT_FOUND/\n\n    at APIError.generate (/home/ruslany/learn/langchain/node_modules/.pnpm/openai@4.96.0_zod@3.24.3/node_modules/openai/error.js:54:20)\n    at AzureOpenAI.makeStatusError (/home/ruslany/learn/langchain/node_modules/.pnpm/openai@4.96.0_zod@3.24.3/node_modules/openai/core.js:302:33)\n    at AzureOpenAI.makeRequest (/home/ruslany/learn/langchain/node_modules/.pnpm/openai@4.96.0_zod@3.24.3/node_modules/openai/core.js:346:30)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async /home/ruslany/learn/langchain/node_modules/.pnpm/@langchain+openai@0.5.7_@langchain+core@0.3.49_openai@4.96.0_zod@3.24.3__/node_modules/@langchain/openai/dist/chat_models.cjs:2175:29\n    at async RetryOperation._fn (/home/ruslany/learn/langchain/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js:50:12)"
NotFoundError: 404 Resource not found

Troubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/MODEL_NOT_FOUND/

    at APIError.generate (/home/ruslany/learn/langchain/node_modules/.pnpm/openai@4.96.0_zod@3.24.3/node_modules/openai/error.js:54:20)
    at AzureOpenAI.makeStatusError (/home/ruslany/learn/langchain/node_modules/.pnpm/openai@4.96.0_zod@3.24.3/node_modules/openai/core.js:302:33)
    at AzureOpenAI.makeRequest (/home/ruslany/learn/langchain/node_modules/.pnpm/openai@4.96.0_zod@3.24.3/node_modules/openai/core.js:346:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/ruslany/learn/langchain/node_modules/.pnpm/@langchain+openai@0.5.7_@langchain+core@0.3.49_openai@4.96.0_zod@3.24.3__/node_modules/@langchain/openai/dist/chat_models.cjs:2175:29
    at async RetryOperation._fn (/home/ruslany/learn/langchain/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js:50:12) {
  status: 404,
  headers: {
    'apim-request-id': '1d4196d2-db68-457f-a8a9-bad96df121c3',
    'content-length': '56',
    'content-type': 'application/json',
    date: 'Sun, 27 Apr 2025 22:08:38 GMT',
    'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
    'x-content-type-options': 'nosniff'
  },
  request_id: undefined,
  error: { code: '404', message: 'Resource not found' },
  code: '404',
  param: undefined,
  type: undefined,
  lc_error_code: 'MODEL_NOT_FOUND',
  attemptNumber: 1,
  retriesLeft: 6
}

Description

It constructs the Azure Open AI url incorrectly:

OpenAI:DEBUG:response (error; (error; not retryable)) 404 https://myazureresource.openai.azure.com/gpt-4o/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview 

The URL should be

https://myazureresource.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview 

If I import the same class from @langchain/azure-openai, then it works with exact same parameters but VS code shows that the class is deprecated.

System Info

pnpm version
{
  langchain: '1.0.0',
  npm: '10.9.2',
  node: '22.14.0',
  acorn: '8.14.0',
  ada: '2.9.2',
  amaro: '0.3.0',
  ares: '1.34.4',
  brotli: '1.1.0',
  cjs_module_lexer: '1.4.1',
  cldr: '46.0',
  icu: '76.1',
  llhttp: '9.2.1',
  modules: '127',
  napi: '10',
  nbytes: '0.1.1',
  ncrypto: '0.0.1',
  nghttp2: '1.64.0',
  nghttp3: '1.6.0',
  ngtcp2: '1.10.0',
  openssl: '3.0.15+quic',
  simdjson: '3.10.1',
  simdutf: '6.0.3',
  sqlite: '3.47.2',
  tz: '2024b',
  undici: '6.21.1',
  unicode: '16.0',
  uv: '1.49.2',
  uvwasi: '0.0.21',
  v8: '12.4.254.21-node.22',
  zlib: '1.3.0.1-motley-82a5fec'
}
@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant