---
title: Create a tag configuration
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Metrics
---

# Create a tag configuration{% #create-a-tag-configuration %}
Copy pageCopied
{% tab title="v2" %}

| Datadog site      | API endpoint                                                         |
| ----------------- | -------------------------------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/metrics/{metric_name}/tags |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/metrics/{metric_name}/tags |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/metrics/{metric_name}/tags      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/metrics/{metric_name}/tags      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/metrics/{metric_name}/tags  |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/metrics/{metric_name}/tags     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/metrics/{metric_name}/tags |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/metrics/{metric_name}/tags |

### Overview

Create and define a list of queryable tag keys for an existing count/gauge/rate/distribution metric. Optionally, include percentile aggregations on any distribution metric. By setting `exclude_tags_mode` to true, the behavior is changed from an allow-list to a deny-list, and tags in the defined list are not queryable. Can only be used with application keys of users with the `Manage Tags for Metrics` permission. This endpoint requires the `metric_tags_write` permission.

### Arguments

#### Path Parameters

| Name                          | Type   | Description             |
| ----------------------------- | ------ | ----------------------- |
| metric_name [*required*] | string | The name of the metric. |

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field | Field                         | Type     | Description                                                                                                                                                                                                                                                         |
| ------------ | ----------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|              | data [*required*]        | object   | Object for a single metric to be configure tags on.                                                                                                                                                                                                                 |
| data         | attributes                    | object   | Object containing the definition of a metric tag configuration to be created.                                                                                                                                                                                       |
| attributes   | aggregations                  | [object] | Deprecated. You no longer need to configure specific time and space aggregations for Metrics Without Limits.                                                                                                                                                        |
| aggregations | space [*required*]       | enum     | A space aggregation for use in query. Allowed enum values: `avg,max,min,sum`                                                                                                                                                                                        |
| aggregations | time [*required*]        | enum     | A time aggregation for use in query. Allowed enum values: `avg,count,max,min,sum`                                                                                                                                                                                   |
| attributes   | exclude_tags_mode             | boolean  | When set to true, the configuration will exclude the configured tags and include any other submitted tags. When set to false, the configuration will include the configured tags and exclude any other submitted tags. Defaults to false. Requires `tags` property. |
| attributes   | include_percentiles           | boolean  | Toggle to include/exclude percentiles for a distribution metric. Defaults to false. Can only be applied to metrics that have a `metric_type` of `distribution`.                                                                                                     |
| attributes   | metric_type [*required*] | enum     | The metric's type. Allowed enum values: `gauge,count,rate,distribution`                                                                                                                                                                                             |
| attributes   | tags [*required*]        | [string] | A list of tag keys that will be queryable for your metric.                                                                                                                                                                                                          |
| data         | id [*required*]          | string   | The metric name for this resource.                                                                                                                                                                                                                                  |
| data         | type [*required*]        | enum     | The metric tag configuration resource type. Allowed enum values: `manage_tags`                                                                                                                                                                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "type": "manage_tags",
    "id": "ExampleMetric",
    "attributes": {
      "tags": [
        "app",
        "datacenter"
      ],
      "metric_type": "gauge"
    }
  }
}
```

{% /tab %}

### Response

{% tab title="201" %}
Created
{% tab title="Model" %}
Response object which includes a single metric's tag configuration.

| Parent field | Field                   | Type      | Description                                                                                                                                                                                                                                                         |
| ------------ | ----------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|              | data                    | object    | Object for a single metric tag configuration.                                                                                                                                                                                                                       |
| data         | attributes              | object    | Object containing the definition of a metric tag configuration attributes.                                                                                                                                                                                          |
| attributes   | aggregations            | [object]  | Deprecated. You no longer need to configure specific time and space aggregations for Metrics Without Limits.                                                                                                                                                        |
| aggregations | space [*required*] | enum      | A space aggregation for use in query. Allowed enum values: `avg,max,min,sum`                                                                                                                                                                                        |
| aggregations | time [*required*]  | enum      | A time aggregation for use in query. Allowed enum values: `avg,count,max,min,sum`                                                                                                                                                                                   |
| attributes   | created_at              | date-time | Timestamp when the tag configuration was created.                                                                                                                                                                                                                   |
| attributes   | exclude_tags_mode       | boolean   | When set to true, the configuration will exclude the configured tags and include any other submitted tags. When set to false, the configuration will include the configured tags and exclude any other submitted tags. Defaults to false. Requires `tags` property. |
| attributes   | include_percentiles     | boolean   | Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the `metric_type` is `distribution`.                                                                                                                               |
| attributes   | metric_type             | enum      | The metric's type. Allowed enum values: `gauge,count,rate,distribution`                                                                                                                                                                                             |
| attributes   | modified_at             | date-time | Timestamp when the tag configuration was last modified.                                                                                                                                                                                                             |
| attributes   | tags                    | [string]  | List of tag keys on which to group.                                                                                                                                                                                                                                 |
| data         | id                      | string    | The metric name for this resource.                                                                                                                                                                                                                                  |
| data         | type                    | enum      | The metric tag configuration resource type. Allowed enum values: `manage_tags`                                                                                                                                                                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "aggregations": [
        {
          "space": "sum",
          "time": "sum"
        }
      ],
      "created_at": "2020-03-25T09:48:37.463835Z",
      "exclude_tags_mode": false,
      "include_percentiles": true,
      "metric_type": "count",
      "modified_at": "2020-03-25T09:48:37.463835Z",
      "tags": [
        "app",
        "datacenter"
      ]
    },
    "id": "test.metric.latency",
    "type": "manage_tags"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

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

{% /tab %}

{% /tab %}

{% tab title="403" %}
Forbidden
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

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

{% /tab %}

{% /tab %}

{% tab title="409" %}
Conflict
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

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

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too Many Requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

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

{% /tab %}

{% /tab %}

### Code Example

##### 
                          \## default
# 
 \# Path parameters export metric_name="dist.http.endpoint.request" \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/metrics/${metric_name}/tags" \
-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
{
  "data": {
    "attributes": {
      "include_percentiles": false,
      "metric_type": "distribution",
      "tags": [
        "app",
        "datacenter"
      ]
    },
    "id": "http.endpoint.request",
    "type": "manage_tags"
  }
}
EOF 
                        
##### 

```go
// Create a tag configuration returns "Created" response

package main

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

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

func main() {
	body := datadogV2.MetricTagConfigurationCreateRequest{
		Data: datadogV2.MetricTagConfigurationCreateData{
			Type: datadogV2.METRICTAGCONFIGURATIONTYPE_MANAGE_TAGS,
			Id:   "ExampleMetric",
			Attributes: &datadogV2.MetricTagConfigurationCreateAttributes{
				Tags: []string{
					"app",
					"datacenter",
				},
				MetricType: datadogV2.METRICTAGCONFIGURATIONMETRICTYPES_GAUGE,
			},
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewMetricsApi(apiClient)
	resp, r, err := api.CreateTagConfiguration(ctx, "ExampleMetric", body)

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

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `MetricsApi.CreateTagConfiguration`:\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="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
##### 

```java
// Create a tag configuration returns "Created" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.MetricsApi;
import com.datadog.api.client.v2.model.MetricTagConfigurationCreateAttributes;
import com.datadog.api.client.v2.model.MetricTagConfigurationCreateData;
import com.datadog.api.client.v2.model.MetricTagConfigurationCreateRequest;
import com.datadog.api.client.v2.model.MetricTagConfigurationMetricTypes;
import com.datadog.api.client.v2.model.MetricTagConfigurationResponse;
import com.datadog.api.client.v2.model.MetricTagConfigurationType;
import java.util.Arrays;

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

    MetricTagConfigurationCreateRequest body =
        new MetricTagConfigurationCreateRequest()
            .data(
                new MetricTagConfigurationCreateData()
                    .type(MetricTagConfigurationType.MANAGE_TAGS)
                    .id("ExampleMetric")
                    .attributes(
                        new MetricTagConfigurationCreateAttributes()
                            .tags(Arrays.asList("app", "datacenter"))
                            .metricType(MetricTagConfigurationMetricTypes.GAUGE)));

    try {
      MetricTagConfigurationResponse result =
          apiInstance.createTagConfiguration("ExampleMetric", body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling MetricsApi#createTagConfiguration");
      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="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
##### 

```python
"""
Create a tag configuration returns "Created" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.metrics_api import MetricsApi
from datadog_api_client.v2.model.metric_tag_configuration_create_attributes import (
    MetricTagConfigurationCreateAttributes,
)
from datadog_api_client.v2.model.metric_tag_configuration_create_data import MetricTagConfigurationCreateData
from datadog_api_client.v2.model.metric_tag_configuration_create_request import MetricTagConfigurationCreateRequest
from datadog_api_client.v2.model.metric_tag_configuration_metric_types import MetricTagConfigurationMetricTypes
from datadog_api_client.v2.model.metric_tag_configuration_type import MetricTagConfigurationType

body = MetricTagConfigurationCreateRequest(
    data=MetricTagConfigurationCreateData(
        type=MetricTagConfigurationType.MANAGE_TAGS,
        id="ExampleMetric",
        attributes=MetricTagConfigurationCreateAttributes(
            tags=[
                "app",
                "datacenter",
            ],
            metric_type=MetricTagConfigurationMetricTypes.GAUGE,
        ),
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = MetricsApi(api_client)
    response = api_instance.create_tag_configuration(metric_name="ExampleMetric", 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="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
##### 

```ruby
# Create a tag configuration returns "Created" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::MetricsAPI.new

body = DatadogAPIClient::V2::MetricTagConfigurationCreateRequest.new({
  data: DatadogAPIClient::V2::MetricTagConfigurationCreateData.new({
    type: DatadogAPIClient::V2::MetricTagConfigurationType::MANAGE_TAGS,
    id: "ExampleMetric",
    attributes: DatadogAPIClient::V2::MetricTagConfigurationCreateAttributes.new({
      tags: [
        "app",
        "datacenter",
      ],
      metric_type: DatadogAPIClient::V2::MetricTagConfigurationMetricTypes::GAUGE,
    }),
  }),
})
p api_instance.create_tag_configuration("ExampleMetric", 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="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"
##### 

```rust
// Create a tag configuration returns "Created" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_metrics::MetricsAPI;
use datadog_api_client::datadogV2::model::MetricTagConfigurationCreateAttributes;
use datadog_api_client::datadogV2::model::MetricTagConfigurationCreateData;
use datadog_api_client::datadogV2::model::MetricTagConfigurationCreateRequest;
use datadog_api_client::datadogV2::model::MetricTagConfigurationMetricTypes;
use datadog_api_client::datadogV2::model::MetricTagConfigurationType;

#[tokio::main]
async fn main() {
    let body = MetricTagConfigurationCreateRequest::new(
        MetricTagConfigurationCreateData::new(
            "ExampleMetric".to_string(),
            MetricTagConfigurationType::MANAGE_TAGS,
        )
        .attributes(MetricTagConfigurationCreateAttributes::new(
            MetricTagConfigurationMetricTypes::GAUGE,
            vec!["app".to_string(), "datacenter".to_string()],
        )),
    );
    let configuration = datadog::Configuration::new();
    let api = MetricsAPI::with_config(configuration);
    let resp = api
        .create_tag_configuration("ExampleMetric".to_string(), 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="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run
##### 

```typescript
/**
 * Create a tag configuration returns "Created" response
 */

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

const configuration = client.createConfiguration();
const apiInstance = new v2.MetricsApi(configuration);

const params: v2.MetricsApiCreateTagConfigurationRequest = {
  body: {
    data: {
      type: "manage_tags",
      id: "ExampleMetric",
      attributes: {
        tags: ["app", "datacenter"],
        metricType: "gauge",
      },
    },
  },
  metricName: "ExampleMetric",
};

apiInstance
  .createTagConfiguration(params)
  .then((data: v2.MetricTagConfigurationResponse) => {
    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="<API-KEY>" DD_APP_KEY="<APP-KEY>" tsc "example.ts"
{% /tab %}
