How to do asynchronous calls with the latest api version?

Hi All,

How do we now handle asynchronous calls to the API now that acreate has been removed?

previously I could do this.

response = await openai.ChatCompletion.acreate

After the update, to call the chat completion API you’d use

response = client.chat.completions.create

I tried searching for acreate or asynchronous on the docs sites and there are no results, even for legacy.

Has asynchronous calls been removed?

Thanks,

Maybe below code is the replacement i have not tried yet though but found on github

from openai import AsyncOpenAI
client = AsyncOpenAI()

response = await client.chat.completions.create(
            model="gpt-4",
            messages=messages,
            tools=functions,
            temperature=0.0,
            tool_choice=None
        )
4 Likes

Thanks @altaf

This worked. For those that come across this thread, you will also need to update how you handle the responses, as objects are now returned.

Something like this:

From:

response.choices[0].message["content"]

To:

response.choices[0].message.content

4 Likes