Azure OpenAI Service
Enterprise-grade access to OpenAI models (GPT-4o, GPT-4, o1, DALL-E, Whisper) with Azure security, compliance, and regional data residency.
Why Azure OpenAI?
Enterprise Security
Private endpoints, VNet integration, Azure AD authentication
Data Residency
Choose deployment region. Data stays in your geography.
Compliance
SOC 2, HIPAA, GDPR, ISO 27001 certifications
Same API
OpenAI-compatible API. Minimal code changes required.
Available Models (2024-2025)
| Model | Context | Best For |
|---|---|---|
| GPT-4o | 128K | Multimodal (text + vision), fastest GPT-4 |
| GPT-4o-mini | 128K | Cost-effective, high volume |
| o1 | 200K | Advanced reasoning, math, coding |
| o1-mini | 128K | Fast reasoning, code |
| GPT-4 Turbo | 128K | Complex tasks, JSON mode |
| GPT-3.5 Turbo | 16K | Simple tasks, low cost |
| DALL-E 3 | - | Image generation |
| Whisper | - | Speech-to-text |
| text-embedding-3-large | - | Embeddings (3072 dim) |
Setup Steps
Create Azure OpenAI Resource
Azure Portal → Create Resource → "Azure OpenAI" → Select region
Deploy a Model
Azure AI Studio → Deployments → Deploy Model → Choose GPT-4o → Set deployment name
Get Credentials
Keys and Endpoint → Copy API Key and Endpoint URL
Python SDK
pip install openai
Chat Completion
from openai import AzureOpenAI
client = AzureOpenAI(
api_key="YOUR_API_KEY",
api_version="2024-10-21",
azure_endpoint="https://YOUR_RESOURCE.openai.azure.com"
)
response = client.chat.completions.create(
model="gpt-4o", # Your deployment name
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
temperature=0.7,
max_tokens=1000
)
print(response.choices[0].message.content)
Streaming Response
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Vision (GPT-4o with Images)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image_url", "image_url": {
"url": "https://example.com/image.jpg"
}}
]
}]
)
Embeddings
response = client.embeddings.create(
model="text-embedding-3-large", # Your embedding deployment
input="The quick brown fox jumps over the lazy dog"
)
embedding = response.data[0].embedding # 3072-dim vector
LangChain Integration
from langchain_openai import AzureChatOpenAI, AzureOpenAIEmbeddings
# Chat model
llm = AzureChatOpenAI(
azure_deployment="gpt-4o",
api_version="2024-10-21",
temperature=0.7
)
# Embeddings
embeddings = AzureOpenAIEmbeddings(
azure_deployment="text-embedding-3-large",
api_version="2024-10-21"
)
# Usage
response = llm.invoke("Explain RAG in simple terms")
print(response.content)
Pricing Overview
| Model | Input (1M tokens) | Output (1M tokens) |
|---|---|---|
| GPT-4o | $2.50 | $10.00 |
| GPT-4o-mini | $0.15 | $0.60 |
| o1 | $15.00 | $60.00 |
| GPT-3.5 Turbo | $0.50 | $1.50 |
*Prices approximate. Check Azure pricing page for current rates.
Azure OpenAI vs OpenAI Direct
| Aspect | Azure OpenAI | OpenAI Direct |
|---|---|---|
| Data Residency | You choose region | US only |
| VNet Support | Yes | No |
| Enterprise SSO | Azure AD | Limited |
| Model Availability | Delayed by weeks | Immediate |
| Billing | Azure subscription | Credit card |
| SLA | Enterprise SLA | Best effort |