An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
Hi @Sharma, Jyoti ,
Thanks for reaching out in Microsoft Q&A forum,
your Agentic Retrieval setup and the requirement to route all Azure OpenAI traffic through Azure API Management (APIM). From what you’ve described, your proof of concept worked when the Knowledge Base LLM was configured directly against the native Azure OpenAI/Foundry endpoint, but you now see 401 Unauthorized errors when the LLM ResourceUri is changed to an APIM endpoint. This behavior is consistent with a current product limitation rather than an RBAC or APIM policy misconfiguration.learn.microsoft+3
Why APIM fails for the Knowledge Base LLM?
In Azure AI Search, an Agentic Retrieval knowledge base is designed to call a supported Azure OpenAI or Foundry model endpoint directly using the search service’s managed identity and role assignment.learn.microsoft+2
- The knowledge base can be created successfully even when the LLM endpoint is set to APIM, because the create operation mainly validates configuration shape and does not fully exercise the LLM path.learn.microsoft+1
- During retrieval, answer synthesis, and low/medium reasoning effort, the service performs internal LLM calls as part of the agentic pipeline. These calls expect a native Azure OpenAI/Foundry endpoint and a supported auth model, not an APIM proxy.learn.microsoft+1
- APIM is not currently documented or supported as the endpoint for the LLM used by an Agentic Retrieval knowledge base, so changing APIM roles or policies alone is unlikely to resolve the 401 Unauthorized you are seeing. The supported configuration explicitly requires the Azure AI Search managed identity to have the Cognitive Services User role on the OpenAI/Foundry resource and call it directly.learn.microsoft+2
Given this limitation and your organization’s APIM requirement, the realistic options are:
- Request a policy exception for the managed service-to-service LLM call
- Allow the Azure AI Search managed identity to call the Azure OpenAI/Foundry resource directly, with the Cognitive Services User role and no API keys where appropriate.learn.microsoft+2
- Secure the OpenAI/Foundry resource using:
- managed identity and RBAC,
- private network access (Private Endpoint / VNet integration), and
- disabled key authentication if your security policy permits.learn.microsoft+1
- This approach keeps the internal LLM traffic within a tightly controlled perimeter while preserving built‑in Agentic Retrieval behavior (query planning, answer synthesis, low/medium reasoning).learn.microsoft+1
- Use the knowledge base without its LLM and generate answers in your application through APIM
- Configure retrieval reasoning effort to
minimal, which explicitly disables LLM-based query planning and processing. In this mode, the knowledge base issues direct text and vector searches against your knowledge sources and returns extractive results only.docs.azure - Your application can then:
- call the knowledge base retrieve API (or standard AI Search queries) to get the relevant documents/snippets, and
- call Azure OpenAI through APIM to perform answer generation using those retrieved results as context.
- This pattern fully preserves the APIM requirement for all model calls, but you won’t have built‑in query planning or answer synthesis inside the knowledge base; all reasoning and generation are handled in your app.
- Configure retrieval reasoning effort to
Kindly let us know if the above helps or you need further assistance on this issue.
Please do not forget to
and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.