Edit

Share via


Azure AI Foundry SDK client libraries

The Azure AI Foundry SDK is a comprehensive toolchain designed to simplify the development of AI applications on Azure. It enables developers to:

  • Access popular models from various model providers through a single interface
  • Easily combine together models, data, and AI services to build AI-powered applications
  • Evaluate, debug, and improve application quality & safety across development, testing, and production environments

The Azure AI Foundry SDK is a set of client libraries and services designed to work together.

Note

This article applies to a Azure AI Foundry project. The code shown here doesn't work for a hub-based project. For more information, see Types of projects.

Prerequisites

  • An Azure subscription. If you don't have one, create a free account.

  • Create a Azure AI Foundry project if you don't have one already.

  • Azure AI Foundry Models allows customers to consume the most powerful models from flagship model providers using a single endpoint and credentials. This means that you can switch between models and consume them from your application without changing a single line of code.

    Copy the Azure AI Foundry project endpoint in the Overview section of your project. You'll use it in a moment.

    Screenshot shows the project overview for a Foundry project.

    Tip

    If you don't see the Azure AI Foundry project endpoint, you're using a hub-based project. (See Types of projects). Switch to a Azure AI Foundry project, or use the preceding steps to create one.

  • Sign in with the Azure CLI using the same account that you use to access your project:

    az login
    

Unified Projects client library

The following examples show how to connect to your Azure AI Foundry project using different programming languages. This connection is the first step to accessing models, data, and AI services through the SDK. Each code block demonstrates how to authenticate and create a client for your project endpoint.

Tip

The code samples below are starting points. You’ll use these clients to interact with models, run evaluations, and more, as described in the client libraries section below.

The Azure AI Foundry Projects client library for Python is a unified library that enables you to use multiple client libraries together by connecting to a single project endpoint.

  • Install the project client library

    pip install azure-ai-projects azure-identity
    
  • Create a project client in code. Copy the Azure AI Foundry project endpoint from the Overview page of the project and update the connections string value.

    from azure.identity import DefaultAzureCredential
    from azure.ai.projects import AIProjectClient
    
    project = AIProjectClient(
      endpoint="your_project_endpoint",  # Replace with your endpoint
      credential=DefaultAzureCredential())
    # The AIProjectClient lets you access models, data, and services in your project.
    

The Azure AI Foundry Projects client library for Java (preview) is a unified library that enables you to use multiple client libraries together by connecting to a single project endpoint.

Important

Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.

  • Add these packages to your installation:

    • com.azure.ai.projects
    • com.azure.core
  • Create a project client in code. Copy the Azure AI Foundry project endpoint from the Overview page of the project and update the connections string value.

    import com.azure.ai.projects.ProjectsClient;
    import com.azure.ai.projects.ProjectsClientBuilder;
    import com.azure.core.credential.AzureKeyCredential;
    
    String endpoint ="your_project_endpoint"; // Replace with your endpoint
    
    ProjectsClient projectClient = new ProjectsClientBuilder()
        .credential(new DefaultAzureCredential())
        .endpoint(endpoint)
        .buildClient();
    // The ProjectsClient enables unified access to your project's resources.
    

The Azure AI Foundry Projects client library for JavaScript is a unified library that enables you to use multiple client libraries together by connecting to a single project endpoint.

  • Install dependencies (preview):

    npm install @azure/ai-projects @azure/identity
    
  • Create a project client in code. Copy the Azure AI Foundry project endpoint from the Overview page of the project and update the connections string value.

    import { AIProjectClient } from '@azure/ai-projects';
    import { DefaultAzureCredential } from '@azure/identity';
    
    const endpoint = "your_project_endpoint"; // Replace with your actual endpoint
    const project = new AIProjectClient(endpoint, new DefaultAzureCredential());
    const projectClient = await project.getAzureOpenAIClient({
        // The API version should match the version of the Azure OpenAI resource
        apiVersion: "2024-12-01-preview"
    });
    // The AIProjectClient lets you access models, data, and services in your project.
    

The Azure AI Foundry Projects client library for .NET is a unified library that enables you to use multiple client libraries together by connecting to a single project endpoint.

  • Install packages:

    dotnet add package Azure.Identity
    dotnet add package Azure.Core
    dotnet add package Azure.AI.Inference
    
  • Create a project client in code. Copy the Azure AI Foundry project endpoint from the Overview page of the project and update the connections string value.

    using Azure;
    using Azure.Identity;
    using Azure.AI.Inference;
    using Azure.Core;
    using Azure.Core.Pipeline;
    
    var endpointUrl = "your_project_endpoint"; // Replace with your actual endpoint
    var credential = new DefaultAzureCredential();
    
    AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions();
    BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(
        credential, 
        new string[] { "https://cognitiveservices.azure.com/.default" }
    );
    // The PerRetry position ensures the authentication policy is applied to every retry attempt.
    // This is important for robust authentication in distributed/cloud environments.
    clientOptions.AddPolicy(tokenPolicy, HttpPipelinePosition.PerRetry);
    
    var projectClient = new ChatCompletionsClient(
        endpointUrl, 
        credential,
        clientOptions
    );
    // The ChatCompletionsClient lets you interact with models and services in your project.
    

After you create a client, you can use it to access models, run evaluations, and connect to other AI services. The next section lists the available client libraries and shows how to use them for specific Azure AI services.

Azure AI Services client libraries

To use Azure AI services, you can use the following client libraries with the endpoints listed on the project homepage.

C# supported services

Service Description Reference documentation
Speech icon Speech Add speech to text, text to speech, translation, and speaker recognition capabilities to applications. • Speech SDK for .NET

• Speech NuGet package (Speech CLI)
Content Safety icon Content Safety Detect harmful content in applications and services. • Content Safety SDK for .NET

• Content Safety NuGet package
Vision icon Vision Analyze content in digital images and rich media assets. • Vision SDK for .NET

• Vision NuGet package
Language icon Language Build applications with natural language understanding capabilities. • Language SDK for .NET (text analysis)

• Language NuGet package (text analysis)

• Language SDK for .NET (Question Answering)

• Language NuGet package (question answering)
Translator icon Translator Use AI-powered translation technology to translate more than 100 in-use, at-risk, and endangered languages and dialects. • Translator SDK for .NET (text)

• Translator NuGet package (text)

• Translator SDK for .NET (batch)

• Translator NuGet package (batch)
Document Intelligence icon Document Intelligence Turn documents into intelligent data-driven solutions. • Document Intelligence SDK for .NET

• Document Intelligence NuGet package
Azure AI Search icon Azure AI Search Bring AI-powered cloud search to your mobile and web apps. • Azure AI Search SDK for .NET

• Azure AI Search NuGet package

Java supported services

Service Description Reference documentation
Speech icon Speech Add speech to text, text to speech, translation, and speaker recognition capabilities to applications. • Speech SDK for Java

• Speech Maven package
Content Safety icon Content Safety Detect harmful content in applications and services. • Content Safety SDK for Java

• Content Safety Maven package
Vision icon [Vision]../../../ai-services/computer-vision/index.yml) Analyze content in digital images and rich media assets. • Vision SDK for Java

• Vision Maven package
Language icon Language Build applications with natural language understanding capabilities. • Language SDK for Java (text analysis)

• Language Maven package
Translator icon Translator Use AI-powered translation technology to translate more than 100 in-use, at-risk, and endangered languages and dialects. • Translator SDK for Java (text)

• Translator Maven package (text)
Document Intelligence icon Document Intelligence Turn documents into intelligent data-driven solutions. • Document Intelligence SDK for Java

• Document Intelligence Maven package
Azure AI Search icon Azure AI Search Bring AI-powered cloud search to your mobile and web apps. • Azure AI Search SDK for Java

• Azure AI Search Maven package

JavaScript Supported Services

Service Description Reference documentation
Speech icon Speech Add speech to text, text to speech, translation, and speaker recognition capabilities to applications. • Speech SDK for JavaScript

• Speech npm package
Content Safety icon Content Safety Detect harmful content in applications and services. • Content Safety SDK for JavaScript

• Content Safety npm package
Vision icon Vision Analyze content in digital images and rich media assets. • Vision SDK for JavaScript

• Vision npm package
Language icon Language Build applications with natural language understanding capabilities. • Language SDK for JavaScript (text analysis)

• Language npm package
Translator icon Translator Use AI-powered translation technology to translate more than 100 in-use, at-risk, and endangered languages and dialects. • Translator SDK for JavaScript (text)

• Translator npm package (text)
Document Intelligence icon Document Intelligence Turn documents into intelligent data-driven solutions. • Document Intelligence SDK for JavaScript

• Document Intelligence npm package
Azure AI Search icon Azure AI Search Bring AI-powered cloud search to your mobile and web apps. • Azure AI Search SDK for JavaScript

• Azure AI Search npm package

Python supported services

Service Description Reference documentation
Speech icon Speech Add speech to text, text to speech, translation, and speaker recognition capabilities to applications. • Speech SDK for Python

• Speech PyPi package
Content Safety icon Content Safety Detect harmful content in applications and services. • Content Safety SDK for Python

• Content Safety PyPi package
Vision icon Vision Analyze content in digital images and rich media assets. • Vision SDK for Python

• Vision PyPi package
Language icon Language Build applications with natural language understanding capabilities. • Language SDK for Python (text analysis)

• Language PyPi package (text analysis)

• Language SDK for Python (question answering)

• Language PyPi package (question answering)

• Language SDK for Python (language conversations)

• Language PyPi package (language conversations)
Translator icon Translator Use AI-powered translation technology to translate more than 100 in-use, at-risk, and endangered languages and dialects. • Translator SDK for Python (text)

• Translator PyPi package (text)

• Translator SDK for Python (batch)

• Translator PyPi package (batch)
Document Intelligence icon Document Intelligence Turn documents into intelligent data-driven solutions. • Document Intelligence SDK for Python

• Document Intelligence PyPi package
Azure AI Search icon Azure AI Search Bring AI-powered cloud search to your mobile and web apps. • Azure AI Search SDK for Python

• Azure AI Search PyPi package