Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
While OpenAI and Azure OpenAI Service rely on a common Python client library, there are small changes you need to make to your code in order to swap back and forth between endpoints. This article walks you through the common changes and differences you'll experience when working across OpenAI and Azure OpenAI.
This article only shows examples with the new OpenAI Python 1.x API library. For information on migrating from 0.28.1
to 1.x
refer to our migration guide.
Prerequisites
Authentication
We recommend using Microsoft Entra ID or Azure Key Vault. You can use environment variables for testing outside of your production environment. If you haven't done this before, our Python quickstarts walks you through this configuration.
API key
OpenAI | Azure OpenAI |
|
|
Microsoft Entra ID authentication
OpenAI | Azure OpenAI |
|
|
Keyword argument for model
OpenAI uses the model
keyword argument to specify what model to use. Azure OpenAI has the concept of unique model deployments. When you use Azure OpenAI, model
should refer to the underlying deployment name you chose when you deployed the model.
Important
When you access the model via the API in Azure OpenAI, you need to refer to the deployment name rather than the underlying model name in API calls, which is one of the key differences between OpenAI and Azure OpenAI. OpenAI only requires the model name. Azure OpenAI always requires deployment name, even when using the model parameter. In our docs, we often have examples where deployment names are represented as identical to model names to help indicate which model works with a particular API endpoint. Ultimately your deployment names can follow whatever naming convention is best for your use case.
OpenAI | Azure OpenAI |
|
|
Azure OpenAI embeddings multiple input support
OpenAI and Azure OpenAI currently support input arrays up to 2,048 input items for text-embedding-ada-002. Both require the max input token limit per API request to remain under 8,191 for this model.
OpenAI | Azure OpenAI |
|
|