Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Note
This article refers to the classic version of the agents API.
You can now connect your Azure AI Agent to an external API by using an OpenAPI 3.0 specified tool, enabling scalable interoperability with various applications. By using managed identities (Microsoft Entra ID) for authentication, you can securely enable your custom tools to authenticate access and connections. This approach is ideal for integrating with existing infrastructure or web services.
OpenAPI Specified tool improves your function calling experience by providing standardized, automated, and scalable API integrations that enhance the capabilities and efficiency of your agent. OpenAPI specifications provide a formal standard for describing HTTP APIs. This standard helps people understand how an API works, how a sequence of APIs works together, and it supports generating client code, creating tests, applying design standards, and more. Currently, the OpenAPI 3.0 specified tools support three authentication types: anonymous, API key, and managed identity.
Usage support
| Microsoft Foundry support | Python SDK | C# SDK | Java SDK | REST API | Basic agent setup | Standard agent setup |
|---|---|---|---|---|---|---|
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
Prerequisites
- Ensure you complete the prerequisites and setup steps in the quickstart.
- Check the OpenAPI spec for the following requirements:
- Although not required by the OpenAPI spec, each function must have an
operationIdto work with the OpenAPI tool. - The
operationIdshould only contain letters,-, and_. You can modify it to meet this requirement. Use a descriptive name to help models efficiently decide which function to use.
- Although not required by the OpenAPI spec, each function must have an
Authenticate with API key
By using API key authentication, you can authenticate your OpenAPI spec through different methods, such as an API key or Bearer token. Each OpenAPI spec supports only one API key security schema. If you need multiple security schemas, create multiple OpenAPI spec tools.
Update your OpenAPI spec security schemas. It has a
securitySchemessection and one scheme of typeapiKey. For example:"securitySchemes": { "apiKeyHeader": { "type": "apiKey", "name": "x-api-key", "in": "header" } }You usually only need to update the
namefield, which corresponds to the name ofkeyin the connection. If the security schemes include multiple schemes, keep only one of them.Update your OpenAPI spec to include a
securitysection:"security": [ { "apiKeyHeader": [] } ]Remove any parameter in the OpenAPI spec that needs API key, because the API key is stored and passed through a connection, as described later in this article.
Create a
custom keysconnection to store your API key.Go to the Microsoft Foundry portal and select Management center from the left navigation pane.
Select Connected resources under the AI project in the left navigation pane.
Select + new connection in the settings page.
Note
If you regenerate the API key at a later date, you need to update the connection with the new key.
Select custom keys in other resource types.
Enter the following information
key:
namefield of your security scheme. In this example, it should bex-api-key"securitySchemes": { "apiKeyHeader": { "type": "apiKey", "name": "x-api-key", "in": "header" } }value: YOUR_API_KEY
Connection name: YOUR_CONNECTION_NAME (You use this connection name in the sample code below.)
Access: you can choose either this project only or shared to all projects. Just make sure in the sample code below, the project you entered connection string for has access to this connection.
After you create a connection, use it through the SDK or REST API. Use the tabs at the top of this article to see code examples.
Authenticate with managed identity (Microsoft Entra ID)
Microsoft Entra ID is a cloud-based identity and access management service that your employees can use to access external resources. By using Microsoft Entra ID, you can add extra security when you authenticate your APIs without needing to use API keys. After you set up managed identity authentication, the Foundry Tool your agent uses handles the authentication.
When configuring managed identity authentication, you need to provide an Audience value. The audience is the OAuth2 resource identifier (also called scope or application ID URI) that identifies which API or service the managed identity can access.
Common audience values:
- Foundry Tools (formerly Azure AI services or Cognitive Services):
https://cognitiveservices.azure.com/ - Azure Resource Manager APIs:
https://management.azure.com/ - Microsoft Graph:
https://graph.microsoft.com/ - Custom APIs registered in Microsoft Entra ID: Use the Application ID URI found in the API's app registration
To set up authentication by using Managed Identity:
Make sure your Foundry resource has a system assigned managed identity enabled.
Create a resource for the service you want to connect to through OpenAPI spec.
Assign the proper access to the resource.
Select Access Control for your resource.
Select Add and then add role assignment at the top of the screen.
Select the proper role assignment needed. Usually, it requires at least the READER role. Then select Next.
Select Managed identity and then select select members.
In the managed identity dropdown menu, search for Foundry Tools and then select the Foundry Tool of your agent.
Select Finish.
After you complete the setup, you can use the tool through the Foundry portal, SDK, or REST API. Use the tabs at the top of this article to see code samples.