Error 404 - This is a chat model and not supported in the v1/completions endpoint

I am working on a project that requires me to compare responses from different version of GPT. My code is working properly for model ‘gpt-3.5-turbo-instruct’, but same code is giving me error when I am trying to use advance model like ‘gpt-4-turbo’, ‘gpt-4’ or ‘gpt-4o’.
I am using below code for my work:

client = OpenAI()

  • client.api_key = ‘xxxxxxxxx’*

  • response = client.completions.create(*

  •    model=in_model,*
    
  •    prompt=in_prompt,*
    
  •    max_tokens=1500*
    
  • )*

  • code = response.choices[0].text.strip()*

Guidance in this case is appreciated.

Hi!
When you go the playground there is a little code icon </> where you can copy and paste the code needed.
For example for 4o

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-4o",
  messages=[],
  response_format={
    "type": "text"
  },
  temperature=1,
  max_completion_tokens=2048,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
)

If you run into further issues at this stage, you need to check out the quickstart guide.

https://platform.openai.com/docs/quickstart