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/api-management/api-management-authenticate-authorize-ai-apis.md
+32-33Lines changed: 32 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,59 +1,59 @@
1
1
---
2
-
title: Authenticate to Azure OpenAI API - Azure API Management
2
+
title: Authenticate and Authorize to LLM APIs - Azure API Management
3
3
titleSuffix: Azure API Management
4
-
description: Options to authenticate and authorize to Azure OpenAI APIs using Azure API Management. Includes API key, managed identity, and OAuth 2.0 authorization.
4
+
description: Options to authenticate and authorize to LLM APIs using Azure API Management. Includes API key, managed identity, and OAuth 2.0 authorization.
5
5
author: dlepow
6
6
ms.service: azure-api-management
7
7
ms.topic: concept-article
8
-
ms.date: 04/01/2025
8
+
ms.date: 12/19/2025
9
9
ms.update-cycle: 180-days
10
10
ms.author: danlep
11
11
ms.collection: ce-skilling-ai-copilot
12
12
---
13
13
14
-
# Authenticate and authorize access to Azure OpenAI APIs using Azure API Management
14
+
# Authenticate and authorize access to LLM APIs by using Azure API Management
In this article, you learn about ways to authenticate and authorize to Azure OpenAI API endpoints that are managed using Azure API Management. This article shows the following common methods:
18
+
In this article, you learn how to authenticate and authorize access to AI API endpoints that Azure API Management manages. This article shows the following common methods:
19
19
20
-
***Authentication** - Authenticate to an Azure OpenAI API using policies that authenticate using either an API key or a Microsoft Entra ID managed identity.
20
+
***Authentication** - Authenticate to an AI API by using policies that use either an API key or a Microsoft Entra ID managed identity.
21
21
22
22
***Authorization** - For more fine-grained access control, preauthorize requests that pass OAuth 2.0 tokens generated by an identity provider such as Microsoft Entra ID.
23
23
24
24
For background, see:
25
25
26
-
*[Azure OpenAI Service REST API reference](/azure/ai-foundry/openai/reference)
27
-
28
26
*[Authentication and authorization to APIs in API Management](authentication-authorization-overview.md).
29
27
30
28
## Prerequisites
31
29
32
-
Before following the steps in this article, you must have:
30
+
To follow the examples in this article, you must have:
33
31
34
32
- An API Management instance. For example steps, see [Create an Azure API Management instance](get-started-create-service-instance.md).
35
-
- An Azure OpenAI resource and model added to your API Management instance. For example steps, see [Import an Azure OpenAI API as a REST API](azure-openai-api-from-specification.md).
36
-
- Permissions to create an app registration in an identity provider such as a Microsoft Entra tenant associated with your Azure subscription (for OAuth 2.0 authorization).
33
+
- An AI model deployment added to your API Management instance as an AI. For example steps, see [Import a Microsoft Foundry API](azure-ai-foundry-api.md) or [Import a language model API](openai-compatible-llm-api.md).
34
+
-(For OAuth 2.0 authorization) Permissions to create an app registration in an identity provider such as a Microsoft Entra ID tenant associated with your Azure subscription.
37
35
38
-
## Authenticate with API key
36
+
## Authenticate by using API key
39
37
40
-
A default way to authenticate to an Azure OpenAI API is by using an API key. For this type of authentication, all API requests must include a valid API key in the `api-key` HTTP header.
38
+
A default way to authenticate to an AI API is by using an API key. For this type of authentication, all API requests must include a valid API key in an HTTP header. The header name depends on the API. For example, Azure OpenAI in Microsoft Foundry APIs use the `api-key` header.
41
39
42
-
* API Management can manage the API key in a secure way, by using a [named value](api-management-howto-properties.md).
43
-
*The named value can then be referenced in an API policy to set the `api-key` header in requests to the Azure OpenAI API. We provide two examples of how to do this: one uses the [`set-backend-service`](set-backend-service-policy.md) policy, and the other uses the [`set-header`](set-header-policy.md) policy.
40
+
* API Management can manage the API key in a secure way by using a [named value](api-management-howto-properties.md).
41
+
*You can reference the named value in an API policy to set the `api-key` header in requests to the API. The following two examples show how to do this: one uses the [`set-backend-service`](set-backend-service-policy.md) policy, and the other uses the [`set-header`](set-header-policy.md) policy.
44
42
45
43
### Store the API key in a named value
46
44
47
-
1. Obtain an API key from the Azure OpenAI resource. In the Azure portal, find a key on the **Keys and Endpoint** page of the Azure OpenAI resource.
45
+
Here's an example of how to store an Azure OpenAI API key in a named value in API Management:
46
+
47
+
1. Get an API key from the AI model deployment. For an Azure OpenAI model deployment, find this information on the **Home** page for your project in the Microsoft Foundry portal.
48
48
1. Go to your API Management instance, and select **Named values** in the left menu.
49
-
1. Select **+ Add**, and add the value as a secret, or optionally for more security, use a [key vault reference](api-management-howto-properties.md#key-vault-secrets).
49
+
1. Select **+ Add**, and add the value as a secret. For more security, optionally use a [key vault reference](api-management-howto-properties.md#key-vault-secrets).
50
50
51
51
### Pass the API key in API requests - set-backend-service policy
52
52
53
53
1. Create a [backend](backends.md) that points to the Azure OpenAI API.
54
54
1. In the left menu of your API Management instance, select **Backends**.
55
55
1. Select **+ Add**, and enter a descriptive name for the backend. Example: *openai-backend*.
56
-
1. Under **Type**, select **Custom**, and enter the URL of the Azure OpenAI endpoint. Example: `https://contoso.openai.azure.com/openai`.
56
+
1. Under **Type**, select **Custom**, and enter the URL of the Azure OpenAI endpoint. Example: `https://contoso.services.ai.azure.com/openai`.
57
57
1. Under **Authorization credentials**, select **Headers**, and enter *api-key* as the header name and the named value as the value.
58
58
1. Select **Create**.
59
59
1. Add the following `set-backend-service` policy snippet in the `inbound` policy section to pass the API key in requests to the Azure OpenAI API.
@@ -76,19 +76,18 @@ In this example, the named value in API Management is *openai-api-key*.
76
76
</set-header>
77
77
```
78
78
79
-
80
79
## Authenticate with managed identity
81
80
82
-
An alternative and recommended way to authenticate to an Azure OpenAI API is by using a managed identity in Microsoft Entra ID. For background, see
83
-
[How to configure Azure OpenAI Service with managed identity](/azure/api-management/api-management-authenticate-authorize-azure-openai).
81
+
For Azure OpenAI and other model deployments in Microsoft Foundry, use a managed identity in Microsoft Entra ID to authenticate. For background, see
82
+
[How to configure Azure OpenAI in Microsoft Foundry Models with Microsoft Entra ID authentication](/azure/ai-foundry/openai/how-to/managed-identity).
84
83
85
-
Following are steps to configure your API Management instance to use a managed identity to authenticate requests to an Azure OpenAI API.
84
+
Follow these steps to configure your API Management instance to use a managed identity for authentication.
86
85
87
-
1.[Enable](api-management-howto-use-managed-service-identity.md) a system-assigned or user-assigned managed identity for your API Management instance. The following example assumes that you've enabled the instance's system-assigned managed identity.
86
+
1.[Enable](api-management-howto-use-managed-service-identity.md) a system-assigned or user-assigned managed identity for your API Management instance. The following example assumes that you enabled the instance's system-assigned managed identity.
88
87
89
-
1. Assign the managed identity the **Cognitive Services OpenAI User** role, scoped to the appropriate resource. For example, assign the system-assigned managed identity the **Cognitive Services OpenAI User** role on the Azure OpenAI resource. For detailed steps, see [Role-based access control for Azure OpenAI service](/azure/ai-foundry/openai/how-to/role-based-access-control).
88
+
1. Assign the managed identity the **Cognitive Services OpenAI User** role, scoped to the appropriate resource. For example, assign the system-assigned managed identity the **Cognitive Services OpenAI User** role on the Microsoft Foundry resource. For detailed steps, see [Role-based access control for Azure OpenAI service](/azure/ai-foundry/openai/how-to/role-based-access-control).
90
89
91
-
1. Add the following policy snippet in the `inbound` policy section to authenticate requests to the Azure OpenAI API using the managed identity.
90
+
1. Add the following policy snippet in the `inbound` policy section to authenticate requests to the API by using the managed identity.
92
91
93
92
In this example:
94
93
@@ -101,22 +100,22 @@ Following are steps to configure your API Management instance to use a managed i
> An alternative to using the `authentication-managed-identity` and `set-header` policies shown in this example is to configure a [backend](backends.md) resource that directs API requests to the Azure OpenAI Service endpoint. In the backend configuration, enable managed identity authentication to the Azure OpenAI Service. Azure API Management automates these steps when importing an API directly from Azure OpenAI Service. For more information, see [Import API from Azure OpenAI Service](azure-openai-api-from-specification.md#option-1-import-api-from-azure-openai).
105
+
> Instead of using the `authentication-managed-identity` and `set-header` policies shown in this example, you can configure a [backend](backends.md) resource that directs API requests to the AI service endpoint. In the backend configuration, configure managed identity credentials to the `https://cognitiveservices.azure.com/` resource. Azure API Management automates these steps when you [import an API directly from Microsoft Foundry](azure-ai-foundry-api.md).
107
106
108
-
## OAuth 2.0 authorization using identity provider
107
+
## OAuth 2.0 authorization by using identity provider
109
108
110
-
To enable more fine-grained access to OpenAPI APIs by particular users or clients, you can preauthorize access to the Azure OpenAI API using OAuth 2.0 authorization with Microsoft Entra ID or another identity provider. For background, see [Protect an API in Azure API Management using OAuth 2.0 authorization with Microsoft Entra ID](api-management-howto-protect-backend-with-aad.md).
109
+
To enable more fine-grained access to Azure OpenAPI or other LLM APIs by particular users or clients, preauthorize access to the API by using OAuth 2.0 authorization with Microsoft Entra ID or another identity provider. For background, see [Protect an API in Azure API Management using OAuth 2.0 authorization with Microsoft Entra ID](api-management-howto-protect-backend-with-aad.md).
111
110
112
111
> [!NOTE]
113
112
> Use OAuth 2.0 authorization as part of a defense-in-depth strategy. It's not a replacement for API key authentication or managed identity authentication to an Azure OpenAI API.
114
113
115
-
Following are high level steps to restrict API access to users or apps that are authorized using an identity provider.
114
+
The following steps show how to restrict API access to users or apps that are authorized by using an identity provider.
116
115
117
-
1. Create an application in your identity provider to represent the OpenAI API in Azure API Management. If you're using Microsoft Entra ID, [register](api-management-howto-protect-backend-with-aad.md#register-an-application-in-microsoft-entra-id-to-represent-the-api) an application in your Microsoft Entra ID tenant. Record details such as the application ID and the audience URI.
116
+
1. Create an application in your identity provider to represent the AI API in Azure API Management. If you're using Microsoft Entra ID, [register](api-management-howto-protect-backend-with-aad.md#register-an-application-in-microsoft-entra-id-to-represent-the-api) an application in your Microsoft Entra ID tenant. Record details such as the application ID and the audience URI.
118
117
119
-
As needed, configure the application to have roles or scopes that represent the fine-grained permissions needed to access the Azure OpenAI API.
118
+
As needed, configure the application to have roles or scopes that represent the fine-grained permissions needed to access the AI API.
120
119
121
120
1. Add an `inbound` policy snippet in your API Management instance to validate requests that present a JSON web token (JWT) in the `Authorization` header. Place this snippet *before* other `inbound` policies that you set to authenticate to the Azure OpenAI API.
122
121
@@ -164,4 +163,4 @@ Following are high level steps to restrict API access to users or apps that are
164
163
## Related content
165
164
166
165
* Learn more about [Microsoft Entra ID and OAuth2.0](/entra/architecture/auth-oauth2).
167
-
* [Authenticate requests to Azure AI services](/azure/ai-services/authentication)
166
+
* [Authenticate requests to Foundry tools](/azure/ai-services/authentication)
0 commit comments