Openai api via azure error: NotFoundError: 404 Resource not found

题意:"OpenAI API通过Azure出错:NotFoundError: 404 找不到资源"

问题背景:

thanks to the university account my team and I were able to get openai credits through microsoft azure. The problem is that now, trying to use the openai library for javascript, rightly specifying the key and endpoint that azure gave us, we can't connect and a 404 error comes up:

"多亏了大学账户,我的团队和我能够通过Microsoft Azure获得OpenAI的额度。但问题是,现在我们尝试使用OpenAI的JavaScript库,并正确指定了Azure提供的密钥和端点,却无法连接,出现了404错误:"

复制代码
NotFoundError: 404 Resource not found
    at APIError.generate (file:///home/teo/social_stories_creator/node_modules/openai/error.mjs:48:20)
    at OpenAI.makeStatusError (file:///home/teo/social_stories_creator/node_modules/openai/core.mjs:244:25)
    at OpenAI.makeRequest (file:///home/teo/social_stories_creator/node_modules/openai/core.mjs:283:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (file:///home/teo/social_stories_creator/test.mjs:9:22) {
  status: 404,
  headers: {
    'apim-request-id': 'e04bf750-6d8c-478e-b6d5-967bbbc44b62',
    'content-length': '56',
    'content-type': 'application/json',
    date: 'Sat, 18 Nov 2023 10:14:24 GMT',
    'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
    'x-content-type-options': 'nosniff'
  },
  error: { code: '404', message: 'Resource not found' },
  code: '404',
  param: undefined,
  type: undefined
}

Node.js v21.1.0

The code we are testing, is this: "我们正在测试的代码如下:"

复制代码
import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'OUR_KEY',
  baseURL: 'OUR_ENDPOINT',
});

async function main() {
  const completion = await openai.chat.completions.create({
    messages: [{ role: 'system', content: 'You are a helpful assistant.' }],
    model: 'gpt-3.5-turbo',
  });

  console.log(completion.choices[0]);
}

main();

问题解决:

You need to use the Azure client library like below.

"您需要像下面这样使用Azure客户端库。"

Install the package below. 安装下面的包

复制代码
npm install @azure/openai

And use the following code. 使用下面的代码

cs 复制代码
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");

async function main(){
  // Replace with your Azure OpenAI key
  const key = "YOUR_AZURE_OPENAI_KEY";
  const endpoint = "https://myaccount.openai.azure.com/";
  const client = new OpenAIClient(endpoint, new AzureKeyCredential(key));

  const examplePrompts = [
    "How are you today?",
    "What is Azure OpenAI?",
    "Why do children love dinosaurs?",
    "Generate a proof of Euler's identity",
    "Describe in single words only the good things that come into your mind about your mother.",
  ];

  const deploymentName  =  "gpt35turbo"; //Your deployment name

  let promptIndex = 0;
  const { choices } = await client.getCompletions(deploymentName, examplePrompts);
  for (const choice of choices) {
    const completion = choice.text;
    console.log(`Input: ${examplePrompts[promptIndex++]}`);
    console.log(`Chatbot: ${completion}`);
  }
}

main().catch((err) => {
  console.error("The sample encountered an error:", err);
});

Here, you need to provide the correct deployment name you deployed in Azure OpenAI.

"在这里,您需要提供在Azure OpenAI中部署的正确部署名称。"

相关推荐
哥布林学者5 小时前
吴恩达深度学习课程五:自然语言处理 第一周:循环神经网络 (三)语言模型
深度学习·ai
Leinwin7 小时前
Azure语音服务(国际版)系列升级,解锁语音交互新体验
microsoft·azure
营销操盘手阿泽7 小时前
从流量红利到构建长期AI数据资产的深度共建指南
ai
熊猫钓鱼>_>11 小时前
AI 加 CloudBase 帮我从零快速打造儿童英语故事学习乐园
ide·人工智能·ai·mcp·codebuddy·cloudbase·ai toolkit
向量引擎11 小时前
[架构师级] 压榨GPT-5.2与Sora 2的极限性能:从单体调用到高并发多模态Agent集群的演进之路(附全套Python源码与性能调优方案)
开发语言·人工智能·python·gpt·ai·ai写作·api调用
CoderJia程序员甲11 小时前
GitHub 热榜项目 - 日榜(2026-1-6)
ai·开源·大模型·github·ai教程
安得权12 小时前
Azure Dataverse 权限设计学习
学习·flask·azure
MicrosoftReactor13 小时前
技术速递|利用 SLM 创建多智能体的 Podcast 解决方案
microsoft·ai·agent·slm
红桃Jk14 小时前
关于开发文档向 Markdown(Docs-as-Code)转型的可行性研究报告
ai·mermaid
云雾J视界14 小时前
AI+IoT双轮驱动:构建风电设备预测性维护数字孪生体的全栈技术实践
人工智能·物联网·ai·lstm·iot·scada·金风科技