Create a Cognitive Services resource using the Azure portal
Use this quickstart to get started with Azure Cognitive Services using the Azure portal. Cognitive Services are represented by Azure resources that you create in your Azure subscription. After creating the resource, Use the keys and endpoint generated for you to authenticate your applications.
- A valid Azure subscription - Create one for free
Azure Cognitive Service resource types
Subscription owners can disable the creation of Cognitive Services resources for resource groups and subscriptions by applying Azure policy, assigning a “Not allowed resource types” policy definition, and specifying Microsoft.CognitiveServices/accounts as the target resource type.
You can access Azure Cognitive Services through two different resources: A multi-service resource, or a single-service one. These subscriptions let you connect to either a single service or multiple services at once.
At this time, these services don't support multi-service keys: QnA Maker, Speech Services, Custom Vision, and Anomaly Detector.
Subscribing to a multi-service Cognitive Services resource:
- Lets you use a single Azure resource for most Azure Cognitive Services.
- Consolidates billing from the services you use. See Cognitive Services pricing for additional information.
Single-service resources (such as Computer Vision or Speech Services) are restricted to their specified service.
Create a new Azure Cognitive Services resource
Before creating a Cognitive Services resource, you must have an Azure resource group to contain the resource. When you create a new resource, you have the option to either create a new resource group, or use an existing one. This article shows how to create a new resource group.
Sign in to the Azure portal, and click +Create a resource.
You can find available Cognitive Services with in the following ways:
Use the search bar and enter the name of the service you want to subscribe to.
- To create a multi-service resource, enter Cognitive Services in the search bar, and select the Cognitive Services resource.
To see all available cognitive services, select AI + Machine Learning, under Azure Marketplace. If you don't see the service you're interested in, click on See all and scroll to Cognitive Services. Click More to view the entire catalog of Cognitive Services APIs.
On the Create page, provide the following information:
Remember your Azure location, as you may need it when calling the Azure Cognitive Services.
Name A descriptive name for your cognitive services resource. For example MyCognitiveServicesAccount. Subscription Select one of your available Azure subscriptions. Location The location of your cognitive service instance. Different locations may introduce latency, but have no impact on the runtime availability of your resource. Pricing tier The cost of your Cognitive Services account depends on the options you choose and your usage. For more information, see the API pricing details. Resource group The Azure resource group that will contain your Cognitive Services resource. You can create a new group or add it to a pre-existing group.
Get the keys for your resource
After creating your resource, you can access it from the Azure dashboard if you pinned it. Otherwise, you can find it in Resource Groups. After selecting your resource, you can get the keys by selecting Keys under Resource Management.
Configure an environment variable for authentication
Applications need to authenticate access to the Cognitive Services they use. To authenticate, we recommend creating an environment variable to store the keys for your Azure Resources.
After you have your key, write it to a new environment variable on the local machine running the application. To set the environment variable, open a console window, and follow the instructions for your operating system. Replace
your-key with one of the keys for your resource.
setx COGNITIVE_SERVICE_KEY "your-key"
After you add the environment variable, you may need to restart any running programs that will need to read the environment variable, including the console window. For example, if you are using Visual Studio as your editor, restart Visual Studio before running the example.
After you add the environment variable, run
source ~/.bashrcfrom your console window to make the changes effective.
Edit your .bash_profile, and add the environment variable:
After you add the environment variable, run
source .bash_profilefrom your console window to make the changes effective.
Clean up resources
If you want to clean up and remove a Cognitive Services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources contained in the group.
To remove a resource group using the Azure portal:
- In the Azure portal, expand the menu on the left side to open the menu of services, and choose Resource Groups to display the list of your resource groups.
- Locate the resource group to delete, and right-click the More button (...) on the right side of the listing.
- Select Delete resource group, and confirm.