0

Im new to OpenAI's API and am following the Quickstart tutorial found here: https://beta.openai.com/docs/quickstart/build-your-application

I just cloned their GitHub repo (git clone https://github.com/openai/openai-quickstart-node.git) and when I tried to run it, I got this error.

POST http://localhost:3000/api/generate 500 (Internal Server Error)

Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

I don't understand what I missed, any help would be greatly appreciated.

source code

sadnapoleon
  • 536
  • 1
  • 4
  • 13

1 Answers1

0

Encountered the same issue.

I simply just forgot to do the step involving adding the API_KEY to the .env file.

Follow the instructions from the documentation, specifically the title labelled "Add your API key" (https://beta.openai.com/docs/quickstart/add-your-api-key).

I have attached a screenshot of the instructions here. It is quite clear.

enter image description here

Hopefully this works for you!

Edit: Also encountered the same problem when doing large requests. If there is a large request to the OpenAI API (i.e returning many tokens), then it will also return this same error.

Shean
  • 58
  • 7