---
title: "Backtest an anomaly detector over a time range without saving a rule."
method: POST
path: "/otel/alerts/preview"
tags: ["Alerts"]
---

# Backtest an anomaly detector over a time range without saving a rule.

`POST /otel/alerts/preview`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/otel/alerts/preview`
- Auth: HTTP bearer

Replays the metric against the same band the evaluator would use, returning
the per-bucket band + which points would have fired. Powers the form's
"would this have fired?" preview and the explorer band overlay. Read-only.

## Request body

- AnomalyPreviewRequest
  - `aggregation` string, required: One of `avg|sum|min|max|count|rate|p50|p90|p95|p99`.
  - `detection_config` union, required: The detector to backtest. `static` and `anomaly` are supported — the kinds the evaluator actually runs.
    - object: v0 (shipping): static threshold comparison of the aggregated value.
      - `comparator` 'gt' | 'gte' | 'lt' | 'lte', required: How `value` is compared against `threshold`.
      - `threshold` number, double, required: The threshold the aggregated value is compared against.
      - `kind` 'static', required
    - object: Seasonal anomaly band (basic/agile/robust/ewma share this variant — the algorithm is a field, not a new kind). Creation rejected until evaluated.
      - `algorithm` 'robust' | 'basic' | 'agile' | 'ewma': Baseline model. `robust` is the default (seasonal, stable, flags level shifts); `ewma`/`agile` adopt level shifts; `basic` is non-seasonal.
      - `baseline_lookback_days` integer, nullable: How far back to build the baseline. `None` = an evaluator default.
      - `deviations` number, double: Band width in robust standard deviations (Datadog's `bounds`).
      - `direction` 'both' | 'above' | 'below': Which side(s) of the band a deviation must be on to count.
      - `pct_anomalous` number, double: Fraction (0..=1) of points in the window that must be anomalous to fire.
      - `seasonality` 'none' | 'hourly' | 'daily' | 'weekly': Seasonality model for the baseline.
      - `kind` 'anomaly', required
    - object: Predict a future threshold breach (capacity planning). Stub.
      - `algorithm` 'linear' | 'seasonal': Forecast model family.
      - `comparator` 'gt' | 'gte' | 'lt' | 'lte', required: Comparator + threshold the *forecast* is checked against.
      - `deviations` number, double
      - `forecast_horizon_secs` integer, required: How far ahead to project before checking the breach condition.
      - `threshold` number, double, required
      - `kind` 'forecast', required
    - object: Cross-series population outlier (one host misbehaving vs its peers). Stub.
      - `algorithm` 'dbscan' | 'scaled_dbscan' | 'mad' | 'scaled_mad': Outlier detection algorithm.
      - `peer_group_key` string, required: Label key defining the peer population compared across series (e.g. `host`).
      - `tolerance` number, double: Sensitivity; higher tolerates larger spread before flagging.
      - `kind` 'outlier', required
    - object: Watchdog-style self-tuning auto-watch (engine picks bounds). Stub.
      - `direction` 'both' | 'above' | 'below': The engine self-tunes the band; the user supplies only the direction.
      - `kind` 'auto_watch', required
  - `end_time` string, nullable: RFC 3339; defaults to now.
  - `metric_name` string, required
  - `project_id` integer, required
  - `start_time` string, nullable: RFC 3339; defaults to 7 days before `end_time`.
  - `window_secs` integer, required

## Response `200`

Per-bucket band + breach points

- AnomalyPreviewResponse
  - `baseline_samples` integer, required: Baseline sample count (drives the `sufficient` flag).
  - `breach_count` integer, required: How many points in the range would have fired.
  - `points` AnomalyPreviewPointResponse[], required
    - `breaching` boolean, required
    - `bucket` string, required
    - `lower` number, double, required: Lower edge of the expected band at this point.
    - `upper` number, double, required: Upper edge of the expected band at this point.
    - `value` number, double, required
  - `sufficient` boolean, required: Whether the baseline had enough history for a trustworthy band.

## Other responses

- `400`: Not an anomaly detector / bad input
- `401`: Unauthorized
- `403`: Insufficient permissions
- `500`: Internal server error

## Changes

- **2026-11-09** `12896146b193`: 4 breaking
  - removed the required property `extensions` from the response with the `400` status
  - removed the required property `extensions` from the response with the `401` status
  - removed the required property `extensions` from the response with the `403` status
  - removed the required property `extensions` from the response with the `500` status
- **2026-10-05** `4b228ebed583`: 4 info
  - added the optional property `status` to the response with the `400` status
  - added the optional property `status` to the response with the `401` status
  - added the optional property `status` to the response with the `403` status
  - added the optional property `status` to the response with the `500` status
- **2026-10-05** `63a80791dc58`: 4 warning
  - removed the optional property `status` from the response with the `400` status
  - removed the optional property `status` from the response with the `401` status
  - removed the optional property `status` from the response with the `403` status
  - removed the optional property `status` from the response with the `500` status
- **2026-09-23** `f4efc4d5c7b7`: 4 info
  - added the optional property `status` to the response with the `400` status
  - added the optional property `status` to the response with the `401` status
  - added the optional property `status` to the response with the `403` status
  - added the optional property `status` to the response with the `500` status
- …earlier changes not shown

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/otel/alerts/preview/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
