Hi @Dat Hoang
Thank you for using the Microsoft Q&A forum.
While there is no direct way to rotate Azure OpenAI API keys programmatically, you can use the OpenAI Python SDK to regenerate the keys in the case of compromise or to comply with the organization's key rotation process.
Here's a simple code using the OpenAI Python SDK. In the code provide a prompt to the model and ask it to complete it for me and use one of the API keys to authenticate to it.
Here's another link to a blog post that provides a code snippet using the OpenAI Python SDK to authenticate to the service using one of the API keys and regenerate the other key: https://journeyofthegeek.com/2023/04/02/authentication-in-azure-openai-service/
Alternatively, you can utilize AAD-based tokens as well, as Azure OpenAI is based on the Azure Cognitive-aligned platform. If you generate a Bearer token in Azure AD and pass it over to the same Azure OpenAI endpoint, but using a slightly different header's key "Authorization," you would be able to retrieve the same data.
Hope this helps.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful.