Skip to content

Commit 30be1bf

Browse files
author
Jill Grant
authored
Merge pull request #2174 from eric-urban/eur/aoai-api-key
retrieve resource info for JS and TS
2 parents 910ada7 + 3b55658 commit 30be1bf

26 files changed

+191
-466
lines changed

articles/ai-services/openai/includes/assistants-env-var-key.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

articles/ai-services/openai/includes/assistants-env-var-without-key.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

articles/ai-services/openai/includes/assistants-javascript.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ ms.custom: passwordless-ts, devex-track-js
2222
- We recommend reviewing the [Responsible AI transparency note](/legal/cognitive-services/openai/transparency-note?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext&tabs=text) and other [Responsible AI resources](/legal/cognitive-services/openai/overview?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext) to familiarize yourself with the capabilities and limitations of the Azure OpenAI Service.
2323
- An Azure OpenAI resource with the `gpt-4 (1106-preview)` model deployed was used testing this example.
2424

25-
## Microsoft Entra ID authentication is recommended
25+
### Microsoft Entra ID prerequisites
2626

27-
For _keyless_ authentication, you need to
28-
29-
1. Use the `@azure/identity` package.
30-
1. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal under **Access control (IAM)** > **Add role assignment**.
31-
1. Sign in with the Azure CLI such as `az login`.
27+
For the recommended keyless authentication with Microsoft Entra ID, you need to:
28+
- Install the [Azure CLI](/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
29+
- Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.
3230

3331
## Set up
3432

@@ -64,18 +62,10 @@ For _keyless_ authentication, you need to
6462
npm install @azure/identity
6563
```
6664

67-
## Retrieve resource information
68-
69-
#### [Microsoft Entra ID](#tab/javascript-keyless)
70-
71-
[!INCLUDE [assistants-keyless-environment-variables](assistants-env-var-without-key.md)]
7265

66+
## Retrieve resource information
7367

74-
#### [API key](#tab/javascript-key)
75-
76-
[!INCLUDE [assistants-key-environment-variables](assistants-env-var-key.md)]
77-
78-
---
68+
[!INCLUDE [resource authentication](resource-auth.md)]
7969

8070
> [!CAUTION]
8171
> To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
@@ -98,7 +88,7 @@ An individual assistant can access up to 128 tools including `code interpreter`,
9888

9989
## Create a new JavaScript application
10090

101-
#### [Microsoft Entra ID](#tab/javascript-keyless)
91+
#### [Microsoft Entra ID](#tab/keyless)
10292

10393
1. Create the `index.js` file with the following code:
10494

@@ -205,7 +195,7 @@ An individual assistant can access up to 128 tools including `code interpreter`,
205195
206196
207197
208-
#### [API key](#tab/javascript-key)
198+
#### [API key](#tab/api-key)
209199
210200
1. Create the `index.js` file with the following code:
211201

articles/ai-services/openai/includes/assistants-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ms.date: 05/22/2024
2424

2525
## Passwordless authentication is recommended
2626

27-
For passwordless authentication, you need to
27+
For passwordless authentication, you need to:
2828

2929
1. Use the [azure-identity](https://pypi.org/project/azure-identity/) package.
3030
2. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal under **Access control (IAM)** > **Add role assignment**.

articles/ai-services/openai/includes/assistants-typescript.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ ms.custom: passwordless-js, devex-track-typescript
2323
- We recommend reviewing the [Responsible AI transparency note](/legal/cognitive-services/openai/transparency-note?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext&tabs=text) and other [Responsible AI resources](/legal/cognitive-services/openai/overview?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext) to familiarize yourself with the capabilities and limitations of the Azure OpenAI Service.
2424
- An Azure OpenAI resource with the `gpt-4 (1106-preview)` model deployed was used testing this example.
2525

26-
## Passwordless authentication is recommended
26+
### Microsoft Entra ID prerequisites
2727

28-
For passwordless authentication, you need to
29-
30-
1. Use the `@azure/identity` package.
31-
1. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal under **Access control (IAM)** > **Add role assignment**.
32-
1. Sign in with the Azure CLI such as `az login`.
28+
For the recommended keyless authentication with Microsoft Entra ID, you need to:
29+
- Install the [Azure CLI](/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
30+
- Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.
3331

3432
## Set up
3533

@@ -67,22 +65,11 @@ For passwordless authentication, you need to
6765

6866
## Retrieve resource information
6967

70-
71-
#### [Microsoft Entra ID](#tab/typescript-keyless)
72-
73-
[!INCLUDE [assistants-keyless-environment-variables](assistants-env-var-without-key.md)]
74-
75-
76-
#### [API key](#tab/typescript-key)
77-
78-
[!INCLUDE [assistants-key-environment-variables](assistants-env-var-key.md)]
79-
80-
---
68+
[!INCLUDE [resource authentication](resource-auth.md)]
8169

8270
> [!CAUTION]
8371
> To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
8472
85-
8673
## Create an assistant
8774
8875
In our code we're going to specify the following values:

articles/ai-services/openai/includes/chatgpt-javascript.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ms.date: 10/22
1414
[Source code](https://github.com/openai/openai-node) | [Package (npm)](https://www.npmjs.com/package/openai) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples)
1515

1616
> [!NOTE]
17-
> This article has been updated to use the [latest OpenAI npm package](https://www.npmjs.com/package/openai) which now fully supports Azure OpenAI. If you are looking for code examples for the legacy Azure OpenAI JavaScript SDK they are currently still [available in this repo](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples/v2-beta/javascript).
17+
> This guide uses the [latest OpenAI npm package](https://www.npmjs.com/package/openai) which now fully supports Azure OpenAI. If you're looking for code examples for the legacy Azure OpenAI JavaScript SDK, they're currently still [available in this repo](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples/v2-beta/javascript).
1818
1919
## Prerequisites
2020

@@ -23,12 +23,19 @@ ms.date: 10/22
2323
- [Azure CLI](/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
2424
- An Azure OpenAI Service resource with either a `gpt-35-turbo` or `gpt-4` series models deployed. For more information about model deployment, see the [resource deployment guide](../how-to/create-resource.md).
2525

26+
### Microsoft Entra ID prerequisites
2627

27-
## Set up
28+
For the recommended keyless authentication with Microsoft Entra ID, you need to:
29+
- Install the [Azure CLI](/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
30+
- Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.
2831

29-
[!INCLUDE [get-key-endpoint](get-key-endpoint.md)]
32+
## Retrieve resource information
33+
34+
[!INCLUDE [resource authentication](resource-auth.md)]
35+
36+
> [!CAUTION]
37+
> To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
3038
31-
[!INCLUDE [environment-variables](environment-variables.md)]
3239

3340
## Create a Node application
3441

@@ -42,7 +49,7 @@ Install the required packages for JavaScript with npm from within the context of
4249
npm install openai @azure/identity
4350
```
4451

45-
Your app's _package.json_ file will be updated with the dependencies.
52+
Your app's _package.json_ file is updated with the dependencies.
4653

4754
## Create a sample application
4855

@@ -158,7 +165,7 @@ node.exe ChatCompletion.js
158165
---
159166

160167
> [!NOTE]
161-
> If your receive the error: *Error occurred: OpenAIError: The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.* You may need to remove a pre-existing environment variable for the API key from your system. Even though the Microsoft Entra ID code sample is not explicitly referencing the API key environment variable, if one is present on the system executing this sample, this error will still be generated.
168+
> If your receive the error: *Error occurred: OpenAIError: The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.* You might need to remove a preexisting environment variable for the API key from your system. Even though the Microsoft Entra ID code sample isn't explicitly referencing the API key environment variable, if one is present on the system executing this sample, this error is still generated.
162169
163170

164171
## Clean up resources

articles/ai-services/openai/includes/chatgpt-typescript.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,28 @@ ms.date: 10/22
1414
[Source code](https://github.com/openai/openai-node) | [Package (npm)](https://www.npmjs.com/package/openai) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples)
1515

1616
> [!NOTE]
17-
> This article has been updated to use the [latest OpenAI npm package](https://www.npmjs.com/package/openai) which now fully supports Azure OpenAI. If you are looking for code examples for the legacy Azure OpenAI JavaScript SDK they are currently still [available in this repo](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples/v2-beta/javascript).
17+
> This guide uses the [latest OpenAI npm package](https://www.npmjs.com/package/openai) which now fully supports Azure OpenAI. If you're looking for code examples for the legacy Azure OpenAI JavaScript SDK, they're currently still [available in this repo](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples/v2-beta/javascript).
1818
1919
## Prerequisites
2020

21-
2221
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2322
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
2423
- [TypeScript](https://www.typescriptlang.org/download/)
2524
- [Azure CLI](/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
2625
- An Azure OpenAI Service resource with a `gpt-35-turbo` or `gpt-4` series models deployed. For more information about model deployment, see the [resource deployment guide](../how-to/create-resource.md).
2726

27+
### Microsoft Entra ID prerequisites
2828

29+
For the recommended keyless authentication with Microsoft Entra ID, you need to:
30+
- Install the [Azure CLI](/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
31+
- Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.
2932

30-
## Set up
33+
## Retrieve resource information
3134

32-
[!INCLUDE [get-key-endpoint](get-key-endpoint.md)]
35+
[!INCLUDE [resource authentication](resource-auth.md)]
3336

34-
[!INCLUDE [environment-variables](environment-variables.md)]
37+
> [!CAUTION]
38+
> To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
3539
3640
## Create a Node application
3741

@@ -45,7 +49,7 @@ Install the required packages for JavaScript with npm from within the context of
4549
npm install openai @azure/identity
4650
```
4751

48-
Your app's _package.json_ file will be updated with the dependencies.
52+
Your app's _package.json_ file is updated with the dependencies.
4953

5054

5155
## Create a sample application
@@ -219,7 +223,7 @@ node.exe ChatCompletion.js
219223
---
220224

221225
> [!NOTE]
222-
> If your receive the error: *Error occurred: OpenAIError: The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.* You may need to remove a pre-existing environment variable for the API key from your system. Even though the Microsoft Entra ID code sample is not explicitly referencing the API key environment variable, if one is present on the system executing this sample, this error will still be generated.
226+
> If your receive the error: *Error occurred: OpenAIError: The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.* You might need to remove a preexisting environment variable for the API key from your system. Even though the Microsoft Entra ID code sample isn't explicitly referencing the API key environment variable, if one is present on the system executing this sample, this error is still generated.
223227
224228

225229
## Clean up resources

articles/ai-services/openai/includes/dall-e-javascript.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ Use this guide to get started generating images with the Azure OpenAI SDK for Ja
1717

1818
## Prerequisites
1919

20-
2120
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2221
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
2322
- [Azure CLI](/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
2423
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
2524

25+
### Microsoft Entra ID prerequisites
2626

27-
## Setup
27+
For the recommended keyless authentication with Microsoft Entra ID, you need to:
28+
- Install the [Azure CLI](/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
29+
- Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.
2830

29-
[!INCLUDE [get-key-endpoint](get-key-endpoint.md)]
31+
## Retrieve resource information
3032

31-
[!INCLUDE [environment-variables](environment-variables.md)]
33+
[!INCLUDE [resource authentication](resource-auth.md)]
3234

35+
> [!CAUTION]
36+
> To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
3337
3438
## Create a Node application
3539

articles/ai-services/openai/includes/dall-e-typescript.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@ Use this guide to get started generating images with the Azure OpenAI SDK for Ja
1717

1818
## Prerequisites
1919

20-
2120
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
2221
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
2322
- [TypeScript](https://www.typescriptlang.org/download/)
2423
- [Azure CLI](/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
2524
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
2625

26+
### Microsoft Entra ID prerequisites
2727

28+
For the recommended keyless authentication with Microsoft Entra ID, you need to:
29+
- Install the [Azure CLI](/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
30+
- Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.
2831

29-
## Setup
30-
31-
[!INCLUDE [get-key-endpoint](get-key-endpoint.md)]
32+
## Retrieve resource information
3233

33-
[!INCLUDE [environment-variables](environment-variables.md)]
34+
[!INCLUDE [resource authentication](resource-auth.md)]
3435

36+
> [!CAUTION]
37+
> To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
3538
3639
## Create a Node application
3740

articles/ai-services/openai/includes/env-var-without-key.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)