Exposing a Microsoft Foundry Agent over A2A via Azure API Management
- Authors

- Name
- Nino
- Occupation
- Senior Tech Editor
Connecting enterprise AI capabilities directly to network consumers without unified governance creates security risks, token management sprawl, and architectural debt. Microsoft AI Foundry allows developers to create autonomous AI agents, but directly exposing these endpoints bypassing corporate gateways exposes infrastructure to unthrottled traffic and unmonitored queries.
By placing Azure API Management (APIM) in front of Microsoft AI Foundry’s Agent2Agent (A2A) protocol endpoint, you introduce central governance, subscription key management, consumer quotas, and full OpenTelemetry/Application Insights tracing. When orchestration requirements expand across multiple model providers, developers can also integrate multi-cloud model endpoints alongside custom agents using n1n.ai for unified LLM access.
This step-by-step guide demonstrates how to securely expose a Microsoft AI Foundry agent over the open A2A protocol using APIM and System-Assigned Managed Identity authentication.
Architecture Overview
The sequence flow maps how an unauthenticated network client communicates with the gated APIM instance, which acquires an Entra ID (Azure AD) token on behalf of the caller and proxies the JSON-RPC request to Microsoft AI Foundry.
Postman / Application / Calling Agent
│
│ POST https://api.yourcompany.com/agents/helper-agent
│ Header: Ocp-Apim-Subscription-Key: <key>
▼
Azure API Management (APIM)
├── 1. Validates Subscription Key & Rate Limits
├── 2. Acquires Entra ID Token (Scope: https://ai.azure.com)
└── 3. Sets Header A2A-Version: 1.0
│
▼ POST https://{account}.services.ai.azure.com/api/projects/{project}/agents/{agent}/endpoint/protocols/a2a
│ Header: Authorization: Bearer <Entra_Token>
▼
Microsoft AI Foundry Agent Endpoint (helper-agent)
Core Technical Benefits
- Enterprise Governance: Centralized API access controls, rate limiting, and subscription key isolation without altering model backend configurations.
- Unified Front Door: Single URL path structure (
/agents/*) across both AI Foundry native agents and custom-hosted container agents. - Zero-Trust Token Exchange: APIM seamlessly exchanges subscription keys for short-lived Entra ID bearer tokens using its System-Assigned Managed Identity.
Prerequisites & Environment Baseline
Ensure the following assets and access levels are available before configuration:
| Requirement | Purpose | Required Role / Setting |
|---|---|---|
| Foundry Project | Hosts the target agent resource | Project Owner or Foundry Project Manager |
| APIM Instance | Functions as the security gateway | Contributor on APIM instance; System-Assigned Managed Identity ON |
| Network Client | Testing and request dispatch | Postman, cURL, or custom HTTP client |
| Target Runtime | Endpoint foundation | Microsoft AI Foundry (New Foundry Experience enabled) |
Configuration Reference Values
Replace the placeholders throughout this tutorial with your specific resource values:
- Account Name:
contoso-agents-poc - Project Name:
contoso-agents-poc - Agent Name:
helper-agent - APIM Name:
contoso-apim - Gateway Base Hostname:
https://api.yourcompany.com(orhttps://contoso-apim.azure-api.net)
Target A2A Base Endpoint Format
Every Foundry agent exposes a standardized A2A protocol URI structure:
https://{account}.services.ai.azure.com/api/projects/{project}/agents/{agent}/endpoint/protocols/a2a
For our target environment, the full base backend URL is: https://contoso-agents-poc.services.ai.azure.com/api/projects/contoso-agents-poc/agents/helper-agent/endpoint/protocols/a2a
Step 1: Configure Microsoft AI Foundry Agent & Agent Card
- Navigate to the Microsoft AI Foundry portal (
ai.azure.com). Verify that the New Foundry experience toggle in the top right is active. - Select your Project (
contoso-agents-poc), navigate to Build → Agents, and click + Create agent. - Name the agent
helper-agentand attach a deployed chat model (e.g.,gpt-4o-mini). - Provide operational instructions:
"You answer questions regarding corporate holiday policies. Be concise. If asked about unrelated subjects, reply that it is outside your scope."
- Click Save. The agent endpoint is immediately provisioned.
Create the Agent Card (A2A Discovery Metadata)
The Agent Card is a structured JSON manifest defining agent capability scopes for inter-agent discovery.
- Select
helper-agentand navigate to the Details tab. - In the A2A / Agent card section, click Create an agent card (Preview).
- Populate the manifest values:
- Name:
helper-agent - Description:
Answers corporate holiday policy queries. Excludes payroll and general IT. - Topics:
holiday, leave, policy, hr - Capabilities:
Given a query regarding leave, returns structured policy guidance. - Sample Prompt:
How many days of annual leave are standard?
- Name:
- Click Save.
Step 2: Register the A2A API in Azure API Management
- Open the Azure Portal and select your APIM instance (
contoso-apim). - From the left menu, select APIs → + Add API.
- Choose the A2A Agent tile.
Note on Compatibility: Native A2A Agent API import capabilities are available on APIM v2 tiers and classic tiers updated past the mid-2026 release cycle. If absent, manual HTTP API registration can be performed using identical policy blocks.
- In the URL field, enter the Agent Card Endpoint:
https://contoso-agents-poc.services.ai.azure.com/api/projects/contoso-agents-poc/agents/helper-agent/endpoint/protocols/a2a/agentCard/v1.0 - Click Next.
Expected Warning Behavior
APIM will display a notification: "We couldn't retrieve the agent card, possibly due to a wrong url or your network configuration."
This occurs because APIM attempts an unauthenticated GET fetch. Foundry strictly requires an Entra ID bearer token for all endpoints including card reads. Ignore the warning and complete the registration manually:
- Protocol:
JSON-RPC - Runtime URL (JSON-RPC):
https://contoso-agents-poc.services.ai.azure.com/api/projects/contoso-agents-poc/agents/helper-agent/endpoint/protocols/a2a - Agent ID:
helper-agent - Display Name:
Helper Agent - Name:
helper-agent - Base path:
agents/helper-agent
Click Create.
Step 3: Configure Entra ID RBAC for APIM Managed Identity
APIM must acquire short-lived bearer tokens scoped to https://ai.azure.com to authenticate against Foundry.
Enable System-Assigned Managed Identity
- In your APIM instance menu, navigate to Security → Managed identities.
- Select the System assigned tab.
- Toggle Status to On and click Save. Copy the generated Object (principal) ID.
Assign Azure RBAC Permissions
- Navigate to the Foundry Project resource in the Azure Portal.
- Open Access control (IAM) → + Add → Add role assignment.
- Select the Foundry User role (or assign
Foundry Agent Consumervia Azure CLI using Role IDeed3b665-ab3a-47b6-8f48-c9382fb1dad6). - Assign access to Managed identity → Select members → Choose your APIM instance
contoso-apim. - Click Review + assign.
Propagating Delay: Azure RBAC role assignments can take 3 to 5 minutes to propagate across Microsoft Entra ID. Allow this time before issuing test requests to avoid false
401 Unauthorizedor403 Forbiddenerrors.
Step 4: Define APIM Inbound Policy Rules
Configure the gateway policy to automatically acquire tokens, set target URLs, and inject protocol negotiation headers.
Navigate to APIs → helper-agent → Policies (Code View) and inject the following policy definition:
<policies>
<inbound>
<base />
<authentication-managed-identity resource="https://ai.azure.com" />
<set-backend-service base-url="https://contoso-agents-poc.services.ai.azure.com/api/projects/contoso-agents-poc/agents/helper-agent/endpoint/protocols/a2a" />
<set-header name="A2A-Version" exists-action="override">
<value>1.0</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Detailed Policy Analysis
authentication-managed-identity: Requests an Entra ID OAuth access token for resourcehttps://ai.azure.comvia the local IMDS identity subsystem and attaches it as aBearertoken to the upstreamAuthorizationheader.set-backend-service: Explicitly routes traffic to the targeted Foundry agent endpoint, bypassing potential portal settings synchronization mismatches.set-header (A2A-Version): Forces protocol version1.0. Omitting this forces default fallback to version0.3, which utilizes a legacy message payload structure.
Step 5: Testing End-to-End Routing with Postman
Retrieve an APIM Subscription Key under Subscriptions → Built-in all-access subscription → Show keys.
Request Configuration
- HTTP Method:
POST - URL:
https://api.yourcompany.com/agents/helper-agent - Headers:
Ocp-Apim-Subscription-Key:<YOUR_APIM_SUBSCRIPTION_KEY>Content-Type:application/json
Request Payload (A2A v1.0 JSON-RPC 2.0 Specification)
{
"jsonrpc": "2.0",
"id": "req-001",
"method": "SendMessage",
"params": {
"message": {
"messageId": "msg-001",
"role": "ROLE_USER",
"parts": [
{ "text": "What is the policy regarding annual leave allowance?" }
]
}
}
}
Expected Response (HTTP Status 200 OK)
{
"jsonrpc": "2.0",
"id": "req-001",
"result": {
"task": {
"id": "resp_task_99823",
"contextId": "ctxt_session_4412",
"status": {
"state": "TASK_STATE_COMPLETED",
"timestamp": "2026-09-06T04:18:09+00:00"
},
"artifacts": [
{
"artifactId": "msg_art_1102",
"parts": [
{
"text": "Employees are entitled to 25 days of paid annual leave per calendar year. Request approval via the HR portal."
}
]
}
]
}
}
}
Extract response text from result.task.artifacts[0].parts[0].text. The contextId should be preserved and passed in subsequent requests for stateful multi-turn dialogs.
Troubleshooting & Operational Diagnostics Matrix
| HTTP Status / Symptom | Root Cause | Remediation Procedure |
|---|---|---|
| 404 Resource Not Found | Incorrect HTTP Method or incorrect APIM base path | Ensure client method is explicitly POST (not GET). Verify APIM route matches /agents/helper-agent. |
| 401 Access Denied | Missing or invalid subscription key | Verify header key is exactly Ocp-Apim-Subscription-Key. |
401/403 (with azureml-served-by-cluster header) | RBAC propagation pending or incorrect role scope | Allow 5 minutes post-assignment. Confirm role was assigned at Foundry Project level, not Foundry Account level. |
| 405 Method Not Allowed | Client issued a GET to the runtime endpoint | Change client request method to POST. |
200 OK with "code": -32601 | JSON-RPC method signature mismatch | Ensure A2A-Version: 1.0 header is active in inbound policy. Method SendMessage applies to v1.0, whereas v0.3 uses message/send. |
Card discovery failure (agent-card.json 405) | APIM cannot proxy card GET requests without URI rewrite rules | Implement path rewrite policies or serve static card JSON documents directly from policy outbound mocks. |
Enterprise Integration & Multi-Model Scaling Strategy
While Azure API Management provides governance for native Microsoft AI Foundry agents, modern enterprise architectures often require hybrid LLM integrations. When combining custom A2A agents with third-party foundational models (e.g., Anthropic Claude 3.5 Sonnet, DeepSeek-V3, or OpenAI o3), maintaining separate gateways for each provider increases complexity.
Integrating centralized model routers such as n1n.ai alongside APIM allows organizations to maintain consistent API interfaces across cloud vendors while maintaining tight operational governance over custom agents.
Advanced Pattern: Converting A2A Endpoints to Model Context Protocol (MCP)
To expose A2A-wrapped agents as tools inside Model Context Protocol (MCP) clients:
- Configure a standard HTTP API in APIM targeting the agent OpenAI-compatible endpoint:
.../endpoint/protocols/openai/responses - Use APIM's native Expose as MCP server capability to convert API endpoints into schema-compliant MCP tools.
By leveraging structured gateways and robust routing layers like n1n.ai, engineering teams build resilient, scalable agent infrastructures ready for enterprise deployment.
Get a free API key at n1n.ai