The first part that must be changed is the “prompt”. The new way to send language to the AI with chat completions endpoint is “messages”
prompt: write a whole complete essay at least 120 word about ${topic}
→
messages: [{"role": "user", "content": "write a whole complete essay in about 80 word about ${topic}"}],
Then the new endpoint must be used elsewhere in the code:
https://api.openai.com/v1/chat/completions
You can read documents about the changes, and best practices for sending multiple messages or a system programming message.