Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/apim.md
1# APIM Deployment Guide23Deploy Azure API Management (APIM) as part of your Azure infrastructure.45> **For AI Gateway configuration** (policies, backends, semantic caching), use the **azure-aigateway** skill after deployment.67---89## When to Deploy APIM1011| Scenario | APIM Tier | Notes |12|----------|-----------|-------|13| AI Gateway for model governance | Standard v2 or Premium v2 | Semantic caching requires v2 SKUs |14| API consolidation | Standard v2 | Single entry point for microservices |15| MCP tool hosting | Standard v2 | Rate limiting and auth for AI tools |16| Development / Testing | Developer | Not for production |17| High-volume production | Premium v2 | Multi-region, higher limits |1819---2021## Quick Deploy (Azure CLI)2223### 1. Create APIM Instance2425```bash26az apim create \27--name <apim-name> \28--resource-group <rg> \29--location <location> \30--publisher-name "<your-org>" \31--publisher-email "<[email protected]>" \32--sku-name "StandardV2" \33--sku-capacity 13435# ⚠ APIM provisioning takes 30-45 minutes for Standard/Premium tiers36```3738### 2. Enable Managed Identity3940```bash41az apim update --name <apim-name> --resource-group <rg> \42--set identity.type=SystemAssigned43```4445### 3. Get Gateway URL4647```bash48az apim show --name <apim-name> --resource-group <rg> \49--query "gatewayUrl" -o tsv50```5152---5354## Bicep Template5556```bicep57@description('Name of the API Management instance')58param apimName string5960@description('Location for the APIM instance')61param location string = resourceGroup().location6263@description('Publisher organization name')64param publisherName string6566@description('Publisher email address')67param publisherEmail string6869@description('SKU name (StandardV2 recommended for AI Gateway)')70@allowed(['Developer', 'StandardV2', 'PremiumV2'])71param skuName string = 'StandardV2'7273@description('Number of scale units')74param skuCapacity int = 17576resource apim 'Microsoft.ApiManagement/service@2023-09-01-preview' = {77name: apimName78location: location79sku: {80name: skuName81capacity: skuCapacity82}83identity: {84type: 'SystemAssigned'85}86properties: {87publisherName: publisherName88publisherEmail: publisherEmail89}90}9192output apimId string = apim.id93output gatewayUrl string = apim.properties.gatewayUrl94output principalId string = apim.identity.principalId95```9697### With Azure OpenAI Backend (AI Gateway Pattern)9899```bicep100@description('Name of the Azure OpenAI resource')101param aoaiName string102103@description('Resource group of the Azure OpenAI resource')104param aoaiResourceGroup string = resourceGroup().name105106// Reference existing Azure OpenAI107resource aoai 'Microsoft.CognitiveServices/accounts@2024-04-01-preview' existing = {108name: aoaiName109scope: resourceGroup(aoaiResourceGroup)110}111112// APIM Backend pointing to Azure OpenAI113resource openaiBackend 'Microsoft.ApiManagement/service/backends@2023-09-01-preview' = {114parent: apim115name: 'openai-backend'116properties: {117protocol: 'http'118url: '${aoai.properties.endpoint}openai'119tls: {120validateCertificateChain: true121validateCertificateName: true122}123}124}125126// Grant APIM access to Azure OpenAI127resource cognitiveServicesUser 'Microsoft.Authorization/roleAssignments@2022-04-01' = {128name: guid(apim.id, aoai.id, 'Cognitive Services User')129scope: aoai130properties: {131roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'a97b65f3-24c7-4388-baec-2e87135dc908')132principalId: apim.identity.principalId133principalType: 'ServicePrincipal'134}135}136```137138---139140## Terraform Module141142```hcl143resource "azurerm_api_management" "apim" {144name = var.apim_name145location = var.location146resource_group_name = var.resource_group_name147publisher_name = var.publisher_name148publisher_email = var.publisher_email149sku_name = "${var.sku_name}_${var.sku_capacity}"150151identity {152type = "SystemAssigned"153}154}155156output "gateway_url" {157value = azurerm_api_management.apim.gateway_url158}159160output "principal_id" {161value = azurerm_api_management.apim.identity[0].principal_id162}163```164165---166167## Post-Deployment Steps168169After APIM is deployed:1701711. **Configure AI backends** → Use **azure-aigateway** skill1722. **Import APIs** → `az apim api import` or portal1733. **Apply policies** → Invoke **azure-aigateway** skill for AI governance policies1744. **Enable monitoring** → Connect Application Insights1755. **Secure endpoints** → Configure subscriptions and RBAC176177---178179## SKU Selection Guide180181| Feature | Developer | Standard v2 | Premium v2 |182|---------|-----------|-------------|------------|183| GenAI policies | ✅ | ✅ | ✅ |184| Semantic caching | ❌ | ✅ | ✅ |185| VNet integration | ❌ | ✅ | ✅ |186| Multi-region | ❌ | ❌ | ✅ |187| SLA | None | 99.95% | 99.99% |188| Scale units | 1 | 1-10 | 1-12 per region |189| Provisioning time | ~30 min | ~30 min | ~45 min |190191> **Recommendation**: Use **Standard v2** for most AI Gateway scenarios. Use **Premium v2** only for multi-region or high-compliance requirements.192193---194195## Naming Conventions196197| Resource | Pattern | Example |198|----------|---------|---------|199| APIM Instance | `apim-<app>-<env>` | `apim-myapp-prod` |200| API | `<api-name>-api` | `openai-api` |201| Backend | `<service>-backend` | `openai-backend` |202| Product | `<tier>-product` | `premium-product` |203| Subscription | `<consumer>-sub` | `frontend-sub` |204205---206207## References208209- [APIM v2 Overview](https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview)210- [APIM Bicep Reference](https://learn.microsoft.com/azure/templates/microsoft.apimanagement/service)211- [APIM Terraform](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management)212- [GenAI Gateway Capabilities](https://learn.microsoft.com/azure/api-management/genai-gateway-capabilities)213