---
title: Create an SLO object
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Service Level Objectives
---

# Create an SLO object{% #create-an-slo-object %}
Copy pageCopied
{% tab title="v1" %}

| Datadog site      | API endpoint                                  |
| ----------------- | --------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v1/slo |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v1/slo |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v1/slo      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v1/slo      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v1/slo  |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v1/slo     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v1/slo |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v1/slo |

### Overview

Create a service level objective object. This endpoint requires the `slos_write` permission.

OAuth apps require the `slos_write` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#service-level-objectives) to access this endpoint.



### Request

#### Body Data (required)

Service level objective request object.

{% tab title="Model" %}

| Parent field         | Field                                  | Type            | Description                                                                                                                                                                                                                                                                                                             |
| -------------------- | -------------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                      | description                            | string          | A user-defined description of the service level objective.                                                                                                                                                                                                                                                              | Always included in service level objective responses (but may be `null`). Optional in create/update requests.                                                                                                       |
|                      | groups                                 | [string]        | A list of (up to 100) monitor groups that narrow the scope of a monitor service level objective.                                                                                                                                                                                                                        | Included in service level objective responses if it is not empty. Optional in create/update requests for monitor service level objectives, but may only be used when then length of the `monitor_ids` field is one. |
|                      | monitor_ids                            | [integer]       | A list of monitor IDs that defines the scope of a monitor service level objective. **Required if type is `monitor`**.                                                                                                                                                                                                   |
|                      | name [*required*]                 | string          | The name of the service level objective object.                                                                                                                                                                                                                                                                         |
|                      | query                                  | object          | A count-based (metric) SLO query. This field is superseded by `sli_specification` but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or min of all of those requests. |
| query                | denominator [*required*]          | string          | A Datadog metric query for total (valid) events.                                                                                                                                                                                                                                                                        |
| query                | numerator [*required*]            | string          | A Datadog metric query for good events.                                                                                                                                                                                                                                                                                 |
|                      | sli_specification                      |  <oneOf>   | A generic SLI specification. This is used for time-slice and count-based (metric) SLOs only.                                                                                                                                                                                                                            |
| sli_specification    | Option 1                               | object          | A time-slice SLI specification.                                                                                                                                                                                                                                                                                         |
| Option 1             | time_slice [*required*]           | object          | The time-slice condition, composed of 3 parts: 1. the metric timeseries query, 2. the comparator, and 3. the threshold. Optionally, a fourth part, the query interval, can be provided.                                                                                                                                 |
| time_slice           | comparator [*required*]           | enum            | The comparator used to compare the SLI value to the threshold. Allowed enum values: `>,>=,<,<=`                                                                                                                                                                                                                         |
| time_slice           | query [*required*]                | object          | The queries and formula used to calculate the SLI value.                                                                                                                                                                                                                                                                |
| query                | formulas [*required*]             | [object]        | A list that contains exactly one formula, as only a single formula may be used in a time-slice SLO.                                                                                                                                                                                                                     |
| formulas             | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                     |
| query                | queries [*required*]              | [ <oneOf>] | A list of queries that are used to calculate the SLI value.                                                                                                                                                                                                                                                             |
| queries              | Option 1                               | object          | A formula and functions metrics query.                                                                                                                                                                                                                                                                                  |
| Option 1             | aggregator                             | enum            | The aggregation methods available for metrics queries. Allowed enum values: `avg,min,max,sum,last,area,l2norm,percentile`                                                                                                                                                                                               |
| Option 1             | cross_org_uuids                        | [string]        | The source organization UUID for cross organization queries. Feature in Private Beta.                                                                                                                                                                                                                                   |
| Option 1             | data_source [*required*]          | enum            | Data source for metrics queries. Allowed enum values: `metrics`                                                                                                                                                                                                                                                         |
| Option 1             | name [*required*]                 | string          | Name of the query for use in formulas.                                                                                                                                                                                                                                                                                  |
| Option 1             | query [*required*]                | string          | Metrics query definition.                                                                                                                                                                                                                                                                                               |
| Option 1             | semantic_mode                          | enum            | Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. Allowed enum values: `combined,native`                                                                                                                                                                 |
| time_slice           | query_interval_seconds                 | enum            | The interval used when querying data, which defines the size of a time slice. Two values are allowed: 60 (1 minute) and 300 (5 minutes). If not provided, the value defaults to 300 (5 minutes). Allowed enum values: `60,300`                                                                                          |
| time_slice           | threshold [*required*]            | double          | The threshold value to which each SLI value will be compared.                                                                                                                                                                                                                                                           |
| sli_specification    | Option 2                               | object          | A metric SLI specification.                                                                                                                                                                                                                                                                                             |
| Option 2             | count [*required*]                |  <oneOf>   | A count-based (metric) SLI specification, composed of three parts: the good events formula, the bad or total events formula, and the underlying queries. Exactly one of `total_events_formula` or `bad_events_formula` must be provided.                                                                                |
| count                | Option 1                               | object          | SLO count definition using a total events formula alongside a good events formula.                                                                                                                                                                                                                                      |
| Option 1             | good_events_formula [*required*]  | object          | A formula that specifies how to combine the results of multiple queries.                                                                                                                                                                                                                                                |
| good_events_formula  | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                     |
| Option 1             | queries [*required*]              | [ <oneOf>] |
| queries              | Option 1                               | object          | A formula and functions metrics query.                                                                                                                                                                                                                                                                                  |
| Option 1             | aggregator                             | enum            | The aggregation methods available for metrics queries. Allowed enum values: `avg,min,max,sum,last,area,l2norm,percentile`                                                                                                                                                                                               |
| Option 1             | cross_org_uuids                        | [string]        | The source organization UUID for cross organization queries. Feature in Private Beta.                                                                                                                                                                                                                                   |
| Option 1             | data_source [*required*]          | enum            | Data source for metrics queries. Allowed enum values: `metrics`                                                                                                                                                                                                                                                         |
| Option 1             | name [*required*]                 | string          | Name of the query for use in formulas.                                                                                                                                                                                                                                                                                  |
| Option 1             | query [*required*]                | string          | Metrics query definition.                                                                                                                                                                                                                                                                                               |
| Option 1             | semantic_mode                          | enum            | Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. Allowed enum values: `combined,native`                                                                                                                                                                 |
| Option 1             | total_events_formula [*required*] | object          | The total events formula. Bad events queries can be defined using the `bad_events_formula` field as an alternative. Only one of `total_events_formula` or `bad_events_formula` must be provided.                                                                                                                        |
| total_events_formula | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                     |
| count                | Option 2                               | object          | SLO count definition using a bad events formula alongside a good events formula.                                                                                                                                                                                                                                        |
| Option 2             | bad_events_formula [*required*]   | object          | The bad events formula (recommended). Total events queries can be defined using the `total_events_formula` field as an alternative. Only one of `total_events_formula` or `bad_events_formula` must be provided.                                                                                                        |
| bad_events_formula   | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                     |
| Option 2             | good_events_formula [*required*]  | object          | A formula that specifies how to combine the results of multiple queries.                                                                                                                                                                                                                                                |
| good_events_formula  | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                     |
| Option 2             | queries [*required*]              | [ <oneOf>] |
| queries              | Option 1                               | object          | A formula and functions metrics query.                                                                                                                                                                                                                                                                                  |
| Option 1             | aggregator                             | enum            | The aggregation methods available for metrics queries. Allowed enum values: `avg,min,max,sum,last,area,l2norm,percentile`                                                                                                                                                                                               |
| Option 1             | cross_org_uuids                        | [string]        | The source organization UUID for cross organization queries. Feature in Private Beta.                                                                                                                                                                                                                                   |
| Option 1             | data_source [*required*]          | enum            | Data source for metrics queries. Allowed enum values: `metrics`                                                                                                                                                                                                                                                         |
| Option 1             | name [*required*]                 | string          | Name of the query for use in formulas.                                                                                                                                                                                                                                                                                  |
| Option 1             | query [*required*]                | string          | Metrics query definition.                                                                                                                                                                                                                                                                                               |
| Option 1             | semantic_mode                          | enum            | Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. Allowed enum values: `combined,native`                                                                                                                                                                 |
|                      | tags                                   | [string]        | A list of tags associated with this service level objective. Always included in service level objective responses (but may be empty). Optional in create/update requests.                                                                                                                                               |
|                      | target_threshold                       | double          | The target threshold such that when the service level indicator is above this threshold over the given timeframe, the objective is being met.                                                                                                                                                                           |
|                      | thresholds [*required*]           | [object]        | The thresholds (timeframes and associated targets) for this service level objective object.                                                                                                                                                                                                                             |
| thresholds           | target [*required*]               | double          | The target value for the service level indicator within the corresponding timeframe.                                                                                                                                                                                                                                    |
| thresholds           | target_display                         | string          | A string representation of the target that indicates its precision. It uses trailing zeros to show significant decimal places (for example `98.00`).                                                                                                                                                                    | Always included in service level objective responses. Ignored in create/update requests.                                                                                                                            |
| thresholds           | timeframe [*required*]            | enum            | The SLO time window options. Note that "custom" is not a valid option for creating or updating SLOs. It is only used when querying SLO history over custom timeframes. Allowed enum values: `7d,30d,90d,custom`                                                                                                         |
| thresholds           | warning                                | double          | The warning value for the service level objective.                                                                                                                                                                                                                                                                      |
| thresholds           | warning_display                        | string          | A string representation of the warning target (see the description of the `target_display` field for details).                                                                                                                                                                                                          | Included in service level objective responses if a warning target exists. Ignored in create/update requests.                                                                                                        |
|                      | timeframe                              | enum            | The SLO time window options. Note that "custom" is not a valid option for creating or updating SLOs. It is only used when querying SLO history over custom timeframes. Allowed enum values: `7d,30d,90d,custom`                                                                                                         |
|                      | type [*required*]                 | enum            | The type of the service level objective. Allowed enum values: `metric,monitor,time_slice`                                                                                                                                                                                                                               |
|                      | warning_threshold                      | double          | The optional warning threshold such that when the service level indicator is below this value for the given threshold, but above the target threshold, the objective appears in a "warning" state. This value must be greater than the target threshold.                                                                |

{% /tab %}

{% tab title="Example" %}
##### 

```json
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
```

##### 

```json
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
```

##### 

```json
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
A response with one or more service level objective.

| Parent field         | Field                                  | Type            | Description                                                                                                                                                                                                                                                                                                                                                                   |
| -------------------- | -------------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                      | data                                   | [object]        | An array of service level objective objects.                                                                                                                                                                                                                                                                                                                                  |
| data                 | created_at                             | int64           | Creation timestamp (UNIX time in seconds)                                                                                                                                                                                                                                                                                                                                     | Always included in service level objective responses.                                                                                                                                                               |
| data                 | creator                                | object          | Object describing the creator of the shared element.                                                                                                                                                                                                                                                                                                                          |
| creator              | email                                  | string          | Email of the creator.                                                                                                                                                                                                                                                                                                                                                         |
| creator              | handle                                 | string          | Handle of the creator.                                                                                                                                                                                                                                                                                                                                                        |
| creator              | name                                   | string          | Name of the creator.                                                                                                                                                                                                                                                                                                                                                          |
| data                 | description                            | string          | A user-defined description of the service level objective.                                                                                                                                                                                                                                                                                                                    | Always included in service level objective responses (but may be `null`). Optional in create/update requests.                                                                                                       |
| data                 | groups                                 | [string]        | A list of (up to 100) monitor groups that narrow the scope of a monitor service level objective.                                                                                                                                                                                                                                                                              | Included in service level objective responses if it is not empty. Optional in create/update requests for monitor service level objectives, but may only be used when then length of the `monitor_ids` field is one. |
| data                 | id                                     | string          | A unique identifier for the service level objective object.                                                                                                                                                                                                                                                                                                                   | Always included in service level objective responses.                                                                                                                                                               |
| data                 | modified_at                            | int64           | Modification timestamp (UNIX time in seconds)                                                                                                                                                                                                                                                                                                                                 | Always included in service level objective responses.                                                                                                                                                               |
| data                 | monitor_ids                            | [integer]       | A list of monitor ids that defines the scope of a monitor service level objective. **Required if type is `monitor`**.                                                                                                                                                                                                                                                         |
| data                 | monitor_tags                           | [string]        | The union of monitor tags for all monitors referenced by the `monitor_ids` field. Always included in service level objective responses for monitor-based service level objectives (but may be empty). Ignored in create/update requests. Does not affect which monitors are included in the service level objective (that is determined entirely by the `monitor_ids` field). |
| data                 | name [*required*]                 | string          | The name of the service level objective object.                                                                                                                                                                                                                                                                                                                               |
| data                 | query                                  | object          | A count-based (metric) SLO query. This field is superseded by `sli_specification` but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or min of all of those requests.                                                       |
| query                | denominator [*required*]          | string          | A Datadog metric query for total (valid) events.                                                                                                                                                                                                                                                                                                                              |
| query                | numerator [*required*]            | string          | A Datadog metric query for good events.                                                                                                                                                                                                                                                                                                                                       |
| data                 | sli_specification                      |  <oneOf>   | A generic SLI specification. This is used for time-slice and count-based (metric) SLOs only.                                                                                                                                                                                                                                                                                  |
| sli_specification    | Option 1                               | object          | A time-slice SLI specification.                                                                                                                                                                                                                                                                                                                                               |
| Option 1             | time_slice [*required*]           | object          | The time-slice condition, composed of 3 parts: 1. the metric timeseries query, 2. the comparator, and 3. the threshold. Optionally, a fourth part, the query interval, can be provided.                                                                                                                                                                                       |
| time_slice           | comparator [*required*]           | enum            | The comparator used to compare the SLI value to the threshold. Allowed enum values: `>,>=,<,<=`                                                                                                                                                                                                                                                                               |
| time_slice           | query [*required*]                | object          | The queries and formula used to calculate the SLI value.                                                                                                                                                                                                                                                                                                                      |
| query                | formulas [*required*]             | [object]        | A list that contains exactly one formula, as only a single formula may be used in a time-slice SLO.                                                                                                                                                                                                                                                                           |
| formulas             | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                                                                           |
| query                | queries [*required*]              | [ <oneOf>] | A list of queries that are used to calculate the SLI value.                                                                                                                                                                                                                                                                                                                   |
| queries              | Option 1                               | object          | A formula and functions metrics query.                                                                                                                                                                                                                                                                                                                                        |
| Option 1             | aggregator                             | enum            | The aggregation methods available for metrics queries. Allowed enum values: `avg,min,max,sum,last,area,l2norm,percentile`                                                                                                                                                                                                                                                     |
| Option 1             | cross_org_uuids                        | [string]        | The source organization UUID for cross organization queries. Feature in Private Beta.                                                                                                                                                                                                                                                                                         |
| Option 1             | data_source [*required*]          | enum            | Data source for metrics queries. Allowed enum values: `metrics`                                                                                                                                                                                                                                                                                                               |
| Option 1             | name [*required*]                 | string          | Name of the query for use in formulas.                                                                                                                                                                                                                                                                                                                                        |
| Option 1             | query [*required*]                | string          | Metrics query definition.                                                                                                                                                                                                                                                                                                                                                     |
| Option 1             | semantic_mode                          | enum            | Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. Allowed enum values: `combined,native`                                                                                                                                                                                                                       |
| time_slice           | query_interval_seconds                 | enum            | The interval used when querying data, which defines the size of a time slice. Two values are allowed: 60 (1 minute) and 300 (5 minutes). If not provided, the value defaults to 300 (5 minutes). Allowed enum values: `60,300`                                                                                                                                                |
| time_slice           | threshold [*required*]            | double          | The threshold value to which each SLI value will be compared.                                                                                                                                                                                                                                                                                                                 |
| sli_specification    | Option 2                               | object          | A metric SLI specification.                                                                                                                                                                                                                                                                                                                                                   |
| Option 2             | count [*required*]                |  <oneOf>   | A count-based (metric) SLI specification, composed of three parts: the good events formula, the bad or total events formula, and the underlying queries. Exactly one of `total_events_formula` or `bad_events_formula` must be provided.                                                                                                                                      |
| count                | Option 1                               | object          | SLO count definition using a total events formula alongside a good events formula.                                                                                                                                                                                                                                                                                            |
| Option 1             | good_events_formula [*required*]  | object          | A formula that specifies how to combine the results of multiple queries.                                                                                                                                                                                                                                                                                                      |
| good_events_formula  | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                                                                           |
| Option 1             | queries [*required*]              | [ <oneOf>] |
| queries              | Option 1                               | object          | A formula and functions metrics query.                                                                                                                                                                                                                                                                                                                                        |
| Option 1             | aggregator                             | enum            | The aggregation methods available for metrics queries. Allowed enum values: `avg,min,max,sum,last,area,l2norm,percentile`                                                                                                                                                                                                                                                     |
| Option 1             | cross_org_uuids                        | [string]        | The source organization UUID for cross organization queries. Feature in Private Beta.                                                                                                                                                                                                                                                                                         |
| Option 1             | data_source [*required*]          | enum            | Data source for metrics queries. Allowed enum values: `metrics`                                                                                                                                                                                                                                                                                                               |
| Option 1             | name [*required*]                 | string          | Name of the query for use in formulas.                                                                                                                                                                                                                                                                                                                                        |
| Option 1             | query [*required*]                | string          | Metrics query definition.                                                                                                                                                                                                                                                                                                                                                     |
| Option 1             | semantic_mode                          | enum            | Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. Allowed enum values: `combined,native`                                                                                                                                                                                                                       |
| Option 1             | total_events_formula [*required*] | object          | The total events formula. Bad events queries can be defined using the `bad_events_formula` field as an alternative. Only one of `total_events_formula` or `bad_events_formula` must be provided.                                                                                                                                                                              |
| total_events_formula | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                                                                           |
| count                | Option 2                               | object          | SLO count definition using a bad events formula alongside a good events formula.                                                                                                                                                                                                                                                                                              |
| Option 2             | bad_events_formula [*required*]   | object          | The bad events formula (recommended). Total events queries can be defined using the `total_events_formula` field as an alternative. Only one of `total_events_formula` or `bad_events_formula` must be provided.                                                                                                                                                              |
| bad_events_formula   | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                                                                           |
| Option 2             | good_events_formula [*required*]  | object          | A formula that specifies how to combine the results of multiple queries.                                                                                                                                                                                                                                                                                                      |
| good_events_formula  | formula [*required*]              | string          | The formula string, which is an expression involving named queries.                                                                                                                                                                                                                                                                                                           |
| Option 2             | queries [*required*]              | [ <oneOf>] |
| queries              | Option 1                               | object          | A formula and functions metrics query.                                                                                                                                                                                                                                                                                                                                        |
| Option 1             | aggregator                             | enum            | The aggregation methods available for metrics queries. Allowed enum values: `avg,min,max,sum,last,area,l2norm,percentile`                                                                                                                                                                                                                                                     |
| Option 1             | cross_org_uuids                        | [string]        | The source organization UUID for cross organization queries. Feature in Private Beta.                                                                                                                                                                                                                                                                                         |
| Option 1             | data_source [*required*]          | enum            | Data source for metrics queries. Allowed enum values: `metrics`                                                                                                                                                                                                                                                                                                               |
| Option 1             | name [*required*]                 | string          | Name of the query for use in formulas.                                                                                                                                                                                                                                                                                                                                        |
| Option 1             | query [*required*]                | string          | Metrics query definition.                                                                                                                                                                                                                                                                                                                                                     |
| Option 1             | semantic_mode                          | enum            | Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. Allowed enum values: `combined,native`                                                                                                                                                                                                                       |
| data                 | tags                                   | [string]        | A list of tags associated with this service level objective. Always included in service level objective responses (but may be empty). Optional in create/update requests.                                                                                                                                                                                                     |
| data                 | target_threshold                       | double          | The target threshold such that when the service level indicator is above this threshold over the given timeframe, the objective is being met.                                                                                                                                                                                                                                 |
| data                 | thresholds [*required*]           | [object]        | The thresholds (timeframes and associated targets) for this service level objective object.                                                                                                                                                                                                                                                                                   |
| thresholds           | target [*required*]               | double          | The target value for the service level indicator within the corresponding timeframe.                                                                                                                                                                                                                                                                                          |
| thresholds           | target_display                         | string          | A string representation of the target that indicates its precision. It uses trailing zeros to show significant decimal places (for example `98.00`).                                                                                                                                                                                                                          | Always included in service level objective responses. Ignored in create/update requests.                                                                                                                            |
| thresholds           | timeframe [*required*]            | enum            | The SLO time window options. Note that "custom" is not a valid option for creating or updating SLOs. It is only used when querying SLO history over custom timeframes. Allowed enum values: `7d,30d,90d,custom`                                                                                                                                                               |
| thresholds           | warning                                | double          | The warning value for the service level objective.                                                                                                                                                                                                                                                                                                                            |
| thresholds           | warning_display                        | string          | A string representation of the warning target (see the description of the `target_display` field for details).                                                                                                                                                                                                                                                                | Included in service level objective responses if a warning target exists. Ignored in create/update requests.                                                                                                        |
| data                 | timeframe                              | enum            | The SLO time window options. Note that "custom" is not a valid option for creating or updating SLOs. It is only used when querying SLO history over custom timeframes. Allowed enum values: `7d,30d,90d,custom`                                                                                                                                                               |
| data                 | type [*required*]                 | enum            | The type of the service level objective. Allowed enum values: `metric,monitor,time_slice`                                                                                                                                                                                                                                                                                     |
| data                 | warning_threshold                      | double          | The optional warning threshold such that when the service level indicator is below this value for the given threshold, but above the target threshold, the objective appears in a "warning" state. This value must be greater than the target threshold.                                                                                                                      |
|                      | errors                                 | [string]        | An array of error messages. Each endpoint documents how/whether this field is used.                                                                                                                                                                                                                                                                                           |
|                      | metadata                               | object          | The metadata object containing additional information about the list of SLOs.                                                                                                                                                                                                                                                                                                 |
| metadata             | page                                   | object          | The object containing information about the pages of the list of SLOs.                                                                                                                                                                                                                                                                                                        |
| page                 | total_count                            | int64           | The total number of resources that could be retrieved ignoring the parameters and filters in the request.                                                                                                                                                                                                                                                                     |
| page                 | total_filtered_count                   | int64           | The total number of resources that match the parameters and filters in the request. This attribute can be used by a client to determine the total number of pages.                                                                                                                                                                                                            |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": [
    {
      "created_at": "integer",
      "creator": {
        "email": "string",
        "handle": "string",
        "name": "string"
      },
      "description": "string",
      "groups": [
        "env:prod",
        "role:mysql"
      ],
      "id": "string",
      "modified_at": "integer",
      "monitor_ids": [],
      "monitor_tags": [],
      "name": "Custom Metric SLO",
      "query": {
        "denominator": "sum:my.custom.metric{*}.as_count()",
        "numerator": "sum:my.custom.metric{type:good}.as_count()"
      },
      "sli_specification": {
        "time_slice": {
          "comparator": ">",
          "query": {
            "formulas": [
              {
                "formula": "query1 - default_zero(query2)"
              }
            ],
            "queries": [
              []
            ]
          },
          "query_interval_seconds": 300,
          "threshold": 5
        }
      },
      "tags": [
        "env:prod",
        "app:core"
      ],
      "target_threshold": 99.9,
      "thresholds": [
        {
          "target": 99.9,
          "target_display": "99.9",
          "timeframe": "30d",
          "warning": 90,
          "warning_display": "90.0"
        }
      ],
      "timeframe": "30d",
      "type": "metric",
      "warning_threshold": 99.95
    }
  ],
  "errors": [],
  "metadata": {
    "page": {
      "total_count": "integer",
      "total_filtered_count": "integer"
    }
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% tab title="Model" %}
Error response object.

| Field                    | Type     | Description                          |
| ------------------------ | -------- | ------------------------------------ |
| errors [*required*] | [string] | Array of errors returned by the API. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="403" %}
Forbidden
{% tab title="Model" %}
Error response object.

| Field                    | Type     | Description                          |
| ------------------------ | -------- | ------------------------------------ |
| errors [*required*] | [string] | Array of errors returned by the API. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
Error response object.

| Field                    | Type     | Description                          |
| ------------------------ | -------- | ------------------------------------ |
| errors [*required*] | [string] | Array of errors returned by the API. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                          \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "description": "Track the availability of our custom metric.",
  "name": "Custom Metric SLO",
  "query": {
    "denominator": "sum:my.custom.metric{*}.as_count()",
    "numerator": "sum:my.custom.metric{type:good}.as_count()"
  },
  "tags": [
    "env:prod",
    "app:core"
  ],
  "thresholds": [
    {
      "target": 95,
      "timeframe": "7d"
    },
    {
      "target": 95,
      "timeframe": "30d",
      "warning": 97
    }
  ],
  "type": "metric"
}
EOF 
                        
##### 
                          \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "description": "Track the availability of our custom metric.",
  "name": "Custom Metric SLO",
  "query": {
    "denominator": "sum:my.custom.metric{*}.as_count()",
    "numerator": "sum:my.custom.metric{type:good}.as_count()"
  },
  "tags": [
    "env:prod",
    "app:core"
  ],
  "thresholds": [
    {
      "target": 95,
      "timeframe": "7d"
    },
    {
      "target": 95,
      "timeframe": "30d",
      "warning": 97
    }
  ],
  "type": "metric"
}
EOF 
                        
##### 
                          \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "description": "Track the availability of our custom metric.",
  "name": "Custom Metric SLO",
  "query": {
    "denominator": "sum:my.custom.metric{*}.as_count()",
    "numerator": "sum:my.custom.metric{type:good}.as_count()"
  },
  "tags": [
    "env:prod",
    "app:core"
  ],
  "thresholds": [
    {
      "target": 95,
      "timeframe": "7d"
    },
    {
      "target": 95,
      "timeframe": "30d",
      "warning": 97
    }
  ],
  "type": "metric"
}
EOF 
                        
##### 

```go
// Create a new metric SLO object using bad events formula 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/datadogV1"
)

func main() {
	body := datadogV1.ServiceLevelObjectiveRequest{
		Type:        datadogV1.SLOTYPE_METRIC,
		Description: *datadog.NewNullableString(datadog.PtrString("Metric SLO using sli_specification")),
		Name:        "Example-Service-Level-Objective",
		SliSpecification: &datadogV1.SLOSliSpec{
			SLOCountSpec: &datadogV1.SLOCountSpec{
				Count: datadogV1.SLOCountDefinition{
					SLOCountDefinitionWithBadEventsFormula: &datadogV1.SLOCountDefinitionWithBadEventsFormula{
						GoodEventsFormula: datadogV1.SLOFormula{
							Formula: "query1 - query2",
						},
						BadEventsFormula: datadogV1.SLOFormula{
							Formula: "query2",
						},
						Queries: []datadogV1.SLODataSourceQueryDefinition{
							datadogV1.SLODataSourceQueryDefinition{
								FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
									DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
									Name:       "query1",
									Query:      "sum:httpservice.hits{*}.as_count()",
								}},
							datadogV1.SLODataSourceQueryDefinition{
								FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
									DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
									Name:       "query2",
									Query:      "sum:httpservice.errors{*}.as_count()",
								}},
						},
					}},
			}},
		Tags: []string{
			"env:prod",
			"type:count",
		},
		Thresholds: []datadogV1.SLOThreshold{
			{
				Target:         99.0,
				TargetDisplay:  datadog.PtrString("99.0"),
				Timeframe:      datadogV1.SLOTIMEFRAME_SEVEN_DAYS,
				Warning:        datadog.PtrFloat64(99.5),
				WarningDisplay: datadog.PtrString("99.5"),
			},
		},
		Timeframe:        datadogV1.SLOTIMEFRAME_SEVEN_DAYS.Ptr(),
		TargetThreshold:  datadog.PtrFloat64(99.0),
		WarningThreshold: datadog.PtrFloat64(99.5),
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV1.NewServiceLevelObjectivesApi(apiClient)
	resp, r, err := api.CreateSLO(ctx, body)

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

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

##### 

```go
// Create a new metric SLO object using sli_specification 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/datadogV1"
)

func main() {
	body := datadogV1.ServiceLevelObjectiveRequest{
		Type:        datadogV1.SLOTYPE_METRIC,
		Description: *datadog.NewNullableString(datadog.PtrString("Metric SLO using sli_specification")),
		Name:        "Example-Service-Level-Objective",
		SliSpecification: &datadogV1.SLOSliSpec{
			SLOCountSpec: &datadogV1.SLOCountSpec{
				Count: datadogV1.SLOCountDefinition{
					SLOCountDefinitionWithTotalEventsFormula: &datadogV1.SLOCountDefinitionWithTotalEventsFormula{
						GoodEventsFormula: datadogV1.SLOFormula{
							Formula: "query1 - query2",
						},
						TotalEventsFormula: datadogV1.SLOFormula{
							Formula: "query1",
						},
						Queries: []datadogV1.SLODataSourceQueryDefinition{
							datadogV1.SLODataSourceQueryDefinition{
								FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
									DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
									Name:       "query1",
									Query:      "sum:httpservice.hits{*}.as_count()",
								}},
							datadogV1.SLODataSourceQueryDefinition{
								FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
									DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
									Name:       "query2",
									Query:      "sum:httpservice.errors{*}.as_count()",
								}},
						},
					}},
			}},
		Tags: []string{
			"env:prod",
			"type:count",
		},
		Thresholds: []datadogV1.SLOThreshold{
			{
				Target:         99.0,
				TargetDisplay:  datadog.PtrString("99.0"),
				Timeframe:      datadogV1.SLOTIMEFRAME_SEVEN_DAYS,
				Warning:        datadog.PtrFloat64(99.5),
				WarningDisplay: datadog.PtrString("99.5"),
			},
		},
		Timeframe:        datadogV1.SLOTIMEFRAME_SEVEN_DAYS.Ptr(),
		TargetThreshold:  datadog.PtrFloat64(99.0),
		WarningThreshold: datadog.PtrFloat64(99.5),
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV1.NewServiceLevelObjectivesApi(apiClient)
	resp, r, err := api.CreateSLO(ctx, body)

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

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

##### 

```go
// Create a time-slice SLO object 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/datadogV1"
)

func main() {
	body := datadogV1.ServiceLevelObjectiveRequest{
		Type:        datadogV1.SLOTYPE_TIME_SLICE,
		Description: *datadog.NewNullableString(datadog.PtrString("string")),
		Name:        "Example-Service-Level-Objective",
		SliSpecification: &datadogV1.SLOSliSpec{
			SLOTimeSliceSpec: &datadogV1.SLOTimeSliceSpec{
				TimeSlice: datadogV1.SLOTimeSliceCondition{
					Query: datadogV1.SLOTimeSliceQuery{
						Formulas: []datadogV1.SLOFormula{
							{
								Formula: "query1",
							},
						},
						Queries: []datadogV1.SLODataSourceQueryDefinition{
							datadogV1.SLODataSourceQueryDefinition{
								FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
									DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
									Name:       "query1",
									Query:      "trace.servlet.request{env:prod}",
								}},
						},
					},
					Comparator: datadogV1.SLOTIMESLICECOMPARATOR_GREATER,
					Threshold:  5,
				},
			}},
		Tags: []string{
			"env:prod",
		},
		Thresholds: []datadogV1.SLOThreshold{
			{
				Target:         97.0,
				TargetDisplay:  datadog.PtrString("97.0"),
				Timeframe:      datadogV1.SLOTIMEFRAME_SEVEN_DAYS,
				Warning:        datadog.PtrFloat64(98),
				WarningDisplay: datadog.PtrString("98.0"),
			},
		},
		Timeframe:        datadogV1.SLOTIMEFRAME_SEVEN_DAYS.Ptr(),
		TargetThreshold:  datadog.PtrFloat64(97.0),
		WarningThreshold: datadog.PtrFloat64(98),
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV1.NewServiceLevelObjectivesApi(apiClient)
	resp, r, err := api.CreateSLO(ctx, body)

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

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

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
##### 

```java
// Create a new metric SLO object using bad events formula returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.ServiceLevelObjectivesApi;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricDataSource;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricQueryDefinition;
import com.datadog.api.client.v1.model.SLOCountDefinition;
import com.datadog.api.client.v1.model.SLOCountDefinitionWithBadEventsFormula;
import com.datadog.api.client.v1.model.SLOCountSpec;
import com.datadog.api.client.v1.model.SLODataSourceQueryDefinition;
import com.datadog.api.client.v1.model.SLOFormula;
import com.datadog.api.client.v1.model.SLOListResponse;
import com.datadog.api.client.v1.model.SLOSliSpec;
import com.datadog.api.client.v1.model.SLOThreshold;
import com.datadog.api.client.v1.model.SLOTimeframe;
import com.datadog.api.client.v1.model.SLOType;
import com.datadog.api.client.v1.model.ServiceLevelObjectiveRequest;
import java.util.Arrays;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    ServiceLevelObjectivesApi apiInstance = new ServiceLevelObjectivesApi(defaultClient);

    ServiceLevelObjectiveRequest body =
        new ServiceLevelObjectiveRequest()
            .type(SLOType.METRIC)
            .description("Metric SLO using sli_specification")
            .name("Example-Service-Level-Objective")
            .sliSpecification(
                new SLOSliSpec(
                    new SLOCountSpec()
                        .count(
                            new SLOCountDefinition(
                                new SLOCountDefinitionWithBadEventsFormula()
                                    .goodEventsFormula(new SLOFormula().formula("query1 - query2"))
                                    .badEventsFormula(new SLOFormula().formula("query2"))
                                    .queries(
                                        Arrays.asList(
                                            new SLODataSourceQueryDefinition(
                                                new FormulaAndFunctionMetricQueryDefinition()
                                                    .dataSource(
                                                        FormulaAndFunctionMetricDataSource.METRICS)
                                                    .name("query1")
                                                    .query("sum:httpservice.hits{*}.as_count()")),
                                            new SLODataSourceQueryDefinition(
                                                new FormulaAndFunctionMetricQueryDefinition()
                                                    .dataSource(
                                                        FormulaAndFunctionMetricDataSource.METRICS)
                                                    .name("query2")
                                                    .query(
                                                        "sum:httpservice.errors{*}.as_count()"))))))))
            .tags(Arrays.asList("env:prod", "type:count"))
            .thresholds(
                Collections.singletonList(
                    new SLOThreshold()
                        .target(99.0)
                        .targetDisplay("99.0")
                        .timeframe(SLOTimeframe.SEVEN_DAYS)
                        .warning(99.5)
                        .warningDisplay("99.5")))
            .timeframe(SLOTimeframe.SEVEN_DAYS)
            .targetThreshold(99.0)
            .warningThreshold(99.5);

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

##### 

```java
// Create a new metric SLO object using sli_specification returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.ServiceLevelObjectivesApi;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricDataSource;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricQueryDefinition;
import com.datadog.api.client.v1.model.SLOCountDefinition;
import com.datadog.api.client.v1.model.SLOCountDefinitionWithTotalEventsFormula;
import com.datadog.api.client.v1.model.SLOCountSpec;
import com.datadog.api.client.v1.model.SLODataSourceQueryDefinition;
import com.datadog.api.client.v1.model.SLOFormula;
import com.datadog.api.client.v1.model.SLOListResponse;
import com.datadog.api.client.v1.model.SLOSliSpec;
import com.datadog.api.client.v1.model.SLOThreshold;
import com.datadog.api.client.v1.model.SLOTimeframe;
import com.datadog.api.client.v1.model.SLOType;
import com.datadog.api.client.v1.model.ServiceLevelObjectiveRequest;
import java.util.Arrays;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    ServiceLevelObjectivesApi apiInstance = new ServiceLevelObjectivesApi(defaultClient);

    ServiceLevelObjectiveRequest body =
        new ServiceLevelObjectiveRequest()
            .type(SLOType.METRIC)
            .description("Metric SLO using sli_specification")
            .name("Example-Service-Level-Objective")
            .sliSpecification(
                new SLOSliSpec(
                    new SLOCountSpec()
                        .count(
                            new SLOCountDefinition(
                                new SLOCountDefinitionWithTotalEventsFormula()
                                    .goodEventsFormula(new SLOFormula().formula("query1 - query2"))
                                    .totalEventsFormula(new SLOFormula().formula("query1"))
                                    .queries(
                                        Arrays.asList(
                                            new SLODataSourceQueryDefinition(
                                                new FormulaAndFunctionMetricQueryDefinition()
                                                    .dataSource(
                                                        FormulaAndFunctionMetricDataSource.METRICS)
                                                    .name("query1")
                                                    .query("sum:httpservice.hits{*}.as_count()")),
                                            new SLODataSourceQueryDefinition(
                                                new FormulaAndFunctionMetricQueryDefinition()
                                                    .dataSource(
                                                        FormulaAndFunctionMetricDataSource.METRICS)
                                                    .name("query2")
                                                    .query(
                                                        "sum:httpservice.errors{*}.as_count()"))))))))
            .tags(Arrays.asList("env:prod", "type:count"))
            .thresholds(
                Collections.singletonList(
                    new SLOThreshold()
                        .target(99.0)
                        .targetDisplay("99.0")
                        .timeframe(SLOTimeframe.SEVEN_DAYS)
                        .warning(99.5)
                        .warningDisplay("99.5")))
            .timeframe(SLOTimeframe.SEVEN_DAYS)
            .targetThreshold(99.0)
            .warningThreshold(99.5);

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

##### 

```java
// Create a time-slice SLO object returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.ServiceLevelObjectivesApi;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricDataSource;
import com.datadog.api.client.v1.model.FormulaAndFunctionMetricQueryDefinition;
import com.datadog.api.client.v1.model.SLODataSourceQueryDefinition;
import com.datadog.api.client.v1.model.SLOFormula;
import com.datadog.api.client.v1.model.SLOListResponse;
import com.datadog.api.client.v1.model.SLOSliSpec;
import com.datadog.api.client.v1.model.SLOThreshold;
import com.datadog.api.client.v1.model.SLOTimeSliceComparator;
import com.datadog.api.client.v1.model.SLOTimeSliceCondition;
import com.datadog.api.client.v1.model.SLOTimeSliceQuery;
import com.datadog.api.client.v1.model.SLOTimeSliceSpec;
import com.datadog.api.client.v1.model.SLOTimeframe;
import com.datadog.api.client.v1.model.SLOType;
import com.datadog.api.client.v1.model.ServiceLevelObjectiveRequest;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    ServiceLevelObjectivesApi apiInstance = new ServiceLevelObjectivesApi(defaultClient);

    ServiceLevelObjectiveRequest body =
        new ServiceLevelObjectiveRequest()
            .type(SLOType.TIME_SLICE)
            .description("string")
            .name("Example-Service-Level-Objective")
            .sliSpecification(
                new SLOSliSpec(
                    new SLOTimeSliceSpec()
                        .timeSlice(
                            new SLOTimeSliceCondition()
                                .query(
                                    new SLOTimeSliceQuery()
                                        .formulas(
                                            Collections.singletonList(
                                                new SLOFormula().formula("query1")))
                                        .queries(
                                            Collections.singletonList(
                                                new SLODataSourceQueryDefinition(
                                                    new FormulaAndFunctionMetricQueryDefinition()
                                                        .dataSource(
                                                            FormulaAndFunctionMetricDataSource
                                                                .METRICS)
                                                        .name("query1")
                                                        .query(
                                                            "trace.servlet.request{env:prod}")))))
                                .comparator(SLOTimeSliceComparator.GREATER)
                                .threshold(5.0))))
            .tags(Collections.singletonList("env:prod"))
            .thresholds(
                Collections.singletonList(
                    new SLOThreshold()
                        .target(97.0)
                        .targetDisplay("97.0")
                        .timeframe(SLOTimeframe.SEVEN_DAYS)
                        .warning(98.0)
                        .warningDisplay("98.0")))
            .timeframe(SLOTimeframe.SEVEN_DAYS)
            .targetThreshold(97.0)
            .warningThreshold(98.0);

    try {
      SLOListResponse result = apiInstance.createSLO(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ServiceLevelObjectivesApi#createSLO");
      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://docs.datadoghq.com/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
##### 

```python
from datadog import initialize, api

options = {
    'api_key': '<DATADOG_API_KEY>',
    'app_key': '<DATADOG_APPLICATION_KEY>'
}

initialize(**options)

# Create a new SLO
thresholds = [
  {"timeframe": "7d", "target": 95},
  {"timeframe": "30d", "target": 95, "warning": 97},
]
tags = ["app:webserver", "frontend"]
api.ServiceLevelObjective.create(
    type="metric",
    name="Custom Metric SLO",
    description="SLO tracking custom service SLO",
    query={
        "numerator": "sum:my.custom.metric{type:good}.as_count()",
        "denominator": "sum:my.custom.metric{*}.as_count()"
    },
    tags=tags,
    thresholds=thresholds
)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python-legacy) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python "example.py"
##### 

```python
"""
Create a new metric SLO object using bad events formula returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v1.api.service_level_objectives_api import ServiceLevelObjectivesApi
from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource
from datadog_api_client.v1.model.formula_and_function_metric_query_definition import (
    FormulaAndFunctionMetricQueryDefinition,
)
from datadog_api_client.v1.model.service_level_objective_request import ServiceLevelObjectiveRequest
from datadog_api_client.v1.model.slo_count_definition_with_bad_events_formula import (
    SLOCountDefinitionWithBadEventsFormula,
)
from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec
from datadog_api_client.v1.model.slo_formula import SLOFormula
from datadog_api_client.v1.model.slo_threshold import SLOThreshold
from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe
from datadog_api_client.v1.model.slo_type import SLOType

body = ServiceLevelObjectiveRequest(
    type=SLOType.METRIC,
    description="Metric SLO using sli_specification",
    name="Example-Service-Level-Objective",
    sli_specification=SLOCountSpec(
        count=SLOCountDefinitionWithBadEventsFormula(
            good_events_formula=SLOFormula(
                formula="query1 - query2",
            ),
            bad_events_formula=SLOFormula(
                formula="query2",
            ),
            queries=[
                FormulaAndFunctionMetricQueryDefinition(
                    data_source=FormulaAndFunctionMetricDataSource.METRICS,
                    name="query1",
                    query="sum:httpservice.hits{*}.as_count()",
                ),
                FormulaAndFunctionMetricQueryDefinition(
                    data_source=FormulaAndFunctionMetricDataSource.METRICS,
                    name="query2",
                    query="sum:httpservice.errors{*}.as_count()",
                ),
            ],
        ),
    ),
    tags=[
        "env:prod",
        "type:count",
    ],
    thresholds=[
        SLOThreshold(
            target=99.0,
            target_display="99.0",
            timeframe=SLOTimeframe.SEVEN_DAYS,
            warning=99.5,
            warning_display="99.5",
        ),
    ],
    timeframe=SLOTimeframe.SEVEN_DAYS,
    target_threshold=99.0,
    warning_threshold=99.5,
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = ServiceLevelObjectivesApi(api_client)
    response = api_instance.create_slo(body=body)

    print(response)
```

##### 

```python
"""
Create a new metric SLO object using sli_specification returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v1.api.service_level_objectives_api import ServiceLevelObjectivesApi
from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource
from datadog_api_client.v1.model.formula_and_function_metric_query_definition import (
    FormulaAndFunctionMetricQueryDefinition,
)
from datadog_api_client.v1.model.service_level_objective_request import ServiceLevelObjectiveRequest
from datadog_api_client.v1.model.slo_count_definition_with_total_events_formula import (
    SLOCountDefinitionWithTotalEventsFormula,
)
from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec
from datadog_api_client.v1.model.slo_formula import SLOFormula
from datadog_api_client.v1.model.slo_threshold import SLOThreshold
from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe
from datadog_api_client.v1.model.slo_type import SLOType

body = ServiceLevelObjectiveRequest(
    type=SLOType.METRIC,
    description="Metric SLO using sli_specification",
    name="Example-Service-Level-Objective",
    sli_specification=SLOCountSpec(
        count=SLOCountDefinitionWithTotalEventsFormula(
            good_events_formula=SLOFormula(
                formula="query1 - query2",
            ),
            total_events_formula=SLOFormula(
                formula="query1",
            ),
            queries=[
                FormulaAndFunctionMetricQueryDefinition(
                    data_source=FormulaAndFunctionMetricDataSource.METRICS,
                    name="query1",
                    query="sum:httpservice.hits{*}.as_count()",
                ),
                FormulaAndFunctionMetricQueryDefinition(
                    data_source=FormulaAndFunctionMetricDataSource.METRICS,
                    name="query2",
                    query="sum:httpservice.errors{*}.as_count()",
                ),
            ],
        ),
    ),
    tags=[
        "env:prod",
        "type:count",
    ],
    thresholds=[
        SLOThreshold(
            target=99.0,
            target_display="99.0",
            timeframe=SLOTimeframe.SEVEN_DAYS,
            warning=99.5,
            warning_display="99.5",
        ),
    ],
    timeframe=SLOTimeframe.SEVEN_DAYS,
    target_threshold=99.0,
    warning_threshold=99.5,
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = ServiceLevelObjectivesApi(api_client)
    response = api_instance.create_slo(body=body)

    print(response)
```

##### 

```python
"""
Create a time-slice SLO object returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v1.api.service_level_objectives_api import ServiceLevelObjectivesApi
from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource
from datadog_api_client.v1.model.formula_and_function_metric_query_definition import (
    FormulaAndFunctionMetricQueryDefinition,
)
from datadog_api_client.v1.model.service_level_objective_request import ServiceLevelObjectiveRequest
from datadog_api_client.v1.model.slo_formula import SLOFormula
from datadog_api_client.v1.model.slo_threshold import SLOThreshold
from datadog_api_client.v1.model.slo_time_slice_comparator import SLOTimeSliceComparator
from datadog_api_client.v1.model.slo_time_slice_condition import SLOTimeSliceCondition
from datadog_api_client.v1.model.slo_time_slice_query import SLOTimeSliceQuery
from datadog_api_client.v1.model.slo_time_slice_spec import SLOTimeSliceSpec
from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe
from datadog_api_client.v1.model.slo_type import SLOType

body = ServiceLevelObjectiveRequest(
    type=SLOType.TIME_SLICE,
    description="string",
    name="Example-Service-Level-Objective",
    sli_specification=SLOTimeSliceSpec(
        time_slice=SLOTimeSliceCondition(
            query=SLOTimeSliceQuery(
                formulas=[
                    SLOFormula(
                        formula="query1",
                    ),
                ],
                queries=[
                    FormulaAndFunctionMetricQueryDefinition(
                        data_source=FormulaAndFunctionMetricDataSource.METRICS,
                        name="query1",
                        query="trace.servlet.request{env:prod}",
                    ),
                ],
            ),
            comparator=SLOTimeSliceComparator.GREATER,
            threshold=5.0,
        ),
    ),
    tags=[
        "env:prod",
    ],
    thresholds=[
        SLOThreshold(
            target=97.0,
            target_display="97.0",
            timeframe=SLOTimeframe.SEVEN_DAYS,
            warning=98.0,
            warning_display="98.0",
        ),
    ],
    timeframe=SLOTimeframe.SEVEN_DAYS,
    target_threshold=97.0,
    warning_threshold=98.0,
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = ServiceLevelObjectivesApi(api_client)
    response = api_instance.create_slo(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
##### 

```ruby
require 'dogapi'

api_key = '<DATADOG_API_KEY>'
app_key = '<DATADOG_APPLICATION_KEY>'

dog = Dogapi::Client.new(api_key, app_key)

# Create a new SLO
thresholds = [
  { timeframe: '7d', target: 95 },
  { timeframe: '30d', target: 95, warning: 97 }
]
tags = ['app:webserver', 'frontend']
dog.create_service_level_objective(
  type: 'metric',
  name: 'Custom Metric SLO',
  description: 'SLO tracking custom service SLO',
  numerator: 'sum:my.custom.metric{type:good}.as_count()',
  denominator: 'sum:my.custom.metric{*}.as_count()',
  tags: tags,
  thresholds: thresholds
)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby-legacy) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
##### 

```ruby
# Create a new metric SLO object using bad events formula returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V1::ServiceLevelObjectivesAPI.new

body = DatadogAPIClient::V1::ServiceLevelObjectiveRequest.new({
  type: DatadogAPIClient::V1::SLOType::METRIC,
  description: "Metric SLO using sli_specification",
  name: "Example-Service-Level-Objective",
  sli_specification: DatadogAPIClient::V1::SLOCountSpec.new({
    count: DatadogAPIClient::V1::SLOCountDefinitionWithBadEventsFormula.new({
      good_events_formula: DatadogAPIClient::V1::SLOFormula.new({
        formula: "query1 - query2",
      }),
      bad_events_formula: DatadogAPIClient::V1::SLOFormula.new({
        formula: "query2",
      }),
      queries: [
        DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
          data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
          name: "query1",
          query: "sum:httpservice.hits{*}.as_count()",
        }),
        DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
          data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
          name: "query2",
          query: "sum:httpservice.errors{*}.as_count()",
        }),
      ],
    }),
  }),
  tags: [
    "env:prod",
    "type:count",
  ],
  thresholds: [
    DatadogAPIClient::V1::SLOThreshold.new({
      target: 99.0,
      target_display: "99.0",
      timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
      warning: 99.5,
      warning_display: "99.5",
    }),
  ],
  timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
  target_threshold: 99.0,
  warning_threshold: 99.5,
})
p api_instance.create_slo(body)
```

##### 

```ruby
# Create a new metric SLO object using sli_specification returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V1::ServiceLevelObjectivesAPI.new

body = DatadogAPIClient::V1::ServiceLevelObjectiveRequest.new({
  type: DatadogAPIClient::V1::SLOType::METRIC,
  description: "Metric SLO using sli_specification",
  name: "Example-Service-Level-Objective",
  sli_specification: DatadogAPIClient::V1::SLOCountSpec.new({
    count: DatadogAPIClient::V1::SLOCountDefinitionWithTotalEventsFormula.new({
      good_events_formula: DatadogAPIClient::V1::SLOFormula.new({
        formula: "query1 - query2",
      }),
      total_events_formula: DatadogAPIClient::V1::SLOFormula.new({
        formula: "query1",
      }),
      queries: [
        DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
          data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
          name: "query1",
          query: "sum:httpservice.hits{*}.as_count()",
        }),
        DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
          data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
          name: "query2",
          query: "sum:httpservice.errors{*}.as_count()",
        }),
      ],
    }),
  }),
  tags: [
    "env:prod",
    "type:count",
  ],
  thresholds: [
    DatadogAPIClient::V1::SLOThreshold.new({
      target: 99.0,
      target_display: "99.0",
      timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
      warning: 99.5,
      warning_display: "99.5",
    }),
  ],
  timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
  target_threshold: 99.0,
  warning_threshold: 99.5,
})
p api_instance.create_slo(body)
```

##### 

```ruby
# Create a time-slice SLO object returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V1::ServiceLevelObjectivesAPI.new

body = DatadogAPIClient::V1::ServiceLevelObjectiveRequest.new({
  type: DatadogAPIClient::V1::SLOType::TIME_SLICE,
  description: "string",
  name: "Example-Service-Level-Objective",
  sli_specification: DatadogAPIClient::V1::SLOTimeSliceSpec.new({
    time_slice: DatadogAPIClient::V1::SLOTimeSliceCondition.new({
      query: DatadogAPIClient::V1::SLOTimeSliceQuery.new({
        formulas: [
          DatadogAPIClient::V1::SLOFormula.new({
            formula: "query1",
          }),
        ],
        queries: [
          DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
            data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
            name: "query1",
            query: "trace.servlet.request{env:prod}",
          }),
        ],
      }),
      comparator: DatadogAPIClient::V1::SLOTimeSliceComparator::GREATER,
      threshold: 5,
    }),
  }),
  tags: [
    "env:prod",
  ],
  thresholds: [
    DatadogAPIClient::V1::SLOThreshold.new({
      target: 97.0,
      target_display: "97.0",
      timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
      warning: 98,
      warning_display: "98.0",
    }),
  ],
  timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
  target_threshold: 97.0,
  warning_threshold: 98,
})
p api_instance.create_slo(body)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
##### 

```rust
// Create a new metric SLO object using bad events formula returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_service_level_objectives::ServiceLevelObjectivesAPI;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
use datadog_api_client::datadogV1::model::SLOCountDefinition;
use datadog_api_client::datadogV1::model::SLOCountDefinitionWithBadEventsFormula;
use datadog_api_client::datadogV1::model::SLOCountSpec;
use datadog_api_client::datadogV1::model::SLODataSourceQueryDefinition;
use datadog_api_client::datadogV1::model::SLOFormula;
use datadog_api_client::datadogV1::model::SLOSliSpec;
use datadog_api_client::datadogV1::model::SLOThreshold;
use datadog_api_client::datadogV1::model::SLOTimeframe;
use datadog_api_client::datadogV1::model::SLOType;
use datadog_api_client::datadogV1::model::ServiceLevelObjectiveRequest;

#[tokio::main]
async fn main() {
    let body = ServiceLevelObjectiveRequest::new(
        "Example-Service-Level-Objective".to_string(),
        vec![SLOThreshold::new(99.0, SLOTimeframe::SEVEN_DAYS)
            .target_display("99.0".to_string())
            .warning(99.5 as f64)
            .warning_display("99.5".to_string())],
        SLOType::METRIC,
    )
    .description(Some("Metric SLO using sli_specification".to_string()))
    .sli_specification(SLOSliSpec::SLOCountSpec(Box::new(SLOCountSpec::new(
        SLOCountDefinition::SLOCountDefinitionWithBadEventsFormula(Box::new(
            SLOCountDefinitionWithBadEventsFormula::new(
                SLOFormula::new("query2".to_string()),
                SLOFormula::new("query1 - query2".to_string()),
                vec![
                    SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
                        Box::new(FormulaAndFunctionMetricQueryDefinition::new(
                            FormulaAndFunctionMetricDataSource::METRICS,
                            "query1".to_string(),
                            "sum:httpservice.hits{*}.as_count()".to_string(),
                        )),
                    ),
                    SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
                        Box::new(FormulaAndFunctionMetricQueryDefinition::new(
                            FormulaAndFunctionMetricDataSource::METRICS,
                            "query2".to_string(),
                            "sum:httpservice.errors{*}.as_count()".to_string(),
                        )),
                    ),
                ],
            ),
        )),
    ))))
    .tags(vec!["env:prod".to_string(), "type:count".to_string()])
    .target_threshold(99.0 as f64)
    .timeframe(SLOTimeframe::SEVEN_DAYS)
    .warning_threshold(99.5 as f64);
    let configuration = datadog::Configuration::new();
    let api = ServiceLevelObjectivesAPI::with_config(configuration);
    let resp = api.create_slo(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

##### 

```rust
// Create a new metric SLO object using sli_specification returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_service_level_objectives::ServiceLevelObjectivesAPI;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
use datadog_api_client::datadogV1::model::SLOCountDefinition;
use datadog_api_client::datadogV1::model::SLOCountDefinitionWithTotalEventsFormula;
use datadog_api_client::datadogV1::model::SLOCountSpec;
use datadog_api_client::datadogV1::model::SLODataSourceQueryDefinition;
use datadog_api_client::datadogV1::model::SLOFormula;
use datadog_api_client::datadogV1::model::SLOSliSpec;
use datadog_api_client::datadogV1::model::SLOThreshold;
use datadog_api_client::datadogV1::model::SLOTimeframe;
use datadog_api_client::datadogV1::model::SLOType;
use datadog_api_client::datadogV1::model::ServiceLevelObjectiveRequest;

#[tokio::main]
async fn main() {
    let body = ServiceLevelObjectiveRequest::new(
        "Example-Service-Level-Objective".to_string(),
        vec![SLOThreshold::new(99.0, SLOTimeframe::SEVEN_DAYS)
            .target_display("99.0".to_string())
            .warning(99.5 as f64)
            .warning_display("99.5".to_string())],
        SLOType::METRIC,
    )
    .description(Some("Metric SLO using sli_specification".to_string()))
    .sli_specification(SLOSliSpec::SLOCountSpec(Box::new(SLOCountSpec::new(
        SLOCountDefinition::SLOCountDefinitionWithTotalEventsFormula(Box::new(
            SLOCountDefinitionWithTotalEventsFormula::new(
                SLOFormula::new("query1 - query2".to_string()),
                vec![
                    SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
                        Box::new(FormulaAndFunctionMetricQueryDefinition::new(
                            FormulaAndFunctionMetricDataSource::METRICS,
                            "query1".to_string(),
                            "sum:httpservice.hits{*}.as_count()".to_string(),
                        )),
                    ),
                    SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
                        Box::new(FormulaAndFunctionMetricQueryDefinition::new(
                            FormulaAndFunctionMetricDataSource::METRICS,
                            "query2".to_string(),
                            "sum:httpservice.errors{*}.as_count()".to_string(),
                        )),
                    ),
                ],
                SLOFormula::new("query1".to_string()),
            ),
        )),
    ))))
    .tags(vec!["env:prod".to_string(), "type:count".to_string()])
    .target_threshold(99.0 as f64)
    .timeframe(SLOTimeframe::SEVEN_DAYS)
    .warning_threshold(99.5 as f64);
    let configuration = datadog::Configuration::new();
    let api = ServiceLevelObjectivesAPI::with_config(configuration);
    let resp = api.create_slo(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

##### 

```rust
// Create a time-slice SLO object returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_service_level_objectives::ServiceLevelObjectivesAPI;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
use datadog_api_client::datadogV1::model::SLODataSourceQueryDefinition;
use datadog_api_client::datadogV1::model::SLOFormula;
use datadog_api_client::datadogV1::model::SLOSliSpec;
use datadog_api_client::datadogV1::model::SLOThreshold;
use datadog_api_client::datadogV1::model::SLOTimeSliceComparator;
use datadog_api_client::datadogV1::model::SLOTimeSliceCondition;
use datadog_api_client::datadogV1::model::SLOTimeSliceQuery;
use datadog_api_client::datadogV1::model::SLOTimeSliceSpec;
use datadog_api_client::datadogV1::model::SLOTimeframe;
use datadog_api_client::datadogV1::model::SLOType;
use datadog_api_client::datadogV1::model::ServiceLevelObjectiveRequest;

#[tokio::main]
async fn main() {
    let body = ServiceLevelObjectiveRequest::new(
        "Example-Service-Level-Objective".to_string(),
        vec![SLOThreshold::new(97.0, SLOTimeframe::SEVEN_DAYS)
            .target_display("97.0".to_string())
            .warning(98.0 as f64)
            .warning_display("98.0".to_string())],
        SLOType::TIME_SLICE,
    )
    .description(Some("string".to_string()))
    .sli_specification(SLOSliSpec::SLOTimeSliceSpec(Box::new(
        SLOTimeSliceSpec::new(SLOTimeSliceCondition::new(
            SLOTimeSliceComparator::GREATER,
            SLOTimeSliceQuery::new(
                vec![SLOFormula::new("query1".to_string())],
                vec![
                    SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
                        Box::new(FormulaAndFunctionMetricQueryDefinition::new(
                            FormulaAndFunctionMetricDataSource::METRICS,
                            "query1".to_string(),
                            "trace.servlet.request{env:prod}".to_string(),
                        )),
                    ),
                ],
            ),
            5.0,
        )),
    )))
    .tags(vec!["env:prod".to_string()])
    .target_threshold(97.0 as f64)
    .timeframe(SLOTimeframe::SEVEN_DAYS)
    .warning_threshold(98.0 as f64);
    let configuration = datadog::Configuration::new();
    let api = ServiceLevelObjectivesAPI::with_config(configuration);
    let resp = api.create_slo(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
##### 

```typescript
/**
 * Create a new metric SLO object using bad events formula returns "OK" response
 */

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

const configuration = client.createConfiguration();
const apiInstance = new v1.ServiceLevelObjectivesApi(configuration);

const params: v1.ServiceLevelObjectivesApiCreateSLORequest = {
  body: {
    type: "metric",
    description: "Metric SLO using sli_specification",
    name: "Example-Service-Level-Objective",
    sliSpecification: {
      count: {
        goodEventsFormula: {
          formula: "query1 - query2",
        },
        badEventsFormula: {
          formula: "query2",
        },
        queries: [
          {
            dataSource: "metrics",
            name: "query1",
            query: "sum:httpservice.hits{*}.as_count()",
          },
          {
            dataSource: "metrics",
            name: "query2",
            query: "sum:httpservice.errors{*}.as_count()",
          },
        ],
      },
    },
    tags: ["env:prod", "type:count"],
    thresholds: [
      {
        target: 99.0,
        targetDisplay: "99.0",
        timeframe: "7d",
        warning: 99.5,
        warningDisplay: "99.5",
      },
    ],
    timeframe: "7d",
    targetThreshold: 99.0,
    warningThreshold: 99.5,
  },
};

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

##### 

```typescript
/**
 * Create a new metric SLO object using sli_specification returns "OK" response
 */

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

const configuration = client.createConfiguration();
const apiInstance = new v1.ServiceLevelObjectivesApi(configuration);

const params: v1.ServiceLevelObjectivesApiCreateSLORequest = {
  body: {
    type: "metric",
    description: "Metric SLO using sli_specification",
    name: "Example-Service-Level-Objective",
    sliSpecification: {
      count: {
        goodEventsFormula: {
          formula: "query1 - query2",
        },
        totalEventsFormula: {
          formula: "query1",
        },
        queries: [
          {
            dataSource: "metrics",
            name: "query1",
            query: "sum:httpservice.hits{*}.as_count()",
          },
          {
            dataSource: "metrics",
            name: "query2",
            query: "sum:httpservice.errors{*}.as_count()",
          },
        ],
      },
    },
    tags: ["env:prod", "type:count"],
    thresholds: [
      {
        target: 99.0,
        targetDisplay: "99.0",
        timeframe: "7d",
        warning: 99.5,
        warningDisplay: "99.5",
      },
    ],
    timeframe: "7d",
    targetThreshold: 99.0,
    warningThreshold: 99.5,
  },
};

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

##### 

```typescript
/**
 * Create a time-slice SLO object returns "OK" response
 */

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

const configuration = client.createConfiguration();
const apiInstance = new v1.ServiceLevelObjectivesApi(configuration);

const params: v1.ServiceLevelObjectivesApiCreateSLORequest = {
  body: {
    type: "time_slice",
    description: "string",
    name: "Example-Service-Level-Objective",
    sliSpecification: {
      timeSlice: {
        query: {
          formulas: [
            {
              formula: "query1",
            },
          ],
          queries: [
            {
              dataSource: "metrics",
              name: "query1",
              query: "trace.servlet.request{env:prod}",
            },
          ],
        },
        comparator: ">",
        threshold: 5,
      },
    },
    tags: ["env:prod"],
    thresholds: [
      {
        target: 97.0,
        targetDisplay: "97.0",
        timeframe: "7d",
        warning: 98,
        warningDisplay: "98.0",
      },
    ],
    timeframe: "7d",
    targetThreshold: 97.0,
    warningThreshold: 98,
  },
};

apiInstance
  .createSLO(params)
  .then((data: v1.SLOListResponse) => {
    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://docs.datadoghq.com/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"
{% /tab %}
