This repository contains code samples of different methods to authenticate to the Azure OpenAI Service using the Python openai library, Python langchain-openai library, and Python requests library.
The samples assume the use of the python-dotenv library for storing sensitive variables.
The following authentication examples are provided:
- Service Principal with LangChain
- API Key with LangChain
- Service Principal with OpenAI SDK
- Managed Identity with OpenAI SDK
- API Key with OpenAI SDK
- Service Principal with REST API
- API Key with REST API
In each example you will find a requirements.txt file with the required libraries and a sample environmental variables file that can be used with the python-dotenv library. You will need to rename it from .env-sample to .env.