OpenAI API error

I am trying to complete the challenge in Intro to AI Engineering, Lesson 9 (An API Call, the messages array). I get the error:
‘Error: 404 The model gpt-4 does not exist or you do not have access to it. Learn more: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4.

Here is my code:

import OpenAI from ‘openai’

const apiKey = process.env.OPENAI_API_KEY

const openai = new OpenAI({
apiKey: apiKey,
dangerouslyAllowBrowser: true
})

/**

  • Challenge:
  • I’ve pasted some output below. Try and figure out
  • what instructions I gave OpenAI to get that output.
  • On the screen, visions gleam, a tech queen’s dream,
  • in every home’s scene.
  • Pixels dance, in a trance, shows advance, in a
  • high-def glance.
  • Remote in hand, worlds expand, from sitcom land to
  • news that’s grand.
  • Binging shows, the excitement grows, the plot thickens
  • and the time just flows.
  • From dawn till night, in colors bright, TVs light up
  • our life just right.
  • **/

const messages = [
{
role: ‘system’,
content: ‘You are a rapper. When prompted, write a five-line rap about the topic.’
},
{
role: ‘user’,
content: ‘television’
}
]

const response = await openai.chat.completions.create({
model: ‘gpt-4’,
messages: messages
})

console.log(response.choices[0].message.content)

Hey @clccode, does your OpenAI account have access to this model? Here is an article to see if your account matches their requirements: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4

Thanks, Roku. It looks like I may not have access to it as I haven’t paid anything.

Can we use the free ChatGPT 3.5?

Chris

No worries! You should be able to use other available models. You can check their documentation out here https://platform.openai.com/docs/models/gpt-3-5 for their 3.5 models. I think you don’t need to change anything else in your code besides the model name in model: <model_name>. Though I’m not 100% sure if you need to change anything else. Have a test and see how you go!

Thank you. I went ahead and paid a little bit of money and I got my request to work. FWIW, I tried changing the model to gpt-3.5 and still got the same error message I listed above.

Thanks again for your help!

Oh that’s strange. There’s been a lot of movement with OpenAI’s API so there might be some other parameters that needs to be changed. Maybe you can get gpt-4 to help figure out how to use gpt-3.5 later if you want :smile: Hopefully it tells you how to do that…

Hey @clccode did you use exactly gpt-3.5 in your code ? gpt-3.5 is actually a group of models. The precise model to use would be gpt-3.5-turbo (or one of the others from the group, but gpt-3.5-turbo is the general one which will point to their newest, stable 3.5 model)

Thank you, Tom. I started trying gpt-3.5, but then also tried gpt-3.5-turbo, also with no luck. I’m wondering if I was importing the wrong version. I think the dependency I was using was 4.14.2. Is there another version that I should import instead?

This is all curiosity now as I got gpt-4 to work after paying a few $$. That said, I am still interested in using gpt-3.5-turbo. Any tips on that are welcome and, I may also follow Roku’s advice and ask gpt-4😀

Thanks again,

Chris