AI Workload Security
AI Gateway in API Management for Foundry · Defender for AI Services · Foundry guardrails · Data and AI security dashboard
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
AI Gateway in Azure API Management for Foundry
The AI gateway in Azure API Management is a set of capabilities for managing AI backends: securing, scaling, monitoring and governing AI models, agents and tools. It extends API Management's existing API gateway and is not a separate offering. In Microsoft Foundry, AI Gateway uses API Management behind the scenes to provide token limits, quotas and governance for model deployments.
| Area | Capability |
|---|---|
| Security and safety | Managed identities to authenticate to AI services (no API keys); OAuth authorization for apps and agents through the credential manager; prompt moderation with Azure AI Content Safety |
| Scalability and performance | Token limit policy (llm-token-limit) with a tokens-per-minute limit or a quota; semantic caching with Azure Managed Redis or another RediSearch-compatible external cache; scale units and regional gateways |
| Resiliency | Backends with load balancing and circuit breaker rules that stop forwarding to unresponsive AI backends |
| Traffic mediation | Import OpenAI-compatible or passthrough LLM endpoints and models in Foundry or other providers; expose REST APIs as MCP servers; manage A2A agent APIs |
- Capability availability varies by API Management service tier. A unified model API appears as a preview feature on the AI gateway page.
- The token limit policy applies per counter key (subscription key, originating IP address, or a policy expression key). Either a rate limit (
tokens-per-minute), a quota (token-quotaover a period of Hourly, Daily, Weekly, Monthly or Yearly), or both must be specified. Exceeding the rate returns 429 Too Many Requests; exceeding the quota returns 403 Forbidden. - The
llm-content-safetypolicy sends prompts or completions to Azure AI Content Safety and blocks malicious content by returning a 403 error code. Optionalshield-promptchecks content for user attacks; custom blocklists are supported.
Content safety policy prerequisites
- An Azure AI Content Safety resource.
- An API Management backend for the Content Safety service. Its URL must be of the form
https://<content-safety-service-name>.cognitiveservices.azure.com, and its authorization credentials must be Managed Identity with the exact resource IDhttps://cognitiveservices.azure.com. - API Management's managed identity configured on the Content Safety service with the Cognitive Services User role.
Enable AI Gateway for a Foundry resource
- Sign in to Microsoft Foundry with the New Foundry toggle on and select Manage > AI Gateway > Add AI Gateway.
- Select the Foundry resource and choose Create new or Use existing API Management.
- Name the gateway and select Add. Wait until the status shows Enabled (provisioning of a Basic v2 instance typically takes 5-10 minutes).
- Add existing projects with Add project to gateway. New projects created in the Foundry resource have AI Gateway enabled by default.
| Requirement | Detail |
|---|---|
| Create a new API Management instance | Contributor or Owner on the target resource group (or subscription) |
| Manage an existing instance | API Management Service Contributor (or Owner) on the instance |
| Foundry portal access | For example Foundry Account Owner or Foundry Owner on the Foundry resource |
| Use existing APIM list | Same Microsoft Entra tenant and same subscription as the Foundry resource; you have at least API Management Service Contributor on it; created in one of the v2 tiers |
| Create new | Creates a Basic v2 SKU instance, designed for development and testing with SLA support. For production or higher throughput, consider an existing Standard v2 or Premium v2 instance |
| Private Foundry resource | If public network access is disabled, use a Standard v2 or Premium v2 instance with a private endpoint, or a Premium v2 instance injected in a virtual network |
- You enable AI Gateway at the Foundry resource level. All projects in that resource share the gateway and its API Management instance; each project gets its own token limits and quotas (limits apply at the project level).
- For completely separate gateways, place projects in separate Foundry resources and enable a gateway on each.
- Disable vs delete: removing a project from the gateway only stops routing that project's traffic. Disabling a project alone doesn't delete the gateway or stop API Management charges. To remove it fully, delete the gateway from the Foundry resource and then delete the API Management instance with the same name, unless another workload still uses it.
- Verify: in the API Management instance check Monitoring > Metrics (Requests), add a diagnostic setting for logs related to ApiManagement Gateway sent to a Log Analytics workspace with a resource-specific table, and query
ApiManagementGatewayLogs. - The Foundry RBAC roles were recently renamed (for example Foundry Account Owner was Azure AI Account Owner); role IDs and permissions are unchanged.
Defender for AI Services in Defender for Cloud
Threat protection for AI services in Microsoft Defender for Cloud protects Microsoft Foundry workloads on an Azure subscription. It works with Azure AI Content Safety Prompt Shields and Microsoft's threat intelligence to provide alerts for threats such as data leakage, data poisoning, jailbreak and credential theft, and it integrates with Defender XDR so AI workload alerts can be centralized in the Defender XDR portal.
| Aspect | Detail |
|---|---|
| Release state | Generally available (GA) |
| Pricing | Billing is on the Defender for Cloud pricing page. 30-day free trial, capped at 75 billion tokens scanned; billing begins if the cap is reached within the 30 days |
| Scanned content | Text tokens only. Image and audio tokens aren't scanned |
| Clouds | Commercial clouds: yes. Azure Government: no. Microsoft Azure operated by 21Vianet: no. Connected AWS accounts: no |
| Features | Activity monitoring (security alerts) and prompt evidence (security alerts) |
Enable the plan
- Enable Defender for Cloud on the Azure subscription. To enable the plan you need Owner or Contributor level (the onboarding article); the overview article says Owner at subscription scope or specific roles with corresponding data actions, so don't rely on the exact role in an answer.
- In the Azure portal open Microsoft Defender for Cloud > Environment settings and select the subscription.
- On the Defender plans page, toggle AI services to On.
| Component (AI services > Settings) | What it does |
|---|---|
| Suspicious prompt evidence | Alerts include suspicious parts of user prompts and model responses, with sensitive data automatically redacted. If it is disabled, analysis of prompts and responses for threat detection continues but the prompt content is masked in alerts |
| Data security for AI interactions | Lets Microsoft Purview access and analyze prompts, responses and metadata (SIT classification, auditing, insider risk, communication compliance, eDiscovery). It is a paid Purview feature that requires a Microsoft Purview license and is not included in the Defender for AI Services plan |
| AI model security | Model scanning gives a unified view of models registered in Azure Machine Learning registries and checks for issues such as serialization vulnerabilities, malware and missing scans |
- Purview integration does not include data or context from Foundry agents.
- Data security policies for Foundry interactions are supported only for API calls that use Microsoft Entra ID authentication with a user-context token, or that explicitly include user context. In other cases, interactions show up only in Purview Audit and DSPM for AI Activity Explorer.
- If Entra ID user interactions don't show in Purview Activity Explorer, check that the Microsoft Purview service principal exists in the tenant and add it if not (see the commands list).
- The onboarding article says the current Purview configuration method for Foundry is being deprecated and points to a new method under Manage compliance and security in Microsoft Foundry.
AI security posture (Defender CSPM) and alerts
- Defender CSPM discovers deployed AI workloads across Azure OpenAI Service, Azure AI Foundry, Azure Machine Learning, Amazon Bedrock and Google Vertex AI, including the generative AI Bill of Materials (AI BOM). It secures generative AI applications and AI agents (Preview), and attack path analysis detects and mitigates risks to AI workloads.
- Current IaC AI security checks include using Azure AI Service private endpoints, restricting Azure AI Service endpoints, and using managed identity or identity-based authentication for Azure AI Service accounts.
- Agent 365 transition: effective July 1, 2026, AI agent discovery and security posture for Foundry agents and third-party cloud agents require a Microsoft Agent 365 license. Defender CSPM continues to discover Foundry accounts and projects. Agent-specific alerts in the Defender for AI Services plan will be deprecated (the page's wording), and the plan continues to support Foundry Models such as Azure OpenAI.
Foundry guardrails for models and agents
A guardrail is a named collection of controls. Each control defines a risk to detect, the intervention points to scan, and the action to take. Risks are flagged by classification models from Azure AI Content Safety. Agent guardrails are in preview. One guardrail can be applied to one or many models and agents in a project.
| Intervention point | What is scanned | Models | Agents |
|---|---|---|---|
| User input | The prompt sent to a model or agent | Yes | Yes |
| Tool call (Preview) | The action and data the agent proposes to send to a tool | No | Yes (Preview) |
| Tool response (Preview) | The content returned from a tool to the agent | No | Yes (Preview) |
| Output | The final completion returned to the user | Yes | Yes |
- Actions: Annotate and Annotate and block apply to models; only Annotate and block applies to agents.
- Blocking levels for Hate, Sexual, Self-harm and Violence: Off, Low (blocks high-severity only), Medium (blocks medium and high), High (blocks low, medium and high; most restrictive). All customers can turn off content harms for inputs; turning them off for outputs is for approved customers only.
- Some risks aren't applicable to agents: Spotlighting (Preview) and Groundedness (Preview) apply to models but not agents. Controls for risks not yet supported for agents don't take effect for that agent but still apply to models using the same guardrail.
- Override: risks are detected in an agent based on the guardrail it is assigned, not the guardrail of its underlying model; the agent guardrail fully overrides the model guardrail. If the model has Violence at High and the agent has Violence at Low for input and output with no tool controls, user queries are scanned at Low and tool calls and tool responses are not scanned for Violence.
- Tool call and tool response intervention points require moderation support from the tool: Azure AI Search, Azure Functions, OpenAPI, Sharepoint Grounding, Fabric Data Agent, Bing Grounding, Bing Custom Search and Browser Automation. Controls don't take effect for tools not in this list.
- The guardrail system applies to Foundry Models sold by Azure (except prompts and completions processed by audio transcription models) and currently applies only to agents developed in the Foundry Agent Service, not other agents registered in the Foundry Control Plane.
- Hosted agents also support network egress controls (preview) configured in the same guardrail. Each intervention point adds roughly 50-100 ms of latency.
Create and assign a guardrail
- Role: Foundry Account Owner or higher on the Azure AI resource.
- In your project select Build, then the Guardrails page, then Create Guardrail (Step 1: Add Controls).
- Select a risk, choose intervention points and one action, then Add control.
- Select Next (Step 2) and choose agents and models to assign, then Next (Step 3: Review). Name the guardrail and select Create.
- To edit a control that can't be deleted (Violence, Hate, Sexual, Self-harm on user inputs and outputs) override it by adding a control for the same risk and confirming.
- Microsoft Default guardrails, such as Default.V2, can't be edited. Deselecting an agent or model from your guardrail re-assigns the Microsoft Default.
- You can also assign from the agent or model (Manage in the Guardrails section of the playground); the new guardrail takes effect immediately.
- To delete a guardrail that has assignments, first reassign the models and agents to a different guardrail or back to the Microsoft Default.
Data and AI security dashboard
The Data and AI security dashboard in Defender for Cloud gives one place to monitor data and AI resources, their risks and protection status. It highlights critical issues, resources that need attention and internet-exposed resources, and it combines attack paths, recommendations and data threat analysis. It is enabled at the subscription level and shows data based on the plans enabled in the subscription.
| Requirement | Detail |
|---|---|
| Plans for full access | Defender CSPM plan, and its sensitive data discovery extension, Defender for Storage, Defender for Databases, and threat protection for AI workloads |
| Resource provider | Register each relevant Azure subscription to the Microsoft.Security resource provider |
| Permissions | Microsoft.Security/assessments/read, Microsoft.Security/assessments/subassessments/read, Microsoft.Security/alerts/read |
| Minimum role | Security explorer (minimum required privileged RBAC role) |
| Section | What it shows |
|---|---|
| Data and AI security overview | Resources by cloud: storage assets, managed databases, hosted databases (IaaS) and AI services; which are fully, partially or not protected by Defender CSPM, Defender for Storage, Defender for Databases and AI threat protection |
| Top issues | Resources needing the most immediate attention: highest-severity alerts by MITRE ATT&CK tactic, and critical and high recommendations and attack paths |
| Data closer look | Sensitive data discovery, data threat protection, data queries in security explorer, internet exposed data resources |
| AI closer look | AI discovery, AI threat protection (prompts scanned and alerts by severity), AI queries in security explorer (for example sensitive data used for grounding), internet exposed resources used for grounding |
Foundry agent data will no longer appear in the Data and AI dashboard or in Cloud Security Explorer, per the Agent 365 transition article.
Troubleshooting: why is it still exposed?
| Symptom | Likely cause | Fix |
|---|---|---|
| Existing API Management instance not listed for AI Gateway | Not a v2 tier, a different tenant or subscription, or you lack API Management Service Contributor | Use a v2 tier instance in the same tenant and subscription with the right role |
| Permission error creating the gateway | Missing Contributor or Owner on the resource group (to create) | Assign the role, or use an existing instance with API Management Service Contributor |
| Older project bypasses the gateway | Existing projects aren't added automatically | Add project to gateway; check Gateway status is Enabled |
| Token limits don't apply | Limits not configured, or the project isn't using the gateway | Enable the project for the gateway, then configure limits on Manage > AI Gateway |
| 500 errors right after gateway setup | Auto-created endpoints still provisioning or model deployment not mapped | Wait several minutes, test without the gateway, check API Management logs; remove and re-add the project |
| Prompt snippets masked in Defender alerts | User prompt evidence is off (analysis still runs) | Turn on Enable user prompt evidence |
| Tool controls in a guardrail do nothing | Tool isn't on the moderation list, or the control is for a risk not supported for agents | Use a supported tool or a supported risk; remember the agent guardrail overrides the model's |
| Dashboard incomplete | Plans not enabled, resource provider not registered | Enable Defender CSPM and related plans; register Microsoft.Security |
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Install the Az PowerShell modules (troubleshooting Purview data security for AI interactions) | - | Install-Module -Name Az -AllowClobber |
| Connect to Azure PowerShell as a tenant admin | - | Connect-AzAccount -Tenant $yourTenantIdHere |
| Check that the Microsoft Purview service principal exists in the tenant | - | Get-AzADServicePrincipal -ApplicationId "9ec59623-ce40-4dc8-a635-ed0275b5d58a" |
| Add the Microsoft Purview service principal to the tenant | - | New-AzADServicePrincipal -ApplicationId "9ec59623-ce40-4dc8-a635-ed0275b5d58a" |
Exam Tips
Tick each tip once you can answer it without looking.
“Foundry AI Gateway: existing APIM instance missing from the list” → It must be a v2 tier, in the same tenant and subscription as the Foundry resource, with API Management Service Contributor or Owner on it. Trap: Create new makes a Basic v2 instance (dev and test); for production use an existing Standard v2 or Premium v2.
“Roles to create the gateway” → Contributor or Owner on the target resource group or subscription, plus Foundry Account Owner or Foundry Owner for portal access. Trap: API Management Service Contributor is for managing an existing instance, assigned on that instance.
“Project created before the gateway still bypasses it” → Manage > AI Gateway, select the gateway, Add project to gateway. Trap: New projects are enabled by default; existing ones aren't. Token limits don't apply if the project isn't using the gateway.
“Stop AI Gateway charges” → Delete the gateway from the Foundry resource, then delete the API Management instance. Trap: Disabling or removing projects leaves the gateway and its charges in place.
“AI gateway token policy responses” → 429 Too Many Requests for the tokens-per-minute limit; 403 Forbidden for the total token quota. Trap: llm-content-safety also returns 403 when it blocks malicious content.
“API Management calls to Azure AI Content Safety fail” → Backend uses Managed Identity (resource ID https://cognitiveservices.azure.com) and the API Management managed identity has the Cognitive Services User role on the Content Safety service. Trap: The backend URL must look like https://<name>.cognitiveservices.azure.com, not an OpenAI endpoint with an API key.
“AI gateway security features: no API keys, moderated prompts” → Managed identities, credential manager OAuth, and Azure AI Content Safety policies. Trap: Semantic caching is performance; circuit breakers are resiliency.
“Turn on threat protection for AI services” → Defender for Cloud > Environment settings > subscription > Defender plans > AI services On (GA). Trap: Text tokens only are scanned; the 30-day trial is capped at 75 billion tokens, then billing begins; not available in Azure Government or 21Vianet.
“Defender for AI alerts show masked prompt text” → Enable user prompt evidence in the plan settings; detection already runs. Trap: Data security for AI interactions is a different, Purview toggle.
“Data security for AI interactions toggle” → Needs a Purview license (not in the Defender for AI Services plan); excludes Foundry agent data; policies need Entra ID auth with user context. Trap: Other calls show only in Purview Audit and DSPM for AI Activity Explorer.
“Foundry guardrail: agent guardrail vs model guardrail” → The agent's guardrail fully overrides the model's; risks are detected from the guardrail the agent is assigned. Trap: Tool calls and tool responses aren't scanned for a risk unless the agent's guardrail has a control there.
“Foundry guardrail intervention points” → User input, Tool call (Preview), Tool response (Preview), Output; tool points are agents only. Trap: Tool controls need a tool with moderation support; otherwise they don't take effect. Agent guardrails are in preview; agents use only Annotate and block.
“Edit a Microsoft Default guardrail or a Violence input control” → Default.V2 can't be edited; create your own guardrail, and override undeletable controls by adding a control for the same risk. Trap: Blocking level Low blocks only high-severity content; High is most restrictive.
“Which role creates Foundry guardrails?” → Foundry Account Owner or higher. Trap: The roles were renamed from Azure AI Account Owner; role IDs and permissions are unchanged.
“Data and AI security dashboard prerequisites” → Defender CSPM plan (plus related plans), Microsoft.Security resource provider registered per subscription, minimum role Security explorer. Trap: It is enabled at the subscription level, not tenant level; Foundry agent data will no longer appear after the Agent 365 transition, per the transition article.
Sources
- AI gateway capabilities in Azure API Management
- Configure AI Gateway in your Foundry resources
- Azure API Management policy reference: llm-content-safety
- Azure API Management policy reference: llm-token-limit
- AI threat protection in Microsoft Defender for Cloud
- Enable threat protection for AI services
- AI security posture management overview
- Alerts for AI services
- Guardrails and controls overview in Microsoft Foundry
- Intervention points concepts
- How to configure guardrails and controls in Microsoft Foundry
- Data and AI security dashboard
- Transition Copilot Studio and Foundry agent security capabilities to Microsoft Agent 365
Checked against Microsoft Learn on November 13, 2026.