Azure AI SDK for JavaScript

Welcome to the official documentation for the Azure AI SDK for JavaScript. This SDK provides a comprehensive set of tools to integrate powerful AI capabilities from Azure into your JavaScript applications.

Leverage cutting-edge AI services such as natural language processing, computer vision, speech synthesis, and more, all from the convenience of your JavaScript codebase.

Getting Started

Begin your journey with Azure AI services by following these simple steps.

Installation

To install the SDK, use npm or yarn:

npm install @azure/ai-language-text @azure/ai-vision-image-analysis @azure/ai-cognitiveservices-speech-text

Note: You may need to install specific packages depending on the AI services you intend to use.

Authentication

Azure AI services require authentication. You can authenticate using API keys or Azure Active Directory (Azure AD).

Using API Key:

const { TextAnalysisClient } = require("@azure/ai-language-text");
const { AzureKeyCredential } = require("@azure/core-auth");

const endpoint = "YOUR_AZURE_AI_ENDPOINT";
const apiKey = "YOUR_AZURE_AI_API_KEY";
const credential = new AzureKeyCredential(apiKey);
const client = new TextAnalysisClient(endpoint, credential);

Using Azure AD:

For Azure AD authentication, you'll typically use the DefaultAzureCredential from the @azure/identity package. Refer to the Azure Identity SDK documentation for detailed instructions.

Quickstart

Here's a basic example of using the Text Analytics client to perform language detection:

async function detectLanguage(text) {
    const credential = new AzureKeyCredential("YOUR_AZURE_AI_API_KEY");
    const client = new TextAnalysisClient("YOUR_AZURE_AI_ENDPOINT", credential);

    const results = await client.detectLanguage([text]);

    for (const result of results) {
        console.log(`Detected language: ${result.primaryLanguage.name} (confidence: ${result.primaryLanguage.confidenceScore})`);
    }
}

detectLanguage("Hello, world! This is a test.");

Core Concepts

Understand the fundamental building blocks of the Azure AI SDK.

Clients

Each Azure AI service is exposed through a dedicated client object. These clients provide methods to interact with the specific AI capabilities.

Models

The SDK utilizes various models tailored for different tasks, such as sentiment analysis models, object detection models, and speech recognition models.

Operations

Operations are the actions you can perform using the clients, like analyzing text, detecting objects in an image, or transcribing audio.

Supported AI Services

The Azure AI SDK for JavaScript supports a wide range of Azure AI services.

  • Azure AI Language: For text analysis, sentiment analysis, key phrase extraction, named entity recognition, translation, and more.
  • Azure AI Vision: Including Computer Vision for image analysis, OCR, face detection, and Custom Vision for custom image classification and object detection.
  • Azure AI Speech: For speech-to-text, text-to-speech, speech translation, and speaker recognition.
  • Azure AI Content Safety: For detecting and filtering harmful content in text and images.
  • Azure AI Search: For building powerful search experiences over your data.

API Reference

Explore the detailed API reference for each service:

Examples

Dive into practical examples showcasing various functionalities:

Contributing

We welcome contributions to the Azure AI SDK for JavaScript! Please see our contributing guide for more information.

Support

If you encounter any issues or have questions, please open an issue on our GitHub repository.