Skip to content

Commit 7097832

Browse files
authored
Merge pull request #249692 from mgreenegit/aiservice-powershell-0
add powershell to quickstarts
2 parents 7d0622a + ec191e7 commit 7097832

13 files changed

+800
-9
lines changed

articles/ai-services/authentication.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ title: Authentication in Azure AI services
33
titleSuffix: Azure AI services
44
description: "There are three ways to authenticate a request to an Azure AI services resource: a resource key, a bearer token, or a multi-service subscription. In this article, you'll learn about each method, and how to make a request."
55
services: cognitive-services
6-
author: PatrickFarley
6+
author: mgreenegit
77
manager: nitinme
88
ms.service: cognitive-services
99
ms.custom: devx-track-azurepowershell
1010
ms.topic: how-to
11-
ms.date: 09/01/2022
12-
ms.author: pafarley
11+
ms.date: 08/30/2023
12+
ms.author: migreene
1313
---
1414

1515
# Authenticate requests to Azure AI services

articles/ai-services/includes/quickstarts/environment-variables.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,39 @@ ms.author: aahi
88

99
## Configure an environment variable for authentication
1010

11-
Your application must be authenticated to access Azure AI services resources. For production, use a secure way of storing and accessing your credentials. For example, after you have a key for your resource, write it to a new environment variable on the local machine running the application.
11+
Your application must be authenticated to access Azure AI services resources. To set the environment variable for your resource key, open a console window, and follow the instructions for your operating system and development environment. To set the `COGNITIVE_SERVICE_KEY` environment variable, replace `your-key` with one of the keys for your resource.
12+
13+
For production, use a secure way of storing and accessing your credentials, such as a password-protected secret vault. For test, writing to an environment variable is standard practice, but keep in mind that environment variables are stored in clear text on the local machine.
1214

1315
> [!TIP]
1416
> Don't include the key directly in your code, and never post it publicly. See the Azure AI services [security](../../security-features.md) article for more authentication options like [Azure Key Vault](../../use-key-vault.md).
1517
16-
To set the environment variable for your resource key, open a console window, and follow the instructions for your operating system and development environment. To set the `COGNITIVE_SERVICE_KEY` environment variable, replace `your-key` with one of the keys for your resource.
18+
1719

1820
#### [Windows](#tab/windows)
1921

22+
PowerShell includes an extensible solution,
23+
[Secret Management](/powershell/module/microsoft.powershell.secretmanagement),
24+
for storing secure strings in platforms such as [Secret Store](/powershell/module/microsoft.powershell.secretstore) or [Azure KeyVault](/powershell/utility-modules/secretmanagement/how-to/using-azure-keyvault).
25+
26+
To set up a secret store to host secure strings, see the article
27+
[Getting started using secret store](/powershell/utility-modules/secretmanagement/get-started/using-secretstore). Then use the following examples to store your api keys.
28+
29+
```powershell
30+
Set-Secret -Name COGNITIVE_SERVICE_KEY -value your-key
31+
```
32+
33+
For test environments, you can either use PowerShell's `$Env:` syntax to set an environment variable for only the current session, or the `setx` command to retain the variable across sessions. Remember that these values are stored in clear text in Windows registry keys.
34+
35+
```powershell
36+
$Env:COGNITIVE_SERVICE_KEY = your-key
37+
```
38+
2039
```console
2140
setx COGNITIVE_SERVICE_KEY your-key
2241
```
2342

24-
> [!NOTE]
25-
> If you only need to access the environment variable in the current running console, you can set the environment variable with `set` instead of `setx`.
26-
27-
After you add the environment variable, you may need to restart any running consoles or other programs that will need to read the environment variable. For example, if you are using Visual Studio as your editor, restart Visual Studio before running the example.
43+
After you add the environment variable using `setx`, you may need to restart any running consoles or other programs that will need to read the environment variable. For example, if you are using Visual Studio as your editor, restart Visual Studio before running the example.
2844

2945
#### [Linux](#tab/linux)
3046

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
title: Create an Azure AI services resource using Azure PowerShell
3+
titleSuffix: Azure AI services
4+
description: Get started with Azure AI services by using Azure PowerShell commands to create and subscribe to a resource.
5+
services: cognitive-services
6+
author: mgreenegit
7+
manager: nitinme
8+
ms.service: cognitive-services
9+
keywords: Azure AI services, cognitive intelligence, cognitive solutions, ai services
10+
ms.topic: include
11+
ms.date: 08/29/2022
12+
ms.author: migreene
13+
ms.custom: mode-api, devx-track-azurepowershell
14+
ms.devlang: azurepowershell
15+
---
16+
17+
Use this quickstart to create an Azure AI services resource using [Azure PowerShell](/powershell/azure/install-azure-powershell) commands. After you create the resource, use the keys and endpoint generated for you to authenticate your applications.
18+
19+
Azure AI services are cloud-based artificial intelligence (AI) services that help developers build cognitive intelligence into applications without having direct AI or data science skills or knowledge. They are available through REST APIs and client library SDKs in popular development languages. Azure AI services enables developers to easily add cognitive features into their applications with cognitive solutions that can see, hear, speak, and analyze.
20+
21+
## Prerequisites
22+
23+
* A valid Azure subscription - [Create one](https://azure.microsoft.com/free/cognitive-services) for free.
24+
* [Azure PowerShell](/powershell/azure/install-azure-powershell)
25+
* [!INCLUDE [contributor-requirement](contributor-requirement.md)]
26+
* [!INCLUDE [terms-azure-portal](terms-azure-portal.md)]
27+
28+
## Install Azure PowerShell and sign in
29+
30+
Install [Azure PowerShell](/powershell/azure/install-azure-powershell). To sign in, run the [Connect-AzAccount](/powershell/module/az.accounts/connect-azaccount) command:
31+
32+
```azurepowershell
33+
Connect-AzAccount
34+
```
35+
36+
You can also use the green **Try It** button to run these commands in your browser.
37+
38+
## Create a new Azure AI services resource group
39+
40+
Before you create an Azure AI services resource, you must have an Azure resource group to contain the resource. When you create a new resource, you can either create a new resource group, or use an existing one. This article shows how to create a new resource group.
41+
42+
### Choose your resource group location
43+
44+
To create a resource, you'll need one of the Azure locations available for your subscription. You can retrieve a list of available locations with the [Get-AzLocation](/powershell/module/az.resources/get-azlocation) command. Most Azure AI services can be accessed from several locations. Choose the one closest to you, or see which locations are available for the service.
45+
46+
> [!IMPORTANT]
47+
> * Remember your Azure location, as you will need it when calling the Azure AI services resources.
48+
> * The availability of some Azure AI services can vary by region. For more information, see [Azure products by region](https://azure.microsoft.com/global-infrastructure/services/?products=cognitive-services).
49+
50+
```azurepowershell-interactive
51+
Get-AzLocation | Select-Object -Property Location, DisplayName
52+
```
53+
54+
After you have your Azure location, create a new resource group in Azure PowerShell using the [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup) command. In the example below, replace the Azure location `westus2` with one of the Azure locations available for your subscription.
55+
56+
```azurepowershell-interactive
57+
New-AzResourceGroup -Name ai-services-resource-group -Location westus2
58+
```
59+
60+
## Create an Azure AI services resource
61+
62+
### Choose a service and pricing tier
63+
64+
When you create a new resource, you'll need to know the kind of service you want to use, along with the [pricing tier](https://azure.microsoft.com/pricing/details/cognitive-services/) (or SKU) you want. You'll use this and other information as parameters when you create the resource.
65+
66+
[!INCLUDE [SKUs and pricing](sku-pricing.md)]
67+
68+
You can find a list of available Azure AI services "kinds" with the [Get-AzCognitiveServicesAccountType](/powershell/module/az.cognitiveservices/get-azcognitiveservicesaccounttype) command:
69+
70+
```azurepowershell-interactive
71+
Get-AzCognitiveServicesAccountType
72+
```
73+
74+
### Add a new resource to your resource group
75+
76+
To create and subscribe to a new Azure AI services resource, use the [New-AzCognitiveServicesAccount](/powershell/module/az.cognitiveservices/new-azcognitiveservicesaccount) command. This command adds a new billable resource to the resource group you created earlier. When you create your new resource, you'll need to know the "kind" of service you want to use, along with its pricing tier (or SKU) and an Azure location:
77+
78+
You can create a Standard S0 multi-service resource named `multi-service-resource` with the command below.
79+
80+
```azurepowershell-interactive
81+
New-AzCognitiveServicesAccount -ResourceGroupName ai-services-resource-group -Name multi-service-resource -Type CognitiveServices -SkuName F0 -Location westus2
82+
```
83+
84+
> [!Tip]
85+
> If your subscription doesn't allow you to create an Azure AI services resource, you may need to enable the privilege of that [Azure resource provider](../../../azure-resource-manager/management/resource-providers-and-types.md#register-resource-provider) using the [Azure portal](../../../azure-resource-manager/management/resource-providers-and-types.md#azure-portal), an [Azure PowerShell command](../../../azure-resource-manager/management/resource-providers-and-types.md#azure-powershell) or an [Azure CLI command](../../../azure-resource-manager/management/resource-providers-and-types.md#azure-cli). If you are not the subscription owner, ask the *Subscription Owner* or someone with a role of *admin* to complete the registration for you or ask for the **/register/action** privileges to be granted to your account.
86+
87+
## Get the keys for your resource
88+
89+
Use the [Get-AzCognitiveServicesAccountKey](/powershell/module/az.cognitiveservices/get-azcognitiveservicesaccountkey) command to get the keys for your resource.
90+
91+
```azurepowershell-interactive
92+
Get-AzCognitiveServicesAccountKey -Name multi-service-resource -ResourceGroupName ai-services-resource-group
93+
```
94+
95+
[!INCLUDE [environment-variables](environment-variables.md)]
96+
97+
## Pricing tiers and billing
98+
99+
Pricing tiers (and the amount you get billed) are based on the number of transactions you send using your authentication information. Each pricing tier specifies the:
100+
* maximum number of allowed transactions per second (TPS).
101+
* service features enabled within the pricing tier.
102+
* The cost for a predefined number of transactions. Going above this amount will cause an extra charge as specified in the [pricing details](https://azure.microsoft.com/pricing/details/cognitive-services/custom-vision-service/) for your service.
103+
104+
## Get current quota usage for your resource
105+
106+
Use the [Get-AzCognitiveServicesAccountUsage](/powershell/module/az.cognitiveservices/get-azcognitiveservicesaccountusage) command to get the usage for your resource.
107+
108+
```azurepowershell-interactive
109+
Get-AzCognitiveServicesAccountUsage -ResourceGroupName ai-services-resource-group -Name multi-service-resource
110+
```
111+
112+
## Clean up resources
113+
114+
If you want to clean up and remove an Azure AI services resource, you can delete it or the resource group. Deleting the resource group also deletes any other resources contained in the group.
115+
116+
To remove the resource group and its associated resources, use the [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup) command.
117+
118+
```azurepowershell-interactive
119+
Remove-AzResourceGroup -Name ai-services-resource-group
120+
```
121+
122+
If you need to recover a deleted resource, see [Recover deleted Azure AI services resources](../../manage-resources.md).

articles/ai-services/multi-service-resource.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ The multi-service resource enables access to the following Azure AI services wit
5656

5757
::: zone-end
5858

59+
::: zone pivot="azpowershell"
60+
61+
[!INCLUDE [Azure PowerShell quickstart](includes/quickstarts/management-azpowershell.md)]
62+
63+
::: zone-end
64+
5965
::: zone pivot="programming-language-csharp"
6066

6167
[!INCLUDE [C# SDK quickstart](includes/quickstarts/management-csharp.md)]

articles/ai-services/openai/chatgpt-quickstart.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ Use this article to get started using Azure OpenAI.
6161
[!INCLUDE [REST API quickstart](includes/chatgpt-rest.md)]
6262

6363
::: zone-end
64+
65+
::: zone pivot="programming-language-powershell"
66+
67+
[!INCLUDE [PowerShell quickstart](includes/chatgpt-powershell.md)]
68+
69+
::: zone-end

articles/ai-services/openai/dall-e-quickstart.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ zone_pivot_groups: openai-quickstart-dall-e
5555

5656
::: zone-end
5757

58+
::: zone pivot="programming-language-powershell"
59+
60+
[!INCLUDE [PowerShell quickstart](includes/dall-e-powershell.md)]
61+
62+
::: zone-end
63+
5864
::: zone pivot="rest-api"
5965

6066
[!INCLUDE [REST API quickstart](includes/dall-e-rest.md)]

articles/ai-services/openai/how-to/create-resource.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ In this article, you review examples for creating and deploying resources in the
3737

3838
::: zone-end
3939

40+
::: zone pivot="ps"
41+
42+
[!INCLUDE [Azure PowerShell resource](../includes/create-resource-powershell.md)]
43+
44+
::: zone-end
45+
4046
## Next steps
4147

4248
- Make API calls and generate text with [Azure OpenAI Service quickstarts](../quickstart.md).

0 commit comments

Comments
 (0)