OpenAI GPT-3 API error: “Cannot specify both model and engine”

All Engines endpoints are deprecated.

Deprecated

Change the URL from this…

https://api.openai.com/v1/engines/davinci/completions

…to this.

https://api.openai.com/v1/completions

If you run test.py the OpenAI API will return a completion. You’ll get a different completion because the temperature parameter is not set to 0. I got the following completion:

The meaning of life is to find out and fulfil the purpose and meaning…

test.py

import json
import requests
import os

data = {
    "prompt": "What is the meaning of life?",
    "model": "text-davinci-003"
}

response = requests.post("https://api.openai.com/v1/completions", json=data, headers={
    "Content-Type": "application/json",
    "Authorization": f"Bearer {apikey}"
})

response_json = json.loads(response.text)

print(response_json["choices"][0]["text"])

Leave a Comment