Edit

Connect to Foundry Tools using Service Connector

In this article, we cover the supported authentication methods and clients that you can use to connect your apps to Foundry Tools using Service Connector. For each supported method, we provide sample code and describe the default environment variable names and values obtained when creating the service connection.

Supported compute services

Service Connector can be used to connect the following compute services to Foundry Tools:

  • Azure App Service
  • Azure Functions
  • Azure Kubernetes Service (AKS)
  • Azure Spring Apps

Supported authentication types and client types

The following table indicates which combinations of authentication methods and clients are supported for connecting your compute service to individual Foundry Tools using Service Connector. A Yes indicates that the combination is supported, while a No indicates that it isn't 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 Foundry Tools using Service Connector.

Default environment variable names or application properties and sample code

Use the following connection details to connect compute services to Foundry Tools. For more information about naming conventions, see the Service Connector internals article.

Default environment variable name Description Sample value
AZURE_AISERVICES_OPENAI_BASE Azure OpenAI endpoint https://<your-Azure-AI-Services-endpoint>.openai.azure.com/
AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT Azure Cognitive Services token provider service https://<your-Azure-AI-Services-endpoint>.cognitiveservices.azure.com/
AZURE_AISERVICES_SPEECH_ENDPOINT Speech to Text (Standard) API endpoint https://<location>.stt.speech.microsoft.com

Sample code

To connect to Foundry Tools using a system-assigned managed identity, refer to the following steps and code.

You can use the Azure client library to access various cognitive APIs that Foundry Tools support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Foundry Tools to call the cognitive APIs directly.

  1. Install the following dependencies. We use Azure.AI.TextAnalytics as an example.

    dotnet add package Azure.AI.TextAnalytics
    dotnet add package Azure.Identity
    
  2. Authenticate using the Azure Identity library and get the Azure AI Services endpoint from the environment variables added by Service Connector. In the code below, uncomment the section for your authentication type.

    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);
    

User-assigned managed identity

Default environment variable name Description Sample value
AZURE_AISERVICES_OPENAI_BASE Azure OpenAI endpoint https://<your-Azure-AI-Services-endpoint>.openai.azure.com/
AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT Azure Cognitive Services token provider service https://<your-Azure-AI-Services-endpoint>.cognitiveservices.azure.com/
AZURE_AISERVICES_SPEECH_ENDPOINT Speech to Text (Standard) API endpoint https://<location>.stt.speech.microsoft.com
AZURE_AISERVICES_CLIENTID Your client ID <client-ID>

Sample code

To connect to Foundry Tools using a user-assigned managed identity, refer to the following steps and code.

You can use the Azure client library to access various cognitive APIs that Foundry Tools support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Foundry Tools to call the cognitive APIs directly.

  1. Install the following dependencies. We use Azure.AI.TextAnalytics as an example.

    dotnet add package Azure.AI.TextAnalytics
    dotnet add package Azure.Identity
    
  2. Authenticate using the Azure Identity library and get the Azure AI Services endpoint from the environment variables added by Service Connector. In the code below, uncomment the section for your authentication type.

    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);
    

Connection string

Default environment variable name Description Sample value
AZURE_AISERVICES_OPENAI_BASE Azure OpenAI endpoint https://<your-Azure-AI-Services-endpoint>.openai.azure.com/
AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT Azure Cognitive Services token provider service https://<your-Azure-AI-Services-endpoint>.cognitiveservices.azure.com/
AZURE_AISERVICES_SPEECH_ENDPOINT Speech to Text (Standard) API endpoint https://<location>.stt.speech.microsoft.com
AZURE_AISERVICES_KEY Foundry Tools API key <api-key>

Sample code

To connect to Foundry Tools using a connection string, refer to the following steps and code.

You can use the Azure client library to access various cognitive APIs that Foundry Tools support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Foundry Tools to call the cognitive APIs directly.

  1. Install the following dependencies. We use Azure.AI.TextAnalytics as an example.

    dotnet add package Azure.AI.TextAnalytics
    dotnet add package Azure.Core --version 1.40.0
    
  2. Get the Azure AI Services endpoint and key from the environment variables added by Service Connector.

    using Azure.AI.TextAnalytics;
    
    string endpoint = Environment.GetEnvironmentVariable("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
    string key = Environment.GetEnvironmentVariable("AZURE_AISERVICES_KEY");
    
    TextAnalyticsClient languageServiceClient = new(
      new Uri(endpoint),
      new AzureKeyCredential(key));
    

Service principal

Default environment variable name Description Sample value
AZURE_AISERVICES_OPENAI_BASE Azure OpenAI endpoint https://<your-Azure-AI-Services-endpoint>.openai.azure.com/
AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT Azure Cognitive Services token provider service https://<your-Azure-AI-Services-endpoint>.cognitiveservices.azure.com/
AZURE_AISERVICES_SPEECH_ENDPOINT Speech to Text (Standard) API endpoint https://<location>.stt.speech.microsoft.com
AZURE_AISERVICES_CLIENTID Your client ID <client-ID>
AZURE_AISERVICES_CLIENTSECRET Your client secret <client-secret>
AZURE_AISERVICES_TENANTID Your tenant ID <tenant-ID>

Sample code

To connect to Foundry Tools using a service principaL, refer to the following steps and code.

You can use the Azure client library to access various cognitive APIs that Foundry Tools support. We use Azure AI Text Analytics as an example in this sample. Refer to Authenticate requests to Foundry Tools to call the cognitive APIs directly.

  1. Install the following dependencies. We use Azure.AI.TextAnalytics as an example.

    dotnet add package Azure.AI.TextAnalytics
    dotnet add package Azure.Identity
    
  2. Authenticate using the Azure Identity library and get the Azure AI Services endpoint from the environment variables added by Service Connector. In the code below, uncomment the section for your authentication type.

    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);