You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-services/agents/how-to/tools/openapi-spec.md
+58-13Lines changed: 58 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ services: cognitive-services
6
6
manager: nitinme
7
7
ms.service: azure-ai-agent-service
8
8
ms.topic: how-to
9
-
ms.date: 12/16/2024
9
+
ms.date: 03/12/2025
10
10
author: aahill
11
11
ms.author: aahi
12
12
zone_pivot_groups: selection-function-calling
@@ -25,7 +25,7 @@ OpenAPI Specified tool improves your function calling experience by providing st
25
25
automated, and scalable API integrations that enhance the capabilities and efficiency of your agent.
26
26
[OpenAPI specifications](https://spec.openapis.org/oas/latest.html) provide a formal standard for
27
27
describing HTTP APIs. This allows people to understand how an API works, how a sequence of APIs
28
-
work together, generate client code, create tests, apply design standards, and more. Currently, we support 3 authentication types with the OpenAPI 3.0 specified tools: `anonymous`, `API key`, `managed identity`.
28
+
work together, generate client code, create tests, apply design standards, and more. Currently, we support three authentication types with the OpenAPI 3.0 specified tools: `anonymous`, `API key`, `managed identity`.
29
29
30
30
### Usage support
31
31
@@ -42,17 +42,30 @@ work together, generate client code, create tests, apply design standards, and m
42
42
43
43
## Authenticating with API Key
44
44
45
-
1. Verify that the OpenAPI spec supports API keys: it has `securitySchemes` section and has one scheme of type `apiKey`. For example:
45
+
With API key authentication, you can authenticate your OpenAPI spec using various methods such as an API key or Bearer token. Only one API key security schema is supported per OpenAPI spec. If you need multiple security schemas, create multiple OpenAPI spec tools.
46
+
47
+
1. Update your OpenAPI spec security schemas. it has a `securitySchemes` section and one scheme of type `apiKey`. For example:
48
+
46
49
```json
47
-
"securitySchemes": {
48
-
"apiKeyHeader": {
49
-
"type": "apiKey",
50
-
"name": "x-api-key",
51
-
"in": "header"
52
-
}
53
-
}
50
+
"securitySchemes": {
51
+
"apiKeyHeader": {
52
+
"type": "apiKey",
53
+
"name": "x-api-key",
54
+
"in": "header"
55
+
}
56
+
}
57
+
```
58
+
59
+
You usually only need to update the `name` field, which corresponds to the name of `key` in the connection. If the security schemes include multiple schemes, we recommend keeping only one of them.
60
+
61
+
1. Update your OpenAPI spec to include a `security` section:
62
+
```json
63
+
"security": [
64
+
{
65
+
"apiKeyHeader": []
66
+
}
67
+
]
54
68
```
55
-
If the security schemes include multiple schemes, we recommend keeping only one of them.
56
69
57
70
1. Remove any parameter in the OpenAPI spec that needs API key, because API key will be stored and passed through a connection, as described later in this article.
58
71
@@ -72,7 +85,7 @@ work together, generate client code, create tests, apply design standards, and m
72
85
:::image type="content" source="../../media/tools/bing/api-key-connection.png" alt-text="A screenshot of the custom keys selection for the AI project." lightbox="../../media/tools/bing/api-key-connection.png":::
73
86
74
87
1. Enter the following information
75
-
- key: `name` of your security scheme. In this example, it should be `x-api-key`
88
+
- key: `name`field of your security scheme. In this example, it should be `x-api-key`
76
89
```json
77
90
"securitySchemes": {
78
91
"apiKeyHeader": {
@@ -85,9 +98,41 @@ work together, generate client code, create tests, apply design standards, and m
85
98
- value: YOUR_API_KEY
86
99
- Connection name: YOUR_CONNECTION_NAME (You will use this connection name in the sample code below.)
87
100
- 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.
88
-
101
+
102
+
1. Once you have created a connection, you can use it through the SDK or REST API. Use the tabs at the top of this article to see code examples.
103
+
104
+
## Authenticating with managed identity (Microsoft Entra ID)
105
+
106
+
[Microsoft Entra ID](/entra/fundamentals/whatis) is a cloud-based identity and access management service that your employees can use to access external resources. Microsoft Entra ID allows you to authenticate your APIs with additional security without the need to pass in API keys. Once you have set up managed identity authentication, it will authenticate through the Azure AI Service your agent is using.
107
+
108
+
To set up authenticating with Managed Identity:
109
+
110
+
1. Enable the Azure AI Service of your agent has `system assigned managed identity` enabled.
111
+
112
+
:::image type="content" source="../../media/tools/managed-identity-portal.png" alt-text="A screenshot showing the managed identity selector in the Azure portal." lightbox="../../media/tools/managed-identity-portal.png":::
113
+
114
+
1. Create a resource of the service you want to connect to through OpenAPI spec.
115
+
116
+
1. Assign proper access to the resource.
117
+
1. Click **Access Control** for your resource
118
+
119
+
1. Click **Add** and then **add role assignment** at the top of the screen.
120
+
121
+
:::image type="content" source="../../media/tools/role-assignment-portal.png" alt-text="A screenshot showing the role assignment selector in the Azure portal." lightbox="../../media/tools/role-assignment-portal.png":::
122
+
123
+
1. Select the proper role assignment needed, usually it will require at least *READER* role. Then click **Next**.
124
+
125
+
1. Select **Managed identity** and then click **select members**.
126
+
127
+
1. In the managed identity dropdown menu, search for **Azure AI services** and then select the AI Service of your agent.
128
+
129
+
1. Click **Finish**.
130
+
131
+
1. Once the setup is done, you can continue by using the tool through the SDK or REST API. Use the tabs at the top of this article to see code samples.
132
+
89
133
::: zone-end
90
134
135
+
91
136
::: zone pivot="code-example"
92
137
## Step 1: Create a project client
93
138
Create a client object, which will contain the connection string for connecting to your AI project and other resources.
0 commit comments