Azure OpenAI Service
Azure OpenAI Service provides REST API access to OpenAI's powerful models (GPT-4o, GPT-4, GPT-3.5 Turbo, DALL-E, Whisper) with the enterprise security, compliance, and regional availability of Azure.
Why Azure OpenAI vs OpenAI Direct?
| Feature | Azure OpenAI | OpenAI API |
|---|---|---|
| Data privacy | Your data stays in your Azure tenant | Sent to OpenAI servers |
| Compliance | SOC 2, HIPAA, ISO 27001, FedRAMP | Limited certifications |
| Networking | Private endpoints, VNet integration | Public API only |
| Content safety | Configurable content filters | Fixed safety layer |
| SLA | 99.9% uptime SLA | Best-effort |
| Scale | Provisioned throughput (PTU) | Shared capacity |
Prerequisites
- Azure subscription
- Azure OpenAI access (apply at aka.ms/oai/access)
Step 1: Create an Azure OpenAI Resource
# Using Azure CLI
az cognitiveservices account create \
--name "my-openai-resource" \
--resource-group "my-rg" \
--kind "OpenAI" \
--sku "S0" \
--location "eastus2"
Or via the Azure Portal:
- Search for "Azure OpenAI" in the marketplace
- Click Create
- Choose subscription, resource group, region, and name
- Click Review + Create
Step 2: Deploy a Model
# Deploy GPT-4o
az cognitiveservices account deployment create \
--name "my-openai-resource" \
--resource-group "my-rg" \
--deployment-name "gpt-4o" \
--model-name "gpt-4o" \
--model-version "2024-08-06" \
--model-format "OpenAI" \
--sku-capacity 30 \
--sku-name "Standard"
Step 3: Use the Playground
- Go to Azure AI Foundry or the Azure OpenAI portal
- Select your deployment
- Open the Chat Playground
- Configure:
- System message: Set the AI's persona and rules
- Temperature: 0 (deterministic) to 1 (creative)
- Max tokens: Limit response length
- Top P: Nucleus sampling parameter
Example System Message
You are a helpful Azure solutions architect assistant.
You help users design cloud architectures using Azure services.
Always provide cost-effective, scalable, and secure recommendations.
Use markdown formatting and include relevant Azure service names.
Step 4: API Integration
Python SDK
from openai import AzureOpenAI
client = AzureOpenAI(
api_key="your-api-key",
api_version="2024-08-01-preview",
azure_endpoint="https://my-openai-resource.openai.azure.com/"
)
response = client.chat.completions.create(
model="gpt-4o", # deployment name
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain Azure Functions in 3 sentences."}
],
temperature=0.7,
max_tokens=500
)
print(response.choices[0].message.content)
C# / .NET SDK
using Azure.AI.OpenAI;
using Azure;
var client = new AzureOpenAIClient(
new Uri("https://my-openai-resource.openai.azure.com/"),
new AzureKeyCredential("your-api-key"));
var chatClient = client.GetChatClient("gpt-4o");
var response = await chatClient.CompleteChatAsync(new[]
{
new SystemChatMessage("You are a helpful assistant."),
new UserChatMessage("Explain Azure Functions in 3 sentences.")
});
Console.WriteLine(response.Value.Content[0].Text);
Step 5: Content Filtering
Azure OpenAI includes configurable content filters:
- Go to Content filters in the Azure OpenAI portal
- Create a custom filter configuration
- Set severity thresholds for: Hate, Sexual, Violence, Self-harm
- Configure Prompt Shield to block jailbreak attempts
- Assign the filter to your deployment
Resources
Video: Watch the Azure OpenAI Getting Started on Microsoft Azure YouTube channel.

