Free Anomaly Detection API Complete Tutorial: Zero-Cost Outlier Detection in Your Data (2026-10-22 Verified)
Looking for more zero-cost developer resources? Browse our complete free API directory and create a free account to bookmark tutorials, track API quotas, and receive update notifications when vendors change their free tiers.
Anomaly detection (also called outlier detection) is the process of automatically identifying data points that deviate significantly from normal patterns. Unlike standard classification, anomaly detection faces the challenge of extreme class imbalance — anomalous samples may represent less than 1% of total data. This tutorial covers five verified free anomaly detection solutions, from statistical methods to deep learning, with feature tables, Python code, and a decision tree to help you choose the right one. All quotas below were re-verified on 2026-10-22.
Quick Comparison Radar Chart
The chart below scores each solution on six dimensions (1–10 scale) so you can visualize trade-offs at a glance.
1. Hugging Face Inference API
Hugging Face hosts several anomaly detection models including Anomaly Transformer and PatchTST. The free Inference API tier lets you call these models without self-hosting.
| Feature | Value |
|---|---|
| Free quota | ~1,000 requests/day (soft cap) |
| Models | Anomaly Transformer, PatchTST, custom models |
| Data types | Time series, tabular, text |
| Response time | Medium (queue-based, cold start may be slow) |
| Commercial use | Depends on model license |
Step-by-Step
- Create a Hugging Face account and generate an access token.
- Search Model Hub for anomaly detection models.
- POST data as JSON to the inference endpoint.
- Parse the returned anomaly scores and labels.
Python Example
import requests
import json
API_URL = "https://api-inference.huggingface.co/models/AnomalyTransformer/Anomaly-Transformer"
HF_TOKEN = "your-huggingface-token"
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
payload = {"inputs": {"data": [45, 43, 44, 95, 43, 98, 44], "threshold": 0.5}}
resp = requests.post(API_URL, headers=headers, json=payload)
print(json.dumps(resp.json(), indent=2))
Recommended Use Cases
- Quick prototyping for time-series anomaly detection
- Academic research on Transformer-based detection
- Teams without GPU infrastructure
2. AWS Lookout for Metrics (500 metrics/month free)
AWS Lookout for Metrics is a managed time-series anomaly detection service that automatically analyzes business metrics and identifies anomalies with root-cause analysis.
| Feature | Value |
|---|---|
| Free quota | 500 metrics/month free |
| Models | AWS internal AutoML |
| Data types | Time series (business and ops metrics) |
| Special features | Automatic root-cause analysis, anomaly grouping, real-time alerts |
| Response time | Near real-time (5–15 min latency) |
| Commercial use | AWS ToS applies |
Step-by-Step
- Create an AWS account and navigate to Lookout for Metrics.
- Create an anomaly detector, selecting your data source (CloudWatch, S3, etc.).
- Map data fields to metric dimensions.
- The service runs automatically; anomalies are pushed via SNS or email.
Python Example (boto3)
import boto3, time
client = boto3.client("lookoutmetrics", region_name="us-east-1")
# Create detector
resp = client.create_anomaly_detector(
AnomalyDetectorName="cpu-anomaly-detector",
AnomalyDetectorConfig={"AnomalyDetectorFrequency": "PT5M"}
)
detector_arn = resp["Arn"]
print(f"Detector ARN: {detector_arn}")
# Wait for activation
while True:
desc = client.describe_anomaly_detector(AnomalyDetectorName="cpu-anomaly-detector")
if desc["Status"] == "ACTIVE":
print("Detector is active!")
break
time.sleep(10)
# Get anomaly results
results = client.get_anomaly_group_results(
AnomalyDetectorName="cpu-anomaly-detector",
SensitivityThreshold=50
)
for group in results.get("AnomalyGroupScores", []):
print(f"Anomaly score: {group.get('Score', 'N/A')}")
Recommended Use Cases
- DevOps teams already on AWS
- Business metrics monitoring with root-cause analysis
- Enterprise-grade anomaly detection without ML expertise
3. Azure Metrics Advisor (25,000 data points/month free)
Azure Metrics Advisor is a multi-dimensional time-series anomaly detection service from Microsoft. It supports automatic feature extraction, root-cause analysis, and intelligent alerting.
| Feature | Value |
|---|---|
| Free quota | 25,000 data points/month free |
| Models | Azure internal ML models |
| Data types | Multi-dimensional time series |
| Special features | Auto feature extraction, multi-dimensional root-cause analysis, smart alerts |
| Response time | Near real-time |
| Commercial use | Azure ToS applies |
Step-by-Step
- Create a Metrics Advisor resource in Azure Portal.
- Obtain Subscription Key and Endpoint from the resource page.
- Create a data feed from CSV, SQL, or Blob Storage.
- Configure detection parameters (sensitivity, detection window).
- Query detection results via REST API.
Python Example
import requests, json
SUB_KEY = "your-azure-subscription-key"
ENDPOINT = "https://your-metrics-advisor.cognitiveservices.azure.com/"
headers = {"Ocp-Apim-Subscription-Key": SUB_KEY, "Content-Type": "application/json"}
# Create data feed
feed_config = {
"dataFeed": {
"dataSourceType": "AzureBlob",
"dataSourceParameter": {"connectionString": "your-conn-string", "container": "metrics"},
"granularity": {"granularityType": "Daily"},
"metrics": [{"name": "cpu_usage", "displayName": "CPU Usage"}],
"dimension": [{"name": "server", "displayName": "Server"}]
}
}
resp = requests.post(f"{ENDPOINT}metricsadvisor/v1.0/dataFeeds", headers=headers, json=feed_config)
feed_id = resp.json().get("dataFeedId")
print(f"Data feed ID: {feed_id}")
# Query anomaly results
detection = {
"name": "cpu-anomaly-config",
"metricId": "metric-id-from-feed",
"detectionConfiguration": {"sensitivity": 75, "anomalyDetectionDirection": "Both"}
}
resp2 = requests.post(f"{ENDPOINT}metricsadvisor/v1.0/enrichment/anomalyDetection/configurations",
headers=headers, json=detection)
print(json.dumps(resp2.json(), indent=2))
Recommended Use Cases
- Enterprise teams already on Azure
- Multi-dimensional root-cause analysis for business metrics
- Smart alerting with incident management
4. Python PyOD Library (50+ Algorithms, Fully Free)
PyOD (Python Outlier Detection) is the most comprehensive open-source anomaly detection library in the Python ecosystem, with 50+ algorithms ranging from classic Z-Score and IQR to deep learning approaches like AutoEncoder and GAN.
| Feature | Value |
|---|---|
| Free quota | Unlimited (your compute) |
| Algorithms | 50+ (IForest, LOF, OCSVM, AutoEncoder, VAE, GAN, etc.) |
| Data types | Tabular, time series, high-dimensional |
| Special features | Unified API, model combination (average/max), save/load |
| Response time | Fast (local CPU) |
| Commercial use | BSD-2-Clause |
Step-by-Step
- Install:
pip install pyod. - Prepare data as NumPy arrays or Pandas DataFrames.
- Choose an algorithm:
IForest(),LOF(), etc. - Train:
model.fit(X_train). - Predict:
model.predict(X_test)returns 0 (normal) or 1 (anomaly). - Get scores:
model.decision_scores_provides continuous anomaly scores.
Python Example
import numpy as np
from pyod.models.iforest import IForest
from pyod.models.lof import LOF
from pyod.models.combination import average
# Generate mock data
np.random.seed(42)
X_train = np.random.randn(1000, 5)
X_test = np.vstack([np.random.randn(950, 5),
np.random.uniform(low=10, high=20, size=(50, 5))])
# IForest detection
clf_if = IForest(contamination=0.05, random_state=42)
clf_if.fit(X_train)
y_pred_if = clf_if.predict(X_test)
# LOF detection
clf_lof = LOF(contamination=0.05)
clf_lof.fit(X_train)
y_pred_lof = clf_lof.predict(X_test)
# Combine detectors (average method)
combined = average(clf_if.decision_scores_, clf_lof.decision_scores_)
combined_pred = (combined > np.percentile(combined, 95)).astype(int)
print(f"IForest detected {y_pred_if.sum()} anomalies")
print(f"LOF detected {y_pred_lof.sum()} anomalies")
print(f"Combined detected {combined_pred.sum()} anomalies")
Recommended Use Cases
- Researchers needing flexible algorithm selection
- Offline detection systems on local or edge devices
- Tabular data anomaly detection with 50+ algorithm options
5. Python Alibi Detect Library (Deep Learning + Drift Detection)
Alibi Detect is an open-source library from Seldon focused on deep learning anomaly detection and data drift monitoring. It supports TensorFlow and PyTorch backends and includes data drift, concept drift, and adversarial detection capabilities.
| Feature | Value |
|---|---|
| Free quota | Unlimited (your compute) |
| Algorithms | Isolation Forest, Mahalanobis, AutoEncoder, VAE, Prophet, SR, etc. |
| Data types | Time series, tabular, images, text |
| Special features | Data drift detection, concept drift, adversarial detection |
| Response time | Depends on backend and hardware |
| Commercial use | Apache-2.0 |
Step-by-Step
- Install:
pip install alibi-detect. - Prepare data as NumPy arrays.
- Choose a detector:
OutlierVAE,IsolationForest, orProphet. - Train:
detector.fit(X). - Predict:
detector.predict(X)returns anomaly flags and scores.
Python Example
import numpy as np
from alibi_detect.od import OutlierVAE
# Generate mock data
np.random.seed(42)
X_train = np.random.randn(2000, 10).astype("float32")
X_test = np.vstack([
np.random.randn(900, 10).astype("float32"),
np.random.uniform(low=5, high=15, size=(100, 10)).astype("float32")
])
# Initialize VAE anomaly detector
od = OutlierVAE(threshold=2.0, latent_dim=5, samples=10, input_shape=(10,))
# Train
od.fit(X_train, epochs=10, batch_size=32, verbose=True)
# Predict
preds = od.predict(X_test)
anomaly_flags = preds["data"]["is_outlier"]
anomaly_scores = preds["data"]["instance_score"]
print(f"Detected {anomaly_flags.sum()} anomalies")
print(f"Top 10 scores: {anomaly_scores[:10]}")
Recommended Use Cases
- Deep learning anomaly detection on images or text
- MLOps data drift monitoring in production pipelines
- Adversarial sample detection for model security
Decision Tree: Which Anomaly Detection Should You Pick?
Decision Tree Steps:
- Deployment preference — If you want managed cloud, go to Options 1–3. If you prefer self-hosting, go to Options 4–5.
- Cloud platform — Already on AWS? Choose Option 2. Already on Azure? Choose Option 3. Otherwise, Hugging Face.
- Deep learning needs — If you need VAE, AutoEncoder, or drift detection, choose Alibi Detect (Option 5).
- Algorithm flexibility — For 50+ algorithm options on tabular data, PyOD (Option 4) is the best choice.
Evaluation Metrics for Anomaly Detection
Anomaly detection evaluation differs from standard classification. Here are the key metrics:
| Metric | Meaning | Best For |
|---|---|---|
| Precision | Fraction of true anomalies among predicted anomalies | High alert cost (false positive is costly) |
| Recall | Fraction of true anomalies detected | High miss cost (e.g., fraud detection) |
| F1-Score | Harmonic mean of Precision and Recall | Balanced evaluation |
| ROC-AUC | Area under ROC curve across thresholds | Model comparison |
| PR-AUC | Area under Precision-Recall curve | Extreme class imbalance |
| Detection Latency | Time from anomaly occurrence to alert | Real-time monitoring |
Best Practices
- In extreme imbalance scenarios, prioritize PR-AUC over ROC-AUC.
- In ops monitoring, prioritize Recall (no missed anomalies) and detection latency.
- In fraud detection, balance Precision and Recall, optimizing for F1-Score.
Conclusion
Anomaly detection is an indispensable capability for data-driven businesses. From Hugging Face's hosted model inference, to PyOD's 50+ algorithm library, to Alibi Detect's deep learning and drift detection support, there is a zero-cost solution for every use case. The key is understanding your data characteristics, choosing the right algorithm, and establishing a scientific evaluation framework.
For a continuously updated list of free APIs across NLP, vision, voice, and beyond, bookmark our free API directory. And if you'd like to save your favorite endpoints and receive quota-change alerts, register a free apishare.cc account today.