Integrate Azure AI services with Service Connector
Article
This page shows supported authentication methods and clients, and shows sample code you can use to connect Azure AI Services to other cloud services using Service Connector. You might still be able to connect to Azure AI Services using other methods. This page also shows default environment variable names and values you get when you create the service connection.
Supported compute services
Service Connector can be used to connect the following compute services to Azure AI Services:
Azure App Service
Azure Container Apps
Azure Functions
Azure Kubernetes Service (AKS)
Azure Spring Apps
Supported authentication types and client types
The table below shows which combinations of authentication methods and clients are supported for connecting your compute service to Azure AI Services using Service Connector. A “Yes” indicates that the combination is supported, while a “No” indicates that it is not supported.
Client type
System-assigned managed identity
User-assigned managed identity
Secret/connection string
Service principal
.NET
Yes
Yes
Yes
Yes
Java
Yes
Yes
Yes
Yes
Node.js
Yes
Yes
Yes
Yes
Python
Yes
Yes
Yes
Yes
None
Yes
Yes
Yes
Yes
This table indicates that all combinations of client types and authentication methods in the table are supported. All client types can use any of the authentication methods to connect to Azure AI Services using Service Connector.
Default environment variable names or application properties and sample code
Use the connection details below to connect compute services to Azure AI Services. For more information about naming conventions, check the Service Connector internals article.
Refer to the steps and code below to connect to Azure AI Services using a system-assigned managed identity.
You can use the Azure client library to access various cognitive APIs that Azure AI Services support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Azure AI services to call the cognitive APIs directly.
Authenticate using the Azure Identity library and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
using Azure.AI.TextAnalytics;
using Azure.Identity;
string endpoint = Environment.GetEnvironmentVariable("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
TextAnalyticsClient languageServiceClient = new(
new Uri(endpoint),
credential);
Add the following dependencies in your pom.xml file. We use azure-ai-textanalytics as an example.
Authenticate using azure-identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential credential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .clientSecret(System.getenv("AZURE_AISERVICES_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_AISERVICES_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
TextAnalyticsClient languageClient = new TextAnalyticsClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
Install the following dependencies. We use azure-ai-textanalytics as an example.
Authenticate using azure-identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
import os
from azure.ai.textanalytics import TextAnalyticsClient
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
# Uncomment the following lines corresponding to the authentication type you want to use.
# system-assigned managed identity
# cred = ManagedIdentityCredential()
# user-assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_AISERVICES_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_AISERVICES_TENANTID')
# client_id = os.getenv('AZURE_AISERVICES_CLIENTID')
# client_secret = os.getenv('AZURE_AISERVICES_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
endpoint = os.getenv('AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT')
language_service_client = TextAnalyticsClient(
endpoint=endpoint,
credential=cred)
Install the following dependencies. We use ai-text-analytics as an example.
Authenticate using @azure/identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { TextAnalyticsClient } = require("@azure/ai-text-analytics");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// const credential = new DefaultAzureCredential();
// for user-assigned managed identity
// const clientId = process.env.AZURE_AISERVICES_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_AISERVICES_TENANTID;
// const clientId = process.env.AZURE_AISERVICES_CLIENTID;
// const clientSecret = process.env.AZURE_AISERVICES_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const endpoint = process.env.AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT;
const languageClient = new TextAnalyticsClient(endpoint, credential);
For other languages, you can use the connection information that Service Connector sets to the environment variables to connect to Azure AI Services. For environment variable details, see Integrate Azure AI services with Service Connector.
Refer to the steps and code below to connect to Azure AI Services using a user-assigned managed identity.
You can use the Azure client library to access various cognitive APIs that Azure AI Services support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Azure AI services to call the cognitive APIs directly.
Authenticate using the Azure Identity library and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
using Azure.AI.TextAnalytics;
using Azure.Identity;
string endpoint = Environment.GetEnvironmentVariable("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
TextAnalyticsClient languageServiceClient = new(
new Uri(endpoint),
credential);
Add the following dependencies in your pom.xml file. We use azure-ai-textanalytics as an example.
Authenticate using azure-identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential credential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .clientSecret(System.getenv("AZURE_AISERVICES_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_AISERVICES_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
TextAnalyticsClient languageClient = new TextAnalyticsClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
Install the following dependencies. We use azure-ai-textanalytics as an example.
Authenticate using azure-identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
import os
from azure.ai.textanalytics import TextAnalyticsClient
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
# Uncomment the following lines corresponding to the authentication type you want to use.
# system-assigned managed identity
# cred = ManagedIdentityCredential()
# user-assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_AISERVICES_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_AISERVICES_TENANTID')
# client_id = os.getenv('AZURE_AISERVICES_CLIENTID')
# client_secret = os.getenv('AZURE_AISERVICES_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
endpoint = os.getenv('AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT')
language_service_client = TextAnalyticsClient(
endpoint=endpoint,
credential=cred)
Install the following dependencies. We use ai-text-analytics as an example.
Authenticate using @azure/identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { TextAnalyticsClient } = require("@azure/ai-text-analytics");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// const credential = new DefaultAzureCredential();
// for user-assigned managed identity
// const clientId = process.env.AZURE_AISERVICES_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_AISERVICES_TENANTID;
// const clientId = process.env.AZURE_AISERVICES_CLIENTID;
// const clientSecret = process.env.AZURE_AISERVICES_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const endpoint = process.env.AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT;
const languageClient = new TextAnalyticsClient(endpoint, credential);
For other languages, you can use the connection information that Service Connector sets to the environment variables to connect to Azure AI Services. For environment variable details, see Integrate Azure AI services with Service Connector.
Refer to the steps and code below to connect to Azure AI Services using a connection string.
You can use the Azure client library to access various cognitive APIs that Azure AI Services support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Azure AI services to call the cognitive APIs directly.
For other languages, you can use the connection information that Service Connector sets to the environment variables to connect to Azure AI Services. For environment variable details, see Integrate Azure AI services with Service Connector.
Refer to the steps and code below to connect to Azure AI Services using a service principaL.
You can use the Azure client library to access various cognitive APIs that Azure AI Services support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Azure AI services to call the cognitive APIs directly.
Authenticate using the Azure Identity library and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
using Azure.AI.TextAnalytics;
using Azure.Identity;
string endpoint = Environment.GetEnvironmentVariable("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
TextAnalyticsClient languageServiceClient = new(
new Uri(endpoint),
credential);
Add the following dependencies in your pom.xml file. We use azure-ai-textanalytics as an example.
Authenticate using azure-identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential credential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .clientSecret(System.getenv("AZURE_AISERVICES_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_AISERVICES_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
TextAnalyticsClient languageClient = new TextAnalyticsClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
Install the following dependencies. We use azure-ai-textanalytics as an example.
Authenticate using azure-identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
import os
from azure.ai.textanalytics import TextAnalyticsClient
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
# Uncomment the following lines corresponding to the authentication type you want to use.
# system-assigned managed identity
# cred = ManagedIdentityCredential()
# user-assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_AISERVICES_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_AISERVICES_TENANTID')
# client_id = os.getenv('AZURE_AISERVICES_CLIENTID')
# client_secret = os.getenv('AZURE_AISERVICES_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
endpoint = os.getenv('AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT')
language_service_client = TextAnalyticsClient(
endpoint=endpoint,
credential=cred)
Install the following dependencies. We use ai-text-analytics as an example.
Authenticate using @azure/identity and get the Azure AI Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { TextAnalyticsClient } = require("@azure/ai-text-analytics");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// const credential = new DefaultAzureCredential();
// for user-assigned managed identity
// const clientId = process.env.AZURE_AISERVICES_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_AISERVICES_TENANTID;
// const clientId = process.env.AZURE_AISERVICES_CLIENTID;
// const clientSecret = process.env.AZURE_AISERVICES_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const endpoint = process.env.AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT;
const languageClient = new TextAnalyticsClient(endpoint, credential);
For other languages, you can use the connection information that Service Connector sets to the environment variables to connect to Azure AI Services. For environment variable details, see Integrate Azure AI services with Service Connector.
Next steps
Follow the tutorial listed below to learn more about Service Connector.