How can I select the proper openai.api_version? – Python

by
Ali Hasan
azure-active-directory azure-openai llama-cpp-python python-3.x

The Problem:

How can I select the proper openai.api_version when using the Azure OpenAI service? Does it depend on my Azure OpenAI instance, deployed models, features used in my Python code, or something else?

The Solutions:

Solution 1: Refer to the Official Documentation

The appropriate openai.api_version to use depends on the specific API method being called. Not all methods are supported in all API versions.

To determine the correct version, refer to the official Azure OpenAI documentation at https://learn.microsoft.com/en-US/azure/cognitive-services/openai/reference. This documentation provides detailed information on the supported API versions for each method.

For example, if you wish to use the “completions” endpoint, you can refer to the documentation to find that it is available in the following versions (ordered by date):

  • 2023-08-01-preview
  • 2023-07-01-preview
  • 2023-06-01-preview
  • 2023-05-15
  • 2023-03-15-preview
  • 2022-12-01

On the other hand, if you wish to use the “chat completions” endpoint, the documentation will indicate that it is only available in the following versions (ordered by date):

  • 2023-08-01-preview
  • 2023-07-01-preview
  • 2023-06-01-preview
  • 2023-05-15
  • 2023-03-15-preview

It is important to note that the “chat completions” endpoint was not offered in the initial API version.

As a general rule, it is recommended to use the latest “not preview” version for production when possible.

Solution 2: Removed in `openai==1.0.0`

openai.api_version has been removed from openai==1.0.0. For more information, refer to the migration guide: https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/migration?tabs=python-new%2Cdalle-fix#removed

However, it is still available in openai==0.28.

Q&A

How can I select the proper openai.api_version?

The API Version property depends on the method you are calling in the API.

Is openai.api_version removed from openai==1.0.0?

Yes, openai.api_version is removed from openai==1.0.0.