---
# System prepended metadata

title: Announcing new preview release of Azure Anomaly Detector libraries

---

# Announcing new preview release of Azure Anomaly Detector libraries

Today we are excited to announce that Azure Anomaly Detector has released new preview SDK libraries that enable developers to easily integrate the service into their applications. The new libraries provide a simple and intuitive interface for detecting anomalies in time series data and offer a range of customization options to fine-tune the detection algorithms for specific use cases. The preview libraries are available for Python, Java, JS/TS and .NET.

[Azure Anomaly Detector](https://learn.microsoft.com/en-us/azure/cognitive-services/Anomaly-Detector/overview) is a cloud-based service that uses machine learning algorithms to automatically detect anomalies in time series data. The service is designed to help customers identify and respond to anomalies in their data in real-time, enabling them to take proactive action to prevent potential issues. Azure Anomaly Detector can be used in a wide range of scenarios, including monitoring the performance of IT systems, detecting anomalies in complex system or equipment for predictive maintenance, and identifying anomalous trends in business data. The service is available through the Azure portal and can be easily integrated into existing applications using the Azure Anomaly Detector SDK libraries released today.
Here're the languages and correlated download materials with sample code.
|Language|	Version|	Package|	Readme|
| -------- | -------- | -------- |-------- |
|Python	|3.0.0b6 |	[Download](https://pypi.org/project/azure-ai-anomalydetector/3.0.0b6/)| [Link](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/anomalydetector/azure-ai-anomalydetector)|
|.NET	|3.0.0-preview.6|	[Download](https://www.nuget.org/packages/Azure.AI.AnomalyDetector/3.0.0-preview.6)|[Link](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/anomalydetector/Azure.AI.AnomalyDetector)|
|JS|	1.0.0-beta.1|	[Download](https://www.npmjs.com/package/@azure-rest/ai-anomaly-detector/v/1.0.0-beta.1)|[Link](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/anomalydetector/ai-anomaly-detector-rest)|
|JAVA	|3.0.0-beta.5	|[Download](https://search.maven.org/artifact/com.azure/azure-ai-anomalydetector/3.0.0-beta.5/jar)| [Link](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/anomalydetector/azure-ai-anomalydetector)|

> Note: I know your time is very valuable, so you could directly try with the following notebooks to  start quickly: 
> * [AnomalyDetector/🆕UVAD-SDK-Demo.ipynb](https://github.com/Azure-Samples/AnomalyDetector/blob/master/ipython-notebook/SDK%20Sample/%F0%9F%86%95UVAD-SDK-Demo.ipynb)
> * [AnomalyDetector/🆕MVAD-SDK-Demo.ipynb](https://github.com/Azure-Samples/AnomalyDetector/blob/master/ipython-notebook/SDK%20Sample/%F0%9F%86%95MVAD-SDK-Demo.ipynb)

## Get started with an Anomaly Detector client
You’ll need to create an Anomaly Detector client to get started, and use that client to operate with different features.
### Python:
```python
from azure.core.credentials import AzureKeyCredential
from azure.ai.anomalydetector import AnomalyDetectorClient

credential = AzureKeyCredential("<api_key>")
client = AnomalyDetectorClient(endpoint="https://<resource-name>.cognitiveservices.azure.com/", credential=credential)
```
### .NET:
```csharp
string endpoint = "<endpoint>";
string apiKey = "<apiKey>";
var credential = new AzureKeyCredential(apiKey);
var client = new AnomalyDetectorClient(new Uri(endpoint), credential);
```
### JAVA:
```java
String endpoint = Configuration.getGlobalConfiguration().get("AZURE_ANOMALY_DETECTOR_ENDPOINT");
String key = Configuration.getGlobalConfiguration().get("AZURE_ANOMALY_DETECTOR_API_KEY");

AnomalyDetectorClient anomalyDetectorClient =
    new AnomalyDetectorClientBuilder()
        .credential(new AzureKeyCredential(key))
        .endpoint(endpoint)
        .buildClient();
```
### JavaScript:
```javascript
const apiKey = process.env["ANOMALY_DETECTOR_API_KEY"] || "";
const endpoint = process.env["ANOMALY_DETECTOR_ENDPOINT"] || "";
```

## Key features
### Univariate Anomaly Detection
The Univariate Anomaly Detection API enables you to monitor and detect abnormalities in your time series data without having to know machine learning. The algorithms adapt by automatically identifying and applying the best-fitting models to your data, regardless of industry, scenario, or data volume. Using your time series data, the API determines boundaries for anomaly detection, expected values, and which data points are anomalies.

With the Univariate Anomaly Detection, you can automatically detect anomalies throughout your time series data, or as they occur in real-time.
#### Example:
Below is an example of using Univariate Anomaly Detection for batch detection.
#### Python:
```python
from azure.ai.anomalydetector import AnomalyDetectorClient
from azure.core.credentials import AzureKeyCredential
from azure.ai.anomalydetector.models import *


SUBSCRIPTION_KEY = os.environ["ANOMALY_DETECTOR_KEY"]
ANOMALY_DETECTOR_ENDPOINT = os.environ["ANOMALY_DETECTOR_ENDPOINT"]
TIME_SERIES_DATA_PATH = os.path.join("sample_data", "request-data.csv")
client = AnomalyDetectorClient(ANOMALY_DETECTOR_ENDPOINT, AzureKeyCredential(SUBSCRIPTION_KEY))

series = []
data_file = pd.read_csv(TIME_SERIES_DATA_PATH, header=None, encoding="utf-8", parse_dates=[0])
for index, row in data_file.iterrows():
    series.append(TimeSeriesPoint(timestamp=row[0], value=row[1]))

request = UnivariateDetectionOptions(
    series=series,
    granularity=TimeGranularity.DAILY,
)


if any(response.is_anomaly):
    print("An anomaly was detected at index:")
    for i, value in enumerate(response.is_anomaly):
        if value:
            print(i)
else:
    print("No anomalies were detected in the time series.")
```
#### .NET:
```csharp
Console.WriteLine("Detecting anomalies in the entire time series.");

try
{
    UnivariateEntireDetectionResult result = client.DetectUnivariateEntireSeries(request);

    bool hasAnomaly = false;
    for (int i = 0; i < request.Series.Count; ++i)
    {
        if (result.IsAnomaly[i])
        {
            Console.WriteLine("An anomaly was detected at index: {0}.", i);
            hasAnomaly = true;
        }
    }
    if (!hasAnomaly)
    {
        Console.WriteLine("No anomalies detected in the series.");
    }
}
catch (RequestFailedException ex)
{
    Console.WriteLine(String.Format("Entire detection failed: {0}", ex.Message));
    throw;
}
catch (Exception ex)
{
    Console.WriteLine(String.Format("Detection error. {0}", ex.Message));
    throw;
}
```
#### JAVA:
```java
public class DetectAnomaliesEntireSeries {
    public static void main(final String[] args) throws IOException {
        String endpoint = Configuration.getGlobalConfiguration().get("AZURE_ANOMALY_DETECTOR_ENDPOINT");
        String key = Configuration.getGlobalConfiguration().get("AZURE_ANOMALY_DETECTOR_API_KEY");

        AnomalyDetectorClient anomalyDetectorClient =
            new AnomalyDetectorClientBuilder()
                .credential(new AzureKeyCredential(key))
                .endpoint(endpoint)
                .buildClient();

        Path path = Paths.get("azure-ai-anomalydetector/src/samples/java/sample_data/request-data.csv");
        List<String> requestData = Files.readAllLines(path);
        List<TimeSeriesPoint> series = requestData.stream()
            .map(line -> line.trim())
            .filter(line -> line.length() > 0)
            .map(line -> line.split(",", 2))
            .filter(splits -> splits.length == 2)
            .map(splits -> {
                TimeSeriesPoint timeSeriesPoint = new TimeSeriesPoint(Float.parseFloat(splits[1]));
                timeSeriesPoint.setTimestamp(OffsetDateTime.parse(splits[0]));
                return timeSeriesPoint;
            })
            .collect(Collectors.toList());

        System.out.println("Detecting anomalies as a batch...");
        UnivariateDetectionOptions request = new UnivariateDetectionOptions(series);
        request.setGranularity(TimeGranularity.DAILY);
        request.setImputeMode(ImputeMode.AUTO);

        UnivariateEntireDetectionResult response = anomalyDetectorClient.detectUnivariateEntireSeries(request);
        if (response.getIsAnomaly().contains(true)) {
            System.out.println("Anomalies found in the following data positions:");
            for (int i = 0; i < request.getSeries().size(); ++i) {
                if (response.getIsAnomaly().get(i)) {
                    System.out.print(i + " ");
                }
            }
            System.out.println();
        } else {
            System.out.println("No anomalies were found in the series.");
        }
}
```
#### JavaScript:
```javascript
const apiKey = process.env["ANOMALY_DETECTOR_API_KEY"] || "";
const endpoint = process.env["ANOMALY_DETECTOR_ENDPOINT"] || "";
const timeSeriesDataPath = "./samples-dev/example-data/request-data.csv";

function read_series_from_file(path: string): Array<TimeSeriesPoint> {
  let result = Array<TimeSeriesPoint>();
  let input = fs.readFileSync(path).toString();
  let parsed = parse(input, { skip_empty_lines: true });
  parsed.forEach(function (e: Array<string>) {
    result.push({ timestamp: new Date(e[0]), value: Number(e[1]) });
  });
  return result;
}

export async function main() {
  // create client
  const credential = new AzureKeyCredential(apiKey);
  const client = AnomalyDetector(endpoint, credential);

  // construct request
  const options: DetectUnivariateEntireSeriesParameters = {
    body: {
      granularity: "daily",
      imputeMode: "auto",
      maxAnomalyRatio: 0.25,
      sensitivity: 95,
      series: read_series_from_file(timeSeriesDataPath),
    },
    headers: { "Content-Type": "application/json" },
  };

  // get last detect result
  const result = await client.path("/timeseries/entire/detect").post(options);
  if (isUnexpected(result)) {
    throw result;
  }

  if (result.body.isAnomaly) {
    result.body.isAnomaly.forEach(function (anomaly, index) {
      if (anomaly === true) {
        console.log(index);
      }
    });
  } else {
    console.log("There is no anomaly detected from the series.");
  }
```

### Multivariate Anomaly Detection
The Multivariate Anomaly Detection APIs further enable developers by easily integrating advanced AI for detecting anomalies from groups of metrics, without the need for machine learning knowledge or labeled data. Dependencies and inter-correlations between up to 300 different signals are now automatically counted as key factors. This new capability helps you to proactively protect your complex systems such as software applications, servers, factory machines, spacecraft, or even your business, from failures.
With the Multivariate Anomaly Detection, you can automatically detect anomalies throughout your time series data, or as they occur in real-time. There are three processes to use Multivariate Anomaly Detection.
* Training: Use Train Model API to create and train a model, then use Get Model Status API to get the status and model metadata.
* Inference: Use Async Inference to trigger an asynchronous inference process and use Get Inference results API to get detection results on a batch of data.You could also use Sync Inference to trigger a detection on one timestamp every time.
* Other operations: List Model and Delete Model are supported in Multivariate Anomaly Detection model for model management.

#### Example:
Since Multivariate Anomaly Detection requires training and inference as a complete flow, please check correlated sample below.


| Language | Sample code | 
| -------- | -------- |
| Python     | [Sample](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py)     | 
| .NET     | [Sample](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/samples/Sample4_MultivariateDetect.cs)     | 
| Java     | [Sample](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/anomalydetector/azure-ai-anomalydetector/src/samples/java/com/azure/ai/anomalydetector/MultivariateSample.java)     | 
| JavaScript     | [Sample](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/anomalydetector/ai-anomaly-detector-rest/samples-dev/sample_multivariate_detection.ts)     | 


## Learn more
We hope this post offered some insight into the Azure Anomaly Detector package. We welcome any feedback or suggestions, please contact us through AnomalyDetector@microsoft.com.

For more information, see the following resources:
* [What is Azure Anomaly Detector?](https://learn.microsoft.com/en-us/azure/cognitive-services/Anomaly-Detector/overview)
* [Github repo of Anomaly Detector API and SDK samples.](https://github.com/Azure-Samples/AnomalyDetector)
* [Join our Teams Channel](https://forms.office.com/pages/responsepage.aspx?id=v4j5cvGGr0GRqy180BHbR2Ci-wb6-iNDoBoNxrnEk9VURjNXUU1VREpOT0U1UEdURkc0OVRLSkZBNC4u) for better support and discussions.




