Frequent error when Requesting gpt-4o with python openai==0.28.1

Hello
I am using openai v1(0.28.1) because my application has dependency on pydantic v1… so I cannot migrate to openai v2…
with the code underneath
sometimes it works and sometimes it doesn’t
it responds with this error - Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.chat_completion.ChatCompletion'>

I thought it was because of my openai key? because testing with other openai keys it seems to work
what should I check? and what may be the problem?

import openai

openai.api_key="sk-********"
body = {
    "model": "gpt-4o-2024-05-13",
    "messages": [
        {
            "role": "system",
            "content": 'Here is who you are:\nYou are a chatbot who only answer questions about a company policy and work guideline in json format.\n',
        },
        {
            "role": "user",
            "content": '"user query:"""What can\'t be infringed even if you limit your basic rights?""""',
        },
    ],
    "temperature": 0,
    "max_tokens": 1000,
    "top_p": 1,
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "response_format": {"type": "json_object"},
}
response = openai.ChatCompletion.create(**body)

Your code works fine for me, it must be something else on your system.

This is a symptom that was a fault that went on for many days a month ago with OpenAI. It would be annoying if they simply introduced the problem again.

The prior python SDK didn’t validate or block inputs as much, so this is likely from the endpoint.

If you are getting a “deployment ID” error, that sounds like something Microsoft Azure-related, or that OpenAI has similar services for non-public customer products.

Engine is actually an old parameter name for “model” that still was being accepted when sent directly.

You can re-implement your API calling with a library like requests or httpx, and not have to worry about compatibility as much, siimply receiving and parsing the JSON response.

2 Likes