In this comprehensive article, I’ll guide you through multiple methods for obtaining your Azure OpenAI key, sharing insights from real-world implementations. This guide will provide you with the complete roadmap to access Azure OpenAI Key.
How to Get Azure OpenAI Key
Before diving into the key acquisition process, let me explain the types of Azure OpenAI Keys.
Types of Azure OpenAI Keys
| Key Type | Use Case | Security Level | Best For |
|---|---|---|---|
| API Key | Direct API access | Medium | Development, testing |
| Azure AD Token | Enterprise authentication | High | Production environments |
| Managed Identity | Azure-native services | Highest | Azure-hosted applications |
| Service Principal | Automated workflows | High | CI/CD pipelines |
Method 1: Using Azure Portal
This is the most straightforward method I use when onboarding new clients to Azure OpenAI services.
Step 1: Create an Azure OpenAI Resource
Step 2: Retrieve Your API Keys
After resource creation, here’s how I extract the API keys:
Key Retrieval Steps:
- Navigate to your newly created Azure OpenAI resource
- In the left sidebar, click “Keys and Endpoint”
- You’ll see two keys displayed:
- Key 1: Primary API key
- Key 2: Secondary API key (for key rotation)
- Copy either key for your applications using the copy buttons next to the respective keys. Refer to the screenshot below for the complete steps.

Security Best Practice I Always Implement:
{
"recommendation": "Use Key 1 for production, Key 2 for development",
"rotation_strategy": "Rotate keys quarterly for security",
"storage": "Store keys in Azure Key Vault, never in code"
}
Method 2: Using Azure CLI
We can execute the Azure CLI script below to retrieve the primary key.
# Get the primary key
az cognitiveservices account keys list \
--name $OPENAI_NAME \
--resource-group $RESOURCE_GROUP \
--query "key1" \
--output tsvaz cognitiveservices account keys list --name 'azurelessons' --resource-group 'myresgrp' --query "key1" --output tsvAfter executing the above query, I got the expected output as shown in the screenshot below.

If we need to get both keys in JSON format, we can execute the following Azure CLI command.
# Get both keys in JSON format
az cognitiveservices account keys list \
--name $OPENAI_NAME \
--resource-group $RESOURCE_GROUPaz cognitiveservices account keys list --name 'azurelessons' --resource-group 'myresgrp' --output tsvAfter executing the above query, I got the expected output as shown in the screenshot below.

Method 3: Using PowerShell
We can also use the PowerShell script for this purpose.