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/amazon-bedrock-passthrough-llm-api.md
+22-33Lines changed: 22 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ms.service: azure-api-management
5
5
author: dlepow
6
6
ms.author: danlep
7
7
ms.topic: how-to
8
-
ms.date: 07/06/2025
8
+
ms.date: 07/07/2025
9
9
ms.update-cycle: 180-days
10
10
ms.collection: ce-skilling-ai-copilot
11
11
ms.custom: template-how-to, build-2024
@@ -32,17 +32,6 @@ Learn more about Amazon Bedrock:
32
32
- An existing API Management instance. [Create one if you haven't already](get-started-create-service-instance.md).
33
33
- An Amazon Web Services (AWS) account with access to Amazon Bedrock, and access to one or more Amazon Bedrock foundation models. [Learn more](https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started-console.html)
34
34
35
-
36
-
<!--
37
-
Outline from Andrei:
38
-
1) Passtrough API (not auth configuration, even URL is not used, but should be setup in the UI anyway)
39
-
2) Named values for aws access key and secret key
40
-
41
-
3) policy for signing on API level that uses secret and access keys
42
-
43
-
4) do a couple of modification to the code (.NET SDK sample Ethan also shared in the same threaed)
44
-
-->
45
-
46
35
## Create IAM user access keys
47
36
48
37
To authenticate your API Management instance to Amazon API Gateway, you need access keys for an AWS IAM user.
@@ -64,9 +53,9 @@ Securely store the two IAM user access keys as secret [named values](api-managem
64
53
| Access key |*accesskey*| Access key ID retrieved from AWS |
## Import a passthrough language model API using the portal
56
+
## Import a Bedrock API using the portal
68
57
69
-
To import an Amazon Bedrock language model API to API Management:
58
+
To import an Amazon Bedrock API to API Management:
70
59
71
60
1. In the [Azure portal](https://portal.azure.com), navigate to your API Management instance.
72
61
1. In the left menu, under **APIs**, select **APIs** > **+ Add API**.
@@ -84,7 +73,7 @@ To import an Amazon Bedrock language model API to API Management:
84
73
1. In **Type**, select **Create a passthrough API**.
85
74
1. Leave values in **Access key** blank.
86
75
87
-
:::image type="content" source="media/openai-compatible-llm-api/configure-api.png" alt-text="Screenshot of language model API configuration in the portal.":::
76
+
:::image type="content" source="media/amazon-bedrock-passthrough-llm-api/configure-api.png" alt-text="Screenshot of language model API configuration in the portal.":::
88
77
89
78
1. On the remaining tabs, optionally configure policies to manage token consumption, semantic caching, and AI content safety. For details, see [Import an OpenAI-compatible language model API](openai-compatible-llm-api.md).
90
79
1. Select **Review**.
@@ -94,9 +83,9 @@ API Management creates the API and (optionally) policies to help you monitor and
94
83
95
84
## Configure policies to authenticate requests to the Amazon Bedrock API
96
85
97
-
Configure API Management policies to sign requests to the Amazon Bedrock API. [Learn more about signing AWS API requests](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html).
86
+
Configure API Management policies to sign requests to the Amazon Bedrock API. [Learn more about signing AWS API requests](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html)
98
87
99
-
The following example uses the *accesskey* and *secretkey* named values you created earlier for the AWS access key and secret key. Set the `region` variable to the appropriate values for your Amazon Bedrock API. The example uses `us-east-1` for the region.
88
+
The following example uses the *accesskey* and *secretkey* named values you created previously for the AWS access key and secret key. Set the `region` variable to the appropriate value for your Amazon Bedrock API. The example uses `us-east-1` for the region.
100
89
101
90
1. In the [Azure portal](https://portal.azure.com), navigate to your API Management instance.
102
91
1. In the left menu, under **APIs**, select **APIs**.
@@ -135,7 +124,7 @@ The following example uses the *accesskey* and *secretkey* named values you crea
135
124
var uri = context.Request.Url;
136
125
var host = uri.Host;
137
126
138
-
// create canonical path
127
+
// Create canonical path
139
128
var path = uri.Path;
140
129
var modelSplit = path.Split(new[] { "model/" }, 2, StringSplitOptions.None);
141
130
var afterModel = modelSplit.Length > 1 ? modelSplit[1] : "";
@@ -147,7 +136,7 @@ The following example uses the *accesskey* and *secretkey* named values you crea
147
136
var amzDate = ((DateTime)context.Variables["now"]).ToString("yyyyMMddTHHmmssZ");
148
137
var dateStamp = ((DateTime)context.Variables["now"]).ToString("yyyyMMdd");
149
138
150
-
// hash the payload
139
+
// Hash the payload
151
140
var body = context.Request.Body.As<string>(preserveContent: true);
152
141
string hashedPayload;
153
142
using (var sha256 = System.Security.Cryptography.SHA256.Create())
@@ -156,7 +145,7 @@ The following example uses the *accesskey* and *secretkey* named values you crea
using (var hmac = new System.Security.Cryptography.HMACSHA256(kSigning))
246
235
{
247
236
var sigBytes = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(stringToSign));
@@ -268,11 +257,11 @@ The following example uses the *accesskey* and *secretkey* named values you crea
268
257
```
269
258
270
259
271
-
## Call the LLM API
260
+
## Call the Bedrock API
272
261
273
-
To call the LLM API through API Management, you can use the AWS Bedrock SDK. This example uses the .NET SDK, but you can use any language that supports the AWS Bedrock API.
262
+
To call the Bedrock API through API Management, you can use the AWS Bedrock SDK. This example uses the .NET SDK, but you can use any language that supports the AWS Bedrock API.
274
263
275
-
The following example uses a custom HTTP client that instantiates classes defined in the accompanying file `BedrockHttpClientFactory.cs`. The custom HTTP client routes requests to the API Management endpoint and includes the API Management subscription key in the request headers.
264
+
The following example uses a custom HTTP client that instantiates classes defined in the accompanying file `BedrockHttpClientFactory.cs`. The custom HTTP client routes requests to the API Management endpoint and includes the API Management subscription key (if necessary) in the request headers.
276
265
277
266
```csharp
278
267
using Amazon;
@@ -281,9 +270,9 @@ using Amazon.BedrockRuntime.Model;
281
270
using Amazon.Runtime;
282
271
using BedrockClient;
283
272
284
-
// Replace with your AWS access key and secret key.
285
-
var accessKey = "<your-access-key>";
286
-
var secretKey = "<your-secret-key>";
273
+
// Leave accessKey and secretKey values as empty strings.
274
+
var accessKey = "";
275
+
var secretKey = "";
287
276
var credentials = new BasicAWSCredentials(accessKey, secretKey);
288
277
289
278
// Create custom configuration to route requests through API Management
The following code implements classes to create a custom HTTP client that routes requests to the Bedrock API through API Management, including the necessary subscription key in the headers.
337
+
The following code implements classes to create a custom HTTP client that routes requests to the Bedrock API through API Management, including an API Management subscription key in the headers.
0 commit comments