{"id":1359,"library":"azure-mgmt-cognitiveservices","title":"Azure Cognitive Services Management Client","description":"This library provides the management client for Azure Cognitive Services, enabling programmatic creation, configuration, and deletion of Cognitive Services accounts (e.g., for Text Analytics, Speech, Vision, Language) within an Azure subscription. It is part of the Azure SDK for Python, currently at version 14.1.0, and receives regular updates as part of the broader Azure SDK.","status":"active","version":"14.1.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cognitiveservices/azure-mgmt-cognitiveservices","tags":["azure","cloud","management","cognitive services","sdk","ai","resource management"],"install":[{"cmd":"pip install azure-mgmt-cognitiveservices azure-identity","lang":"bash","label":"Install core and authentication packages"}],"dependencies":[{"reason":"Essential for authenticating to Azure services; typically used with DefaultAzureCredential.","package":"azure-identity","optional":false},{"reason":"Base layer for all Azure SDK clients, providing common primitives and error handling.","package":"azure-core","optional":false},{"reason":"Shared components for Azure management clients, including pollers for long-running operations.","package":"azure-mgmt-core","optional":false}],"imports":[{"symbol":"CognitiveServicesManagementClient","correct":"from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient"},{"note":"Required for authenticating to Azure using standard credential flows. Install `azure-identity` separately.","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.cognitiveservices import CognitiveServicesManagementClient\n\n# Ensure these environment variables are set:\n# AZURE_SUBSCRIPTION_ID\n# AZURE_RESOURCE_GROUP_NAME (e.g., 'myResourceGroup')\n# AZURE_LOCATION (e.g., 'eastus')\n\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"\")\nresource_group_name = os.environ.get(\"AZURE_RESOURCE_GROUP_NAME\", \"\")\nlocation = os.environ.get(\"AZURE_LOCATION\", \"eastus\")\naccount_name = \"myunique_cogsrv_account\" # Must be globally unique for some services\n\nif not all([subscription_id, resource_group_name]):\n    raise ValueError(\"Please set AZURE_SUBSCRIPTION_ID and AZURE_RESOURCE_GROUP_NAME environment variables.\")\n\n# Authenticate with Azure\ncredential = DefaultAzureCredential()\n\n# Create Cognitive Services Management Client\nclient = CognitiveServicesManagementClient(credential, subscription_id)\n\nprint(f\"Listing Cognitive Services accounts in resource group '{resource_group_name}':\")\nfor account in client.accounts.list_by_resource_group(resource_group_name):\n    print(f\"- {account.name} (Kind: {account.kind}, Location: {account.location})\")\n\n# Example: Create a new account (if it doesn't exist)\nprint(f\"\\nAttempting to create/update account '{account_name}'...\")\naccount_properties = {\n    \"sku\": {\"name\": \"F0\"}, # F0 is the free tier\n    \"kind\": \"TextAnalytics\", # Example kind: 'TextAnalytics', 'Face', 'SpeechServices'\n    \"location\": location,\n    \"properties\": {}\n}\n\ntry:\n    # begin_create returns a poller for long-running operations\n    poller = client.accounts.begin_create(\n        resource_group_name,\n        account_name,\n        account_properties\n    )\n    new_account = poller.result() # Wait for the operation to complete\n    print(f\"Successfully created/updated account: {new_account.name} (ID: {new_account.id})\")\nexcept Exception as e:\n    print(f\"Error creating/updating account: {e}\")","lang":"python","description":"This quickstart demonstrates how to authenticate with `DefaultAzureCredential`, create a `CognitiveServicesManagementClient`, list existing Cognitive Services accounts within a resource group, and create a new Cognitive Services account. It uses environment variables for Azure subscription, resource group, and location."},"warnings":[{"fix":"Migrate authentication to `azure-identity.DefaultAzureCredential`. Ensure environment variables like `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` (for service principal) or `AZURE_SUBSCRIPTION_ID` are set.","message":"Authentication mechanisms have significantly evolved in Azure SDK for Python. Older libraries used `ServicePrincipalCredentials` or similar direct credential objects. Modern SDKs (like `azure-mgmt-cognitiveservices` v14.x) primarily use `azure-identity` with `DefaultAzureCredential` for a unified and more secure authentication experience.","severity":"breaking","affected_versions":"<10.0.0 (approximate) to 14.x.x"},{"fix":"For data plane operations (calling the actual AI services), use specific 'data plane' SDKs like `azure-ai-textanalytics`, `azure-cognitiveservices-speech`, or `azure-ai-vision`.","message":"This library (`azure-mgmt-cognitiveservices`) is a 'control plane' client, used for managing (creating, deleting, configuring) Cognitive Services *accounts*. It is NOT for interacting with the Cognitive Services APIs themselves (e.g., performing text analysis, speech-to-text, or computer vision tasks).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always call `.result()` on the poller object returned by `begin_*` methods (e.g., `client.accounts.begin_create(...).result()`) to wait for the operation to complete and retrieve the final resource or confirmation of completion.","message":"Many resource creation/deletion operations in Azure management clients are long-running operations (LROs). Methods like `begin_create()` or `begin_delete()` return a poller object, not the final resource.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When creating an account, ensure the `account_name` parameter is unique. A common practice is to append a random string or timestamp to a base name.","message":"Cognitive Services account names must be globally unique across Azure, not just within your subscription or resource group, for some service kinds.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}