---
title: 시계열 이상 조사
description: 메트릭 시계열 요청에서 가장 심각한 이상을 조사하고 결정론적 결과를 반환합니다. 그룹화 여부와 관계없이 메트릭 쿼리가 지원됩니다. 이 API 버전은 정확히 하나의 요청을 수락하며 최대 하나의 이상을 반환합니다.
breadcrumbs: 문서 > API > 시계열 이상 조사
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/llms.txt).

# 시계열 이상 조사

## v2 (latest)

{% alert level="warning" %}
**Note**: This endpoint is in preview and is subject to change.
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help.md).
{% /alert %}

| Datadog site      | API endpoint                                                                |
| ----------------- | --------------------------------------------------------------------------- |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/timeseries-anomaly-investigations     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/timeseries-anomaly-investigations |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/timeseries-anomaly-investigations |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/timeseries-anomaly-investigations      |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/timeseries-anomaly-investigations |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/timeseries-anomaly-investigations |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/timeseries-anomaly-investigations |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/timeseries-anomaly-investigations      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/timeseries-anomaly-investigations  |

### Overview

메트릭 시계열 요청에서 가장 심각한 이상을 조사하고 결정론적 결과를 반환합니다.
그룹화 여부와 관계없이 메트릭 쿼리가 지원됩니다. 이 API 버전은 정확히 하나의 요청을 수락하며 최대 하나의 이상을 반환합니다.

This endpoint requires all of the following permissions:

- `timeseries_query`
- `metrics_read`

OAuth apps require the `timeseries_query`, `metrics_read` authorization [scope](https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/ko/api/latest/scopes.md#timeseries-anomaly-investigations) to access this endpoint.

### Request

#### Body Data (required)

조사할 메트릭 시계열 요청입니다. 요청 본문은 2MiB를 초과할 수 없습니다.

{% tabs %}
{% tab label="Model" %}
| Parent field | Field                    | Type     | Description                                                                                                                                                                                                                                                               |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|              | data [*required*]        | object   | 메트릭 시계열의 이상을 조사하도록 요청합니다.                                                                                                                                                                                                                                                 |
| data         | attributes [*required*]  | object   | Attributes of an anomaly investigation request.                                                                                                                                                                                                                           |
| attributes   | requests [*required*]    | [object] | Timeseries requests to investigate. This API version accepts exactly one request.                                                                                                                                                                                         |
| requests     | formulas [*required*]    | [object] | Formulas to evaluate. Each formula may contain an explicit `anomalies()` call or a supported metrics expression.                                                                                                                                                          |
| formulas     | formula [*required*]     | string   | Formula expression referencing one or more named queries. When the expression does not contain an explicit `anomalies()` call, the endpoint applies the default Watchdog Explains anomaly detection configuration.                                                        |
| formulas     | limit                    | object   | Optional formula limit accepted for compatibility with Timeseries API requests. Formula limits have no effect on timeseries queries.                                                                                                                                      |
| limit        | count                    | int64    | Requested result limit. This field has no effect on a timeseries anomaly investigation.                                                                                                                                                                                   |
| limit        | order                    | enum     | Sort order used when applying a formula series limit. Allowed enum values: `asc`, `desc`.                                                                                                                                                                                 |
| requests     | from [*required*]        | int64    | Start of the investigation time window in milliseconds since the Unix epoch.                                                                                                                                                                                              |
| requests     | interval                 | int64    | Optional requested aggregation interval in milliseconds.                                                                                                                                                                                                                  |
| requests     | queries [*required*]     | [object] | Metrics queries referenced by the formulas.                                                                                                                                                                                                                               |
| queries      | aggregator               | string   | Optional scalar aggregator accepted for request compatibility. This field is ignored for timeseries queries.                                                                                                                                                              |
| queries      | cross_org_uuids          | [string] | Optional organization UUID used for a cross-organization query. Each query accepts at most one UUID; use separate queries for separate organizations. Influential-tag analysis is currently unsupported for cross-organization queries, but anomaly detection still runs. |
| queries      | data_source [*required*] | enum     | Data source for an anomaly investigation query. Allowed enum values: `metrics`.                                                                                                                                                                                           |
| queries      | name [*required*]        | string   | Name used to reference this query from formulas.                                                                                                                                                                                                                          |
| queries      | query [*required*]       | string   | Datadog metrics query expression.                                                                                                                                                                                                                                         |
| requests     | to [*required*]          | int64    | End of the investigation time window in milliseconds since the Unix epoch. Must be later than `from`.                                                                                                                                                                     |
| data         | type [*required*]        | enum     | Resource type for a timeseries anomaly investigation. Allowed enum values: `timeseries_anomaly_investigation`.                                                                                                                                                            |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "requests": [
        {
          "formulas": [
            {
              "formula": "query1",
              "limit": {
                "count": 10,
                "order": "desc"
              }
            }
          ],
          "from": 1754406000000,
          "interval": 60000,
          "queries": [
            {
              "aggregator": "avg",
              "cross_org_uuids": [
                "00000000-0000-0000-0000-000000000000"
              ],
              "data_source": "metrics",
              "name": "query1",
              "query": "avg:system.cpu.user{env:prod} by {service}"
            }
          ],
          "to": 1754423940000
        }
      ]
    },
    "type": "timeseries_anomaly_investigation"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="200" %}
OK

{% tabs %}
{% tab label="Model" %}
Response containing the anomaly investigation results and timeseries metadata.

| Parent field           | Field                             | Type      | Description                                                                                                                                                                                    |
| ---------------------- | --------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                        | data [*required*]                 | object    | JSON:API resource containing anomaly investigation results.                                                                                                                                    |
| data                   | attributes [*required*]           | object    | Attributes of an anomaly investigation response.                                                                                                                                               |
| attributes             | results [*required*]              | [object]  | Results returned in the same order as the submitted requests. This API version returns exactly one result.                                                                                     |
| results                | anomalies [*required*]            | [object]  | Detected anomalies, ordered by significance. This API version returns at most three anomalies across the submitted request.                                                                    |
| anomalies              | anomaly_detection [*required*]    | object    | Anomaly detection configuration used for the result.                                                                                                                                           |
| anomaly_detection      | configuration_source [*required*] | enum      | Source of the anomaly detection configuration. Allowed enum values: `request_formula`, `watchdog_explains_default`.                                                                            |
| anomaly_detection      | profile [*required*]              | string    | Applied Watchdog Explains profile, or null when the request supplied an explicit `anomalies()` formula. The current Watchdog profile is `watchdog_explains_v1`.                                |
| anomalies              | detected_interval [*required*]    | object    | Inclusive time interval in milliseconds since the Unix epoch.                                                                                                                                  |
| detected_interval      | end [*required*]                  | int64     | Timestamp of the final point in the interval.                                                                                                                                                  |
| detected_interval      | start [*required*]                | int64     | Inclusive start of the interval.                                                                                                                                                               |
| anomalies              | display_interval [*required*]     | object    | Inclusive time interval in milliseconds since the Unix epoch.                                                                                                                                  |
| display_interval       | end [*required*]                  | int64     | Timestamp of the final point in the interval.                                                                                                                                                  |
| display_interval       | start [*required*]                | int64     | Inclusive start of the interval.                                                                                                                                                               |
| anomalies              | findings [*required*]             | [<oneOf>] | Deterministic explanations for the anomaly, ordered by importance.                                                                                                                             |
| findings               | <type=influential_tag>            | object    | Finding that attributes an anomaly to an influential tag.                                                                                                                                      |
| <type=influential_tag> | description [*required*]          | string    | Deterministic explanation of the finding.                                                                                                                                                      |
| <type=influential_tag> | headline [*required*]             | string    | Concise, deterministic finding title.                                                                                                                                                          |
| <type=influential_tag> | tag [*required*]                  | object    | Structured tag evidence for an influential-tag finding.                                                                                                                                        |
| tag                    | influence_type [*required*]       | enum      | Kind of influence a tag has on a series. Allowed enum values: `shape`, `value`.                                                                                                                |
| tag                    | key [*required*]                  | string    | Influential tag key.                                                                                                                                                                           |
| tag                    | rating [*required*]               | double    | Influence rating from 1 through 5.                                                                                                                                                             |
| tag                    | synonyms [*required*]             | [object]  | Tags grouped with this tag by Variation of Influence synonym analysis.                                                                                                                         |
| synonyms               | key [*required*]                  | string    | Synonymous tag key.                                                                                                                                                                            |
| synonyms               | values [*required*]               | [string]  | Values associated with the synonymous tag.                                                                                                                                                     |
| tag                    | values [*required*]               | [string]  | Influential values for the tag key.                                                                                                                                                            |
| <type=influential_tag> | type [*required*]                 | enum      | Finding category for an influential tag. Allowed enum values: `influential_tag`.                                                                                                               |
| findings               | <type=anomaly>                    | object    | Finding that describes the anomaly when completed analysis produces no displayable influential tags.                                                                                           |
| <type=anomaly>         | description [*required*]          | string    | Deterministic explanation of the finding.                                                                                                                                                      |
| <type=anomaly>         | headline [*required*]             | string    | Concise, deterministic finding title.                                                                                                                                                          |
| <type=anomaly>         | type [*required*]                 | enum      | Finding category for an anomaly without a displayable influential tag. Allowed enum values: `anomaly`.                                                                                         |
| anomalies              | maximum_deviation [*required*]    | object    | Most anomalous point within the detected interval.                                                                                                                                             |
| maximum_deviation      | delta_from_boundary [*required*]  | double    | Absolute distance between the observed value and the nearest anomaly boundary.                                                                                                                 |
| maximum_deviation      | timestamp [*required*]            | int64     | Point timestamp in milliseconds since the Unix epoch.                                                                                                                                          |
| maximum_deviation      | value [*required*]                | double    | Observed value at the point.                                                                                                                                                                   |
| anomalies              | series [*required*]               | object    | Logical series on which the anomaly was detected.                                                                                                                                              |
| series                 | group_tags [*required*]           | [string]  | Tags identifying the selected group. Empty for a query without grouping.                                                                                                                       |
| series                 | label [*required*]                | string    | Display label for the selected series.                                                                                                                                                         |
| series                 | query_index [*required*]          | int64     | Zero-based index of the caller's formula that produced the series.                                                                                                                             |
| anomalies              | tag_analysis [*required*]         | object    | Summary of optional influential-tag enrichment. Count and key fields are present only when analysis completes; enrichment availability does not affect completion of the investigation result. |
| tag_analysis           | analyzed_tag_keys                 | [string]  | Tag keys analyzed. Present only when analysis completes.                                                                                                                                       |
| tag_analysis           | status [*required*]               | enum      | Outcome of optional influential-tag enrichment. Allowed enum values: `complete`, `unsupported`, `failed`.                                                                                      |
| tag_analysis           | tag_keys_analyzed                 | int64     | Number of tag keys analyzed. Present only when analysis completes.                                                                                                                             |
| tag_analysis           | tag_values_analyzed               | int64     | Number of tag values analyzed. Present only when analysis completes.                                                                                                                           |
| anomalies              | type [*required*]                 | enum      | Direction of an anomaly relative to its expected range. Allowed enum values: `spike`, `dip`.                                                                                                   |
| results                | status [*required*]               | enum      | Status value indicating successful completion. Allowed enum values: `complete`.                                                                                                                |
| data                   | id [*required*]                   | enum      | Stable identifier for an anomaly investigation response resource. Allowed enum values: `0`.                                                                                                    |
| data                   | type [*required*]                 | enum      | Resource type for a timeseries anomaly investigation. Allowed enum values: `timeseries_anomaly_investigation`.                                                                                 |
|                        | meta [*required*]                 | object    | Timeseries execution metadata for the single request accepted by this API version.                                                                                                             |
| meta                   | from_date [*required*]            | int64     | Effective start of the timeseries query in milliseconds since the Unix epoch.                                                                                                                  |
| meta                   | interval [*required*]             | int64     | Effective timeseries interval in milliseconds.                                                                                                                                                 |
| meta                   | queries [*required*]              | [object]  | Execution status for the request's queries.                                                                                                                                                    |
| queries                | name [*required*]                 | string    | Query name from the request.                                                                                                                                                                   |
| queries                | status [*required*]               | enum      | Current execution status for a named query. Allowed enum values: `running`, `done`.                                                                                                            |
| meta                   | res_type [*required*]             | enum      | Response metadata type for a timeseries anomaly investigation. Allowed enum values: `timeseries_anomaly_investigation`.                                                                        |
| meta                   | results_warnings [*required*]     | [object]  | Non-fatal warnings produced while executing the investigation.                                                                                                                                 |
| results_warnings       | message [*required*]              | string    | Human-readable warning message.                                                                                                                                                                |
| results_warnings       | name [*required*]                 | string    | Machine-readable warning name.                                                                                                                                                                 |
| meta                   | to_date [*required*]              | int64     | Effective end of the timeseries query in milliseconds since the Unix epoch.                                                                                                                    |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "results": [
        {
          "anomalies": [
            {
              "anomaly_detection": {
                "configuration_source": "request_formula",
                "profile": null
              },
              "detected_interval": {
                "end": 1754406120000,
                "start": 1754406060000
              },
              "display_interval": {
                "end": 1754406120000,
                "start": 1754406060000
              },
              "findings": [
                []
              ],
              "maximum_deviation": {
                "delta_from_boundary": 7,
                "timestamp": 1754406090000,
                "value": 42
              },
              "series": {
                "group_tags": [
                  "service:api"
                ],
                "label": "api",
                "query_index": 0
              },
              "tag_analysis": {
                "analyzed_tag_keys": [
                  "service",
                  "env"
                ],
                "status": "complete",
                "tag_keys_analyzed": 2,
                "tag_values_analyzed": 4
              },
              "type": "spike"
            }
          ],
          "status": "complete"
        }
      ]
    },
    "id": "0",
    "type": "timeseries_anomaly_investigation"
  },
  "meta": {
    "from_date": 1754406000000,
    "interval": 60000,
    "queries": [
      {
        "name": "query1",
        "status": "done"
      }
    ],
    "res_type": "timeseries_anomaly_investigation",
    "results_warnings": [
      {
        "message": "Influential tag analysis failed for at least one detected anomaly.",
        "name": "tag_analysis_failed"
      }
    ],
    "to_date": 1754423940000
  }
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="401" %}
Unauthorized

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="403" %}
Forbidden

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="413" %}
Payload Too Large

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="422" %}
Unprocessable Entity

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/timeseries-anomaly-investigations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "requests": [
        {
          "formulas": [
            {
              "formula": "query1"
            }
          ],
          "from": 1754406000000,
          "queries": [
            {
              "data_source": "metrics",
              "name": "query1",
              "query": "avg:system.cpu.user{env:prod} by {service}"
            }
          ],
          "to": 1754423940000
        }
      ]
    },
    "type": "timeseries_anomaly_investigation"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Investigate a timeseries anomaly returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.TimeseriesAnomalyInvestigationRequest{
		Data: datadogV2.TimeseriesAnomalyInvestigationRequestData{
			Attributes: datadogV2.TimeseriesAnomalyInvestigationRequestAttributes{
				Requests: []datadogV2.TimeseriesAnomalyInvestigationTimeseriesRequest{
					{
						Formulas: []datadogV2.TimeseriesAnomalyInvestigationFormula{
							{
								Formula: "query1",
							},
						},
						From: 1754406000000,
						Queries: []datadogV2.TimeseriesAnomalyInvestigationMetricQuery{
							{
								DataSource: datadogV2.TIMESERIESANOMALYINVESTIGATIONDATASOURCE_METRICS,
								Name:       "query1",
								Query:      "avg:system.cpu.user{env:prod} by {service}",
							},
						},
						To: 1754423940000,
					},
				},
			},
			Type: datadogV2.TIMESERIESANOMALYINVESTIGATIONTYPE_TIMESERIES_ANOMALY_INVESTIGATION,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.CreateTimeseriesAnomalyInvestigation", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewTimeseriesAnomalyInvestigationsApi(apiClient)
	resp, r, err := api.CreateTimeseriesAnomalyInvestigation(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `TimeseriesAnomalyInvestigationsApi.CreateTimeseriesAnomalyInvestigation`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `TimeseriesAnomalyInvestigationsApi.CreateTimeseriesAnomalyInvestigation`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"
```
{% /tab %}

{% tab label="Java" %}
```java
// Investigate a timeseries anomaly returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.TimeseriesAnomalyInvestigationsApi;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationDataSource;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationFormula;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationMetricQuery;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationRequest;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationRequestAttributes;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationRequestData;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationResponse;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationTimeseriesRequest;
import com.datadog.api.client.v2.model.TimeseriesAnomalyInvestigationType;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
    defaultClient.setUnstableOperationEnabled("v2.createTimeseriesAnomalyInvestigation", true);
    TimeseriesAnomalyInvestigationsApi apiInstance =
        new TimeseriesAnomalyInvestigationsApi(defaultClient);

    TimeseriesAnomalyInvestigationRequest body =
        new TimeseriesAnomalyInvestigationRequest()
            .data(
                new TimeseriesAnomalyInvestigationRequestData()
                    .attributes(
                        new TimeseriesAnomalyInvestigationRequestAttributes()
                            .requests(
                                Collections.singletonList(
                                    new TimeseriesAnomalyInvestigationTimeseriesRequest()
                                        .formulas(
                                            Collections.singletonList(
                                                new TimeseriesAnomalyInvestigationFormula()
                                                    .formula("query1")))
                                        .from(1754406000000L)
                                        .queries(
                                            Collections.singletonList(
                                                new TimeseriesAnomalyInvestigationMetricQuery()
                                                    .dataSource(
                                                        TimeseriesAnomalyInvestigationDataSource
                                                            .METRICS)
                                                    .name("query1")
                                                    .query(
                                                        "avg:system.cpu.user{env:prod} by"
                                                            + " {service}")))
                                        .to(1754423940000L))))
                    .type(TimeseriesAnomalyInvestigationType.TIMESERIES_ANOMALY_INVESTIGATION));

    try {
      TimeseriesAnomalyInvestigationResponse result =
          apiInstance.createTimeseriesAnomalyInvestigation(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println(
          "Exception when calling"
              + " TimeseriesAnomalyInvestigationsApi#createTimeseriesAnomalyInvestigation");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"
```
{% /tab %}

{% tab label="Python" %}
```python
"""
Investigate a timeseries anomaly returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.timeseries_anomaly_investigations_api import TimeseriesAnomalyInvestigationsApi
from datadog_api_client.v2.model.timeseries_anomaly_investigation_data_source import (
    TimeseriesAnomalyInvestigationDataSource,
)
from datadog_api_client.v2.model.timeseries_anomaly_investigation_formula import TimeseriesAnomalyInvestigationFormula
from datadog_api_client.v2.model.timeseries_anomaly_investigation_metric_query import (
    TimeseriesAnomalyInvestigationMetricQuery,
)
from datadog_api_client.v2.model.timeseries_anomaly_investigation_request import TimeseriesAnomalyInvestigationRequest
from datadog_api_client.v2.model.timeseries_anomaly_investigation_request_attributes import (
    TimeseriesAnomalyInvestigationRequestAttributes,
)
from datadog_api_client.v2.model.timeseries_anomaly_investigation_request_data import (
    TimeseriesAnomalyInvestigationRequestData,
)
from datadog_api_client.v2.model.timeseries_anomaly_investigation_timeseries_request import (
    TimeseriesAnomalyInvestigationTimeseriesRequest,
)
from datadog_api_client.v2.model.timeseries_anomaly_investigation_type import TimeseriesAnomalyInvestigationType

body = TimeseriesAnomalyInvestigationRequest(
    data=TimeseriesAnomalyInvestigationRequestData(
        attributes=TimeseriesAnomalyInvestigationRequestAttributes(
            requests=[
                TimeseriesAnomalyInvestigationTimeseriesRequest(
                    formulas=[
                        TimeseriesAnomalyInvestigationFormula(
                            formula="query1",
                        ),
                    ],
                    _from=1754406000000,
                    queries=[
                        TimeseriesAnomalyInvestigationMetricQuery(
                            data_source=TimeseriesAnomalyInvestigationDataSource.METRICS,
                            name="query1",
                            query="avg:system.cpu.user{env:prod} by {service}",
                        ),
                    ],
                    to=1754423940000,
                ),
            ],
        ),
        type=TimeseriesAnomalyInvestigationType.TIMESERIES_ANOMALY_INVESTIGATION,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
configuration.unstable_operations["create_timeseries_anomaly_investigation"] = True
with ApiClient(configuration) as api_client:
    api_instance = TimeseriesAnomalyInvestigationsApi(api_client)
    response = api_instance.create_timeseries_anomaly_investigation(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"
```
{% /tab %}

{% tab label="Ruby" %}
```ruby
# Investigate a timeseries anomaly returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.access_token = ENV["DD_BEARER_TOKEN"]
  config.unstable_operations["v2.create_timeseries_anomaly_investigation".to_sym] = true
end
api_instance = DatadogAPIClient::V2::TimeseriesAnomalyInvestigationsAPI.new

body = DatadogAPIClient::V2::TimeseriesAnomalyInvestigationRequest.new({
  data: DatadogAPIClient::V2::TimeseriesAnomalyInvestigationRequestData.new({
    attributes: DatadogAPIClient::V2::TimeseriesAnomalyInvestigationRequestAttributes.new({
      requests: [
        DatadogAPIClient::V2::TimeseriesAnomalyInvestigationTimeseriesRequest.new({
          formulas: [
            DatadogAPIClient::V2::TimeseriesAnomalyInvestigationFormula.new({
              formula: "query1",
            }),
          ],
          from: 1754406000000,
          queries: [
            DatadogAPIClient::V2::TimeseriesAnomalyInvestigationMetricQuery.new({
              data_source: DatadogAPIClient::V2::TimeseriesAnomalyInvestigationDataSource::METRICS,
              name: "query1",
              query: "avg:system.cpu.user{env:prod} by {service}",
            }),
          ],
          to: 1754423940000,
        }),
      ],
    }),
    type: DatadogAPIClient::V2::TimeseriesAnomalyInvestigationType::TIMESERIES_ANOMALY_INVESTIGATION,
  }),
})
p api_instance.create_timeseries_anomaly_investigation(body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"
```
{% /tab %}

{% tab label="Rust" %}
```rust
// Investigate a timeseries anomaly returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_timeseries_anomaly_investigations::TimeseriesAnomalyInvestigationsAPI;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationDataSource;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationFormula;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationMetricQuery;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationRequest;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationRequestAttributes;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationRequestData;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationTimeseriesRequest;
use datadog_api_client::datadogV2::model::TimeseriesAnomalyInvestigationType;

#[tokio::main]
async fn main() {
    let body =
        TimeseriesAnomalyInvestigationRequest::new(TimeseriesAnomalyInvestigationRequestData::new(
            TimeseriesAnomalyInvestigationRequestAttributes::new(vec![
                TimeseriesAnomalyInvestigationTimeseriesRequest::new(
                    vec![TimeseriesAnomalyInvestigationFormula::new(
                        "query1".to_string(),
                    )],
                    1754406000000,
                    vec![TimeseriesAnomalyInvestigationMetricQuery::new(
                        TimeseriesAnomalyInvestigationDataSource::METRICS,
                        "query1".to_string(),
                        "avg:system.cpu.user{env:prod} by {service}".to_string(),
                    )],
                    1754423940000,
                ),
            ]),
            TimeseriesAnomalyInvestigationType::TIMESERIES_ANOMALY_INVESTIGATION,
        ));
    let mut configuration = datadog::Configuration::new();
    configuration
        .set_unstable_operation_enabled("v2.create_timeseries_anomaly_investigation", true);
    let api = TimeseriesAnomalyInvestigationsAPI::with_config(configuration);
    let resp = api.create_timeseries_anomaly_investigation(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
```
{% /tab %}

{% tab label="TypeScript" %}
```typescript
/**
 * Investigate a timeseries anomaly returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration({
  authMethods: {
    AuthZ: {
      accessToken: process.env.DD_BEARER_TOKEN as string,
    },
  },
});
configuration.unstableOperations["v2.createTimeseriesAnomalyInvestigation"] =
  true;
const apiInstance = new v2.TimeseriesAnomalyInvestigationsApi(configuration);

const params: v2.TimeseriesAnomalyInvestigationsApiCreateTimeseriesAnomalyInvestigationRequest =
  {
    body: {
      data: {
        attributes: {
          requests: [
            {
              formulas: [
                {
                  formula: "query1",
                },
              ],
              from: 1754406000000,
              queries: [
                {
                  dataSource: "metrics",
                  name: "query1",
                  query: "avg:system.cpu.user{env:prod} by {service}",
                },
              ],
              to: 1754423940000,
            },
          ],
        },
        type: "timeseries_anomaly_investigation",
      },
    },
  };

apiInstance
  .createTimeseriesAnomalyInvestigation(params)
  .then((data: v2.TimeseriesAnomalyInvestigationResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"
```
{% /tab %}
{% /tabs %}
