본문 바로가기
Resources/Errors

[OpenAI API] Request failed with status code 404

by 쭈대디 2024. 3. 18.
Error Log
2024-03-18T09:56:20.404Z	b465f80f-7456-4a52-88c1-d86c4e29ce7e	ERROR	Invoke Error 	
{
    "message": "Request failed with status code 404",
    "name": "Error",
    "stack": "Error: Request failed with status code 404\n    at createError (/var/task/index.js:356:19)\n    at settle (/var/task/index.js:372:16)\n    at IncomingMessage.handleStreamEnd (/var/task/index.js:2222:15)\n    at IncomingMessage.emit (node:events:529:35)\n    at endReadableNT (node:internal/streams/readable:1400:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)",
    ...
    중략
    ...
        "url": "https://api.openai.com/v1/completions"
    },
    "status": 404
}

 

실행 환경
  • openai API 구현 language : typescript
  • opanai Version : 3.1.0
  • nodejs Version : 18.18.2
  • npm version : 9.8.1

 

Solution 

 

Note: OpenAI NodeJS SDK v4 was released on August 16, 2023, and is a complete rewrite of the SDK. The code below differs depending on the version you currently have. See the v3 to v4 migration guide.

 

참조한 Git 소스 마지막 Commit이 작년 6월경인 것을 미뤄짐작컨대 그 시점 이후 API 변경으로 인한 404 오류로 보입니다. 우선 migration이 불가피한 것으로 판단되어, 아래와 같이 업그레이드 및 코드 수정을 시도합니다.

 

  OpenAI v3.2.1 OpenAI v4.29.1
Dependency (package.json) "openai" : "^3.1.0" "openai" : "^4.0.0"
Initialization import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
  apiKey: OPEN-API-KEY,
});
const openai = new OpenAIApi(configuration);
import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: OPEN-API-KEY
});
SDK Request [createCompletion]    const result = await openai.createCompletion({
    model: 'text-davinci-003',
    prompt: prompt,
    max_tokens: 1000,
    temperature: 0.7,
  });
  const result = await openai.completions.create({
    model: 'gpt-3.5-turbo',
    prompt: prompt,
    max_tokens: 1000,
    temperature: 0.7,
  });
SDK Response [createCompletion]     const response = result.data.choices[0].text;   const response = result.choices[0].text;
DALL-E [TBD] TBD TBD

https://github.com/openai/openai-node/discussions/217

 

v3 to v4 Migration Guide · openai openai-node · Discussion #217

v4 is a complete rewrite of the SDK. To see what's new, see the release notes. Installation First, update your package.json to specify v4: "openai": "^4.0.0" and run npm install or equivalent to do...

github.com

 

해결!