You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js调用OpenAI API出现“That model does not exist”错误求助

错误原因及解决方案

核心问题分析

你的代码存在两个关键错误,直接导致了「That model does not exist」的提示:

  1. 模型名称错误:OpenAI不存在名为chat-gpt的模型,GPT-3系列的文本生成模型需使用官方规范名称,比如gpt-3.5-turbo-instruct(文本补全场景)或gpt-3.5-turbo(聊天交互场景)。
  2. API接口路径错误:你使用的/v1/engines/chat-gpt/jobs是批量任务专用接口,且路径格式已过时,普通文本生成应使用对应功能的标准接口。

修复方案

根据你的业务场景,选择以下两种修复方式:

方式一:文本补全场景(基于单prompt生成)

修改接口URL和模型名称,调整后的代码如下:

const chatGptUrl = "https://api.openai.com/v1/completions";

// ...

const response = await axios.post(
  chatGptUrl,
  {
    model: "gpt-3.5-turbo-instruct", // 正确的GPT-3补全模型
    prompt,
    max_tokens: 100,
    n: 1,
    stop: ""
  },
  {
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${chatGptApiKey}`
    }
  }
);

const responseText = response.data.choices[0].text;

方式二:聊天交互场景(多轮对话)

如果需要实现聊天功能,需切换到聊天专用接口,同时调整参数结构:

const chatGptUrl = "https://api.openai.com/v1/chat/completions";

// ...

const response = await axios.post(
  chatGptUrl,
  {
    model: "gpt-3.5-turbo", // 官方推荐的聊天模型
    messages: [
      { role: "user", content: prompt } // 用messages数组替代单个prompt
    ],
    max_tokens: 100,
    n: 1
  },
  {
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${chatGptApiKey}`
    }
  }
);

// 聊天接口返回结构不同,需调整取值逻辑
const responseText = response.data.choices[0].message.content;

额外注意事项

  • 确认你的API密钥拥有对应模型的调用权限,权限不足也可能触发类似报错。
  • 优先使用官方推荐的最新模型,旧模型(如text-davinci-003)已逐步停止维护。

内容的提问来源于stack exchange,提问作者chovy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 09:56:03