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

调用gpt-3.5-turbo模型出现404错误,如何正确使用?

正确使用gpt-3.5-turbo模型的方法

你遇到的404错误是因为gpt-3.5-turbo系列模型不属于Completion接口范畴,它需要使用Chat Completions接口调用,而非你当前用的createCompletion方法。

修正后的代码示例:

const completion = await openai.createChatCompletion({
  model: "gpt-3.5-turbo-0301",
  messages: [
    { role: "user", content: 'my prompt' }
  ]
});
// 注意返回数据结构和Completion接口不同
alert(completion.data.choices[0].message.content);

关键差异说明:

  • 方法名从createCompletion改为createChatCompletion
  • 输入参数不再使用prompt,而是替换为messages数组,每个元素需包含role(可选值:user、assistant、system)和content字段
  • 返回结果结构变化:需从choices[0].message.content获取回复内容,而非choices[0].text

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 05:14:54