Azure AI Services offer several pricing tiers and models to suit different usage patterns. Understanding pricing is essential for the AI-102 exam because cost management is tested as part of the "Plan and manage Azure AI solutions" domain. Each AI resource type has its own pricing structure, but common patterns exist across services.
| Tier | Typical Use | Limitations | Best For |
|---|---|---|---|
| Free (F0) | Evaluation, prototyping | Limited transactions per month (typically 5K-20K), low TPS (transactions per second), single region | Learning, small-scale proofs of concept, development environments |
| Standard (S0) | Production workloads | Pay-as-you-go per transaction, no monthly caps, higher TPS limits (varies by service) | Production applications with variable usage patterns |
| Commitment Tier | High-volume, predictable workloads | Pre-purchased tier (e.g., 100K, 500K, 1M transactions per month), discounted rate over S0 | Production with steady or growing usage — 40-60% savings over pay-as-you-go |
Pricing for Azure AI Services is typically per-transaction (per API call), with some services having additional costs for specific features. Azure AI Vision S1 charges per image for analysis and per page for OCR (Read). Azure AI Language S0 charges per text record (up to 5,120 characters per record). Azure OpenAI charges per 1,000 tokens (separate rates for input and output tokens). Speech services charge per audio hour for transcription and per character for synthesis. Document Intelligence charges per page for analysis. The Free tier is an important exam topic — remember that F0 can only be created once per subscription per service and is limited to evaluation only. You cannot run production workloads on F0.
Azure Budgets allow you to set spending limits and receive alerts when your consumption approaches or exceeds those limits. Budgets can be set at the subscription, resource group, or resource level. Each budget defines a monetary amount, a time period (monthly, quarterly, or annual), and alert thresholds (typically 50%, 90%, and 100% of the budget). When a threshold is crossed, Azure sends email notifications to the configured recipients. Budgets can also trigger automation runbooks to take corrective action — for example, scaling down a service or disabling a resource. Budgets are advisory only — they do not stop services from running. To enforce cost limits, you need additional automation (Azure Functions or Logic Apps) that monitors the budget and takes action.
To set a budget in the Azure portal, navigate to Cost Management + Billing, select Budgets, and create a new budget. Specify the scope (subscription or resource group), name, amount, and time period. Configure alert conditions at your chosen thresholds. For AI solutions, it is best practice to set budgets at the resource group level — one budget per project or environment. This gives you granular visibility into which AI services are driving costs. In an exam scenario, you might be asked where to configure budget alerts — the answer is Cost Management + Billing in the Azure portal.
Azure Monitor collects metric data from Azure AI Services automatically. These metrics are available in the Azure portal under each resource's Metrics tab or through the Azure Monitor Metrics Explorer. Key metrics tracked for AI services include TotalCalls (total number of API calls), SuccessfulCalls (calls returning HTTP 2xx), ServerErrors (HTTP 5xx), ClientErrors (HTTP 4xx), DataIn (inbound data size in bytes), DataOut (outbound data size in bytes), Latency (response time at P50, P95, and P99 percentiles), and BlockedCalls (calls blocked by content filtering or rate limiting). These metrics are retained for 93 days by default and can be viewed as line charts, bar charts, or tables.
For Azure OpenAI specifically, additional metrics include GeneratedTokens, ProcessedPromptTokens, and FineTunedModelInvocations. For Azure AI Search, metrics include Documents indexed per second, Search latency, and Query execution (throttled queries). For Speech services, metrics include Audio duration processed and Successful recognitions. Understanding which metrics are available per service helps you answer scenario questions on the exam — for example, "Which metric shows how many tokens were generated by an Azure OpenAI model?" Answer: GeneratedTokens.
Diagnostic logs provide detailed operational data about your AI service. Unlike metrics (which are numerical time-series data), logs contain event-level details such as authentication events, individual API requests, and internal operations. Diagnostic logs must be explicitly enabled and configured to route to one or more destinations — a Log Analytics Workspace for analysis and querying, a Storage Account for long-term archival and auditing, or an Event Hub for streaming to third-party SIEM systems.
| Category | Description | Typical Use |
|---|---|---|
| Audit | Authentication events — successful and failed token validation, API key usage, managed identity attempts | Security auditing, unauthorized access detection, compliance reporting |
| Request | API request details — endpoint called, HTTP method, status code, response size, client IP, user agent | Usage analysis, error investigation, throttling detection, client troubleshooting |
| Trace | Internal operation details — model execution steps, pipeline stages, content filter decisions, latency breakdown | Deep diagnostics for unexpected model behavior, filter false positives, latency root cause analysis |
Diagnostic logs are not enabled by default — you must configure them in the Diagnostic settings tab of each AI resource. You can send logs to multiple destinations simultaneously. The cost of diagnostic logging includes data ingestion costs for Log Analytics, storage costs for archival, and Event Hub throughput costs. For exam scenarios, remember that Audit logs are essential for security compliance, Request logs help troubleshoot specific client errors, and Trace logs are needed for deep model behavior analysis but generate significant volume.
Application Insights provides application performance monitoring (APM) for bot applications and custom SDK clients. For bots, the TelemetryLoggerMiddleware automatically tracks activities, dialog events, and custom dimensions. For custom applications using the Azure AI SDKs, you can emit custom telemetry by integrating the Application Insights SDK directly — track events for each API call, including the input size, response latency, model used, and any errors. This telemetry is essential for understanding real-world usage patterns, identifying performance bottlenecks, and debugging production issues.
# Python - Custom metric emission and KQL query
import os
import time
from openai import AzureOpenAI
from applicationinsights import TelemetryClient
from azure.monitor.query import LogsQueryClient
from azure.identity import DefaultAzureCredential
# Emit custom telemetry for each API call
tc = TelemetryClient(os.environ["APPINSIGHTS_CONNECTION_STRING"])
client = AzureOpenAI(
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ["AZURE_OPENAI_KEY"],
api_version="2024-10-21"
)
def tracked_chat_completion(messages, model="gpt-4o-deployment"):
start = time.time()
try:
response = client.chat.completions.create(
model=model, messages=messages, temperature=0.3
)
latency_ms = (time.time() - start) * 1000
usage = response.usage
tc.track_event("OpenAICall", {
"model": model,
"prompt_tokens": usage.prompt_tokens,
"completion_tokens": usage.completion_tokens,
"total_tokens": usage.total_tokens,
"latency_ms": latency_ms,
"finish_reason": response.choices[0].finish_reason
})
tc.flush()
return response.choices[0].message.content
except Exception as e:
tc.track_exception()
tc.flush()
raise
# KQL query for analyzing API call patterns
query = """
AppEvents
| where Name == "OpenAICall"
| extend Model = tostring(Properties.model)
| extend PromptTokens = toint(Properties.prompt_tokens)
| extend CompletionTokens = toint(Properties.completion_tokens)
| extend Latency = toint(Properties.latency_ms)
| summarize
TotalCalls = count(),
AvgTokens = avg(PromptTokens + CompletionTokens),
AvgLatency = avg(Latency),
P95Latency = percentile(Latency, 95),
TotalErrors = countif(Properties.finish_reason == "error")
by Model, bin(Timestamp, 1h)
| order by Timestamp desc
"""
# Run the query using Azure Monitor
credential = DefaultAzureCredential()
logs_client = LogsQueryClient(credential)
response = logs_client.query_workspace(
workspace_id=os.environ["LOG_ANALYTICS_WORKSPACE_ID"],
query=query,
timespan=timedelta(days=7)
)
for row in response.tables[0].rows:
print(f"{row.Timestamp}: {row.Model} - "
f"Calls: {row.TotalCalls}, "
f"Avg tokens: {row.AvgTokens:.0f}, "
f"P95 latency: {row.P95Latency:.0f}ms")
Azure AI Services enforce rate limits to ensure fair resource sharing and protect service stability. Rate limits are expressed in transactions per second (TPS) or transactions per minute. The limit depends on the service, pricing tier, and region. For example, AI Vision S1 allows 10 TPS for Analyze Image but 100 TPS for OCR Read. Azure OpenAI Standard deployments have TPS limits based on the provisioned capacity unit (e.g., 100 TPM per capacity unit). When the rate limit is exceeded, the service returns HTTP 429 (Too Many Requests) with a Retry-After header indicating how long to wait before retrying. Your application must implement exponential backoff — retry with increasing delays (e.g., 1 second, 2 seconds, 4 seconds, 8 seconds) between attempts. The Azure SDKs for AI services include built-in retry policies with exponential backoff.
# Python - Retry with exponential backoff for 429 handling
import time
import requests
def call_with_retry(url, headers, json_payload, max_retries=5):
for attempt in range(max_retries):
response = requests.post(url, headers=headers, json=json_payload)
if response.status_code == 429:
retry_after = int(response.headers.get("Retry-After", 2 ** attempt))
print(f"Throttled. Retrying in {retry_after}s (attempt {attempt + 1}/{max_retries})")
time.sleep(retry_after)
continue
if response.status_code != 200:
response.raise_for_status()
return response.json()
raise Exception("Max retries exceeded — service is throttling heavily.")
# Example: Calling Vision OCR with retry
result = call_with_retry(
url="https://my-vision.cognitiveservices.azure.com/vision/v3.2/ocr",
headers={"Ocp-Apim-Subscription-Key": "your-key"},
json_payload={"url": "https://example.com/invoice.jpg"}
)
Error handling is critical for production AI applications. Understand the common HTTP error codes tested on the AI-102 exam. 401 (Unauthorized) means the API key is invalid, missing, or revoked — the client must provide a valid key or token. 403 (Forbidden) means the key is valid but does not have permission to access the specific resource or operation — check RBAC assignments or network restrictions (virtual networks, IP allowlists). 404 (Not Found) means the endpoint URL is incorrect or the resource does not exist — verify the endpoint URL and resource name. 429 (Throttled) means rate limit exceeded — implement exponential backoff and consider upgrading the tier or requesting a quota increase.
Optimizing costs for Azure AI solutions involves selecting the right tier, minimizing unnecessary calls, and optimizing input sizes. Start by analyzing usage patterns with Azure Monitor metrics — identify peak hours, low-usage periods, and the distribution of call types. If call volume is steady and growing, switch from pay-as-you-go S0 to a commitment tier for 40-60% savings. If you only need services during business hours, consider auto-shutdown scripts using Azure Automation or Logic Apps to disable resources during off-hours (though note that disabling AI resources retains their data). For development and testing, use the Free tier where possible, but remember the F0 limitations — only one instance per subscription per service.
Reduce unnecessary API calls by implementing caching — store results for identical requests in a Redis cache or Azure Cache for Redis with a TTL. For OCR and Document Intelligence, optimize input size — large images take longer to process and cost more. Resize images to the minimum resolution needed for accurate extraction (typically 300 DPI for document OCR). For Language services, batch multiple texts into a single API call (the Analyze API accepts up to 10 documents at a time) to stay within the same request cost. For Azure OpenAI, optimize prompt length — shorter prompts reduce input token costs, and lower max_tokens values reduce output token costs. Use the text-embedding-3-small model instead of large when accuracy requirements allow — the dimension reduction parameter further reduces storage and compute costs.
The AI-102 exam tests your understanding of error codes and their resolutions. Know that 401 means fix the key, 403 means fix permissions or network access, 404 means check the endpoint URL, and 429 means implement retry policies or request a quota increase. For quota increase requests, navigate to the resource's "Limits + Quota" blade in the Azure portal (or the "Quota" blade in Azure AI Studio for OpenAI). Increases are not instant — they require a support request and can take 1-2 business days. For regional pricing variance, understand that Azure AI Services may cost differently across regions — for example, US East and West Europe are typically the least expensive, while Brazil South and Southeast Asia may have premium pricing. Always check the pricing calculator before selecting a deployment region for cost-sensitive workloads.
Cost management, monitoring, and diagnostics are essential operational aspects of Azure AI solutions evaluated on the AI-102 exam. Pricing tiers (Free, Standard, Commitment) provide different cost profiles for different usage patterns — evaluating usage metrics helps select the right tier. Budget alerts notify you of approaching spending limits. Azure Monitor metrics track call volume, errors, latency, and data transfer for each AI service. Diagnostic logs (Audit, Request, Trace) provide detailed operational data that you route to Log Analytics, Storage, or Event Hubs. Application Insights gives you application-level telemetry for bots and custom SDK clients. Rate limiting at the service level requires exponential backoff retry policies in your application code. Cost optimization strategies — caching, tier selection, input optimization, and batching — reduce spending without sacrificing functionality. The next and final chapter provides comprehensive exam preparation, including a domain-by-domain review, practice questions, and study strategies.