2: Implement generative AI solutions

    Plan and prepare for a generative AI solution

    Planning a generative AI solution starts before any model deployment. The work splits into capacity sizing, identity, residency, content safety policy, integration surface, and the path foundational model updates will take through development, test, and production. A team that skips the planning phase repeats the same fix loop: a Standard deployment hits the regional TPM ceiling under load, a Global Standard deployment violates a data residency clause, a Provisioned deployment burns PTU minutes for a workload that runs once a week, or a model deprecation cycle takes the application offline because there is no version pin.

    The first decision is the workload shape. Interactive workloads (chat, copilot inline completions, code assist surfaces) demand low first token latency and tight failover. Batch workloads (nightly summarization, classification of historical documents, embedding refresh of a corpus) tolerate hours of latency for half the price. Streaming workloads (transcript copilots, real time call summarization) blend Speech in Foundry Tools with Azure OpenAI streaming responses and need provisioned capacity to keep tail latency in check. Map each user journey to one of those shapes before sizing capacity, because the deployment SKU follows directly.

    Sizing then translates expected traffic into tokens per minute (TPM) and requests per minute (RPM) for Standard family deployments, or into PTUs for Provisioned family deployments. The Foundry portal exposes the Azure OpenAI capacity calculator that takes peak RPM, input tokens per request, output tokens per request, and target model. The output is a recommended PTU count plus a minimum deployment size for the model. The same calculator helps right size Standard deployments by reporting whether the requested TPM fits within the regional default quota or whether a quota increase request through Azure support is required first.

    Residency planning runs alongside sizing. Standard and Provisioned deployments process traffic in the deployment region and store any prompts in that region. Data Zone Standard and Data Zone Provisioned deployments expand processing to the EU or US data zone while keeping data inside the zone. Global Standard and Global Provisioned route inference to any region within the Microsoft global Azure OpenAI footprint, which yields the deepest model availability but ships customer data outside any single region for the duration of the inference call. Workloads with a contractual residency clause (financial services, public sector, healthcare) almost always rule out Global SKUs. Workloads with no residency clause but a need for the latest model previews almost always select Global Standard first and migrate down to Data Zone when residency is finalized.

    Identity planning sits next to residency. Production deployments authenticate with Microsoft Entra ID through a managed identity assigned to the application host (Azure App Service, Azure Container Apps, Azure Functions, AKS via workload identity). Local development authenticates with az login and DefaultAzureCredential. Account keys remain useful for short lived test scripts only, and Chapter 1 already covered the disableLocalAuth switch that takes them off the table for production accounts. The RBAC roles Cognitive Services OpenAI User and Cognitive Services OpenAI Contributor gate inference and deployment management. The role Azure AI Developer gates Foundry project membership for builders.

    Provisioning an Azure OpenAI in Foundry Models resource

    Provisioning happens at two layers. The Foundry account is the parent resource (kind AIServices) that hosts the catalog. Each model deployment lives inside a Foundry project that connects to that account, and the deployment surface mirrors the original Azure OpenAI resource API. A team that previously ran a standalone Azure OpenAI resource sees the same deployment lifecycle, the same api-version pattern, and the same SDK clients, but the resource provider is Microsoft.CognitiveServices/accounts with kind=AIServices and the endpoint takes the Foundry shape.

    A minimal Bicep template provisions the account and a Standard deployment in one pass:

    param accountName string
    param location string = 'eastus2'
    param modelName string = 'gpt-4o'
    param modelVersion string = '2024-11-20'
    param deploymentName string = 'gpt-4o-prod'
    param capacity int = 50
    
    resource foundry 'Microsoft.CognitiveServices/accounts@2024-10-01' = {
     name: accountName
     location: location
     sku: {
     name: 'S0'
     }
     kind: 'AIServices'
     identity: {
     type: 'SystemAssigned'
     }
     properties: {
     customSubDomainName: accountName
     publicNetworkAccess: 'Enabled'
     disableLocalAuth: true
     networkAcls: {
     defaultAction: 'Allow'
     }
     }
    }
    
    resource deployment 'Microsoft.CognitiveServices/accounts/deployments@2024-10-01' = {
     parent: foundry
     name: deploymentName
     sku: {
     name: 'Standard'
     capacity: capacity
     }
     properties: {
     model: {
     format: 'OpenAI'
     name: modelName
     version: modelVersion
     }
     versionUpgradeOption: 'OnceCurrentVersionExpired'
     raiPolicyName: 'Microsoft.Default'
     }
    }
    

    The sku.name field selects the deployment SKU family (Standard, GlobalStandard, DataZoneStandard, ProvisionedManaged, GlobalProvisionedManaged, DataZoneProvisionedManaged, Batch). capacity is in TPM thousands for Standard SKUs and in PTUs for Provisioned SKUs. The versionUpgradeOption property controls how the deployment reacts when the configured model version reaches end of life: OnceCurrentVersionExpired upgrades to the next supported version automatically, NoAutoUpgrade blocks any upgrade, and OnceNewDefaultVersionAvailable upgrades as soon as Microsoft promotes a newer version to default.

    💡 Exam Trap: versionUpgradeOption=NoAutoUpgrade does not protect against retirement. When Microsoft retires a model version the deployment stops serving traffic. Choose NoAutoUpgrade only when the team has a manual upgrade runbook tied to retirement notices.

    💡 Exam Trap: Capacity in a Standard deployment is in units of 1,000 TPM. A capacity of 50 buys 50,000 TPM, not 50 requests per minute. The RPM ceiling is derived as TPM divided by 1,000 multiplied by 6, so 50 capacity gives 300 RPM.

    Optimizing and managing resources for deployment, including scalability and foundational model updates

    Scaling Standard family deployments uses two knobs. First, raise the capacity value on the deployment to consume more of the available regional TPM. Second, request additional regional quota through Azure Help and Support when the account is at the regional ceiling. Scaling Provisioned family deployments uses PTU reservations; PTUs are reserved capacity per minute and bill at a flat rate independent of token volume. Provisioned scaling responds to traffic by adding PTUs to the deployment, not by raising a TPM number.

    Foundational model updates flow through three stages. Microsoft publishes a model version (for example gpt-4o-2024-11-20). Each version progresses from preview to GA, then to legacy, then to retired. The versionUpgradeOption setting on the deployment chooses the rollover policy. Production teams use a blue/green pattern: deploy the new version to a parallel deployment name, route a small percentage of traffic through application logic, validate evaluation metrics, and cut over by renaming the production deployment or by swapping the deployment string in configuration.

    from azure.identity import DefaultAzureCredential
    from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient
    
    credential = DefaultAzureCredential()
    sub_id = "<subscription-id>"
    rg = "rg-foundry-prod"
    account = "foundry-prod-eus2"
    
    client = CognitiveServicesManagementClient(credential, sub_id)
    
    new_deployment = client.deployments.begin_create_or_update(
     resource_group_name=rg,
     account_name=account,
     deployment_name="gpt-4o-canary",
     deployment={
     "sku": {"name": "Standard", "capacity": 10},
     "properties": {
     "model": {
     "format": "OpenAI",
     "name": "gpt-4o",
     "version": "2024-11-20",
     },
     "versionUpgradeOption": "NoAutoUpgrade",
     "raiPolicyName": "rai-strict-prod",
     },
     },
    ).result()
    

    📊 Limit: A single Foundry account can hold many deployments, but each model version has a per region TPM allocation. The Azure OpenAI quotas and limits page lists the default values; numbers vary by model and region.

    ⚠️ Anti-Pattern: Pinning a Provisioned deployment to a version with NoAutoUpgrade and then forgetting it. When the version retires the PTU reservation continues to bill while the deployment refuses traffic. Track every pinned version against the model retirement calendar.

    🎯 Scenario: A retail copilot serves 800 RPM at peak with average input of 1,500 tokens and output of 300 tokens. That sums to roughly 1.44 million TPM. Standard at 1,500 capacity would cover steady state but cannot tolerate the spiky shopping weekend. The team moves to GlobalProvisionedManaged at 100 PTU, which Microsoft sizes through the capacity calculator, and falls back to a GlobalStandard deployment when the PTU pool is fully consumed.

    Decision Anchor: Choose Standard when traffic fits the regional TPM ceiling and the team needs the lowest cost per token. Choose Provisioned when latency must be predictable and the workload sustains constant traffic worth the PTU reservation. Choose Batch when the workload is offline and a 24 hour SLA is acceptable. Choose Global SKUs when residency is unconstrained and broader model availability matters.

    The planning artifact that ties everything together is a capacity plan document with: workload shape, expected peak RPM, average input and output tokens, region, residency constraint, SKU choice, capacity number, RBAC roles, and version upgrade option. Reviewing that document with the security and finance owners before deploying anything removes most of the rework that hits generative AI projects later.


    Continue with the interactive course

    Track your progress, jump into practice questions and use the Shark AI tutor inside the Microsoft - AI-102 learning hub.