---
title: "Create a log-based metric"
method: POST
path: "/api/v2/logs/config/metrics"
tags: ["Logs Metrics"]
---

# Create a log-based metric

`POST /api/v2/logs/config/metrics`

## Request

- Base URL: `https://api.datadoghq.com`
- URL: `https://api.datadoghq.com/api/v2/logs/config/metrics`
- Auth: API key in header `DD-API-KEY` and API key in header `DD-APPLICATION-KEY`

Create a metric based on your ingested logs in your organization.
Returns the log-based metric object from the request body when the request is successful.

## Request body

- LogsMetricCreateRequest: The new log-based metric body.
  - `data` LogsMetricCreateData, required: The new log-based metric properties.
    - `attributes` LogsMetricCreateAttributes, required: The object describing the Datadog log-based metric to create.
      - `compute` LogsMetricCompute, required: The compute rule to compute the log-based metric.
        - `aggregation_type` 'count' | 'distribution', required: The type of aggregation to use.
        - `include_percentiles` boolean: Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the `aggregation_type` is `distribution`.
        - `path` string: The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").
      - `filter` LogsMetricFilter: The log-based metric filter. Logs matching this filter will be aggregated in this metric.
        - `query` string: The search query - following the log search syntax.
      - `group_by` LogsMetricGroupBy[]: The rules for the group by.
        - `path` string, required: The path to the value the log-based metric will be aggregated over.
        - `tag_name` string: Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.
    - `id` string, required: The name of the log-based metric.
    - `type` 'logs_metrics', required: The type of the resource. The value should always be logs_metrics.

## Response `200`

OK

- LogsMetricResponse: The log-based metric object.
  - `data` LogsMetricResponseData: The log-based metric properties.
    - `attributes` LogsMetricResponseAttributes: The object describing a Datadog log-based metric.
      - `compute` LogsMetricResponseCompute: The compute rule to compute the log-based metric.
        - `aggregation_type` 'count' | 'distribution': The type of aggregation to use.
        - `include_percentiles` boolean: Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the `aggregation_type` is `distribution`.
        - `path` string: The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").
      - `filter` LogsMetricResponseFilter: The log-based metric filter. Logs matching this filter will be aggregated in this metric.
        - `query` string: The search query - following the log search syntax.
      - `group_by` LogsMetricResponseGroupBy[]: The rules for the group by.
        - `path` string: The path to the value the log-based metric will be aggregated over.
        - `tag_name` string: Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.
    - `id` string: The name of the log-based metric.
    - `type` 'logs_metrics': The type of the resource. The value should always be logs_metrics.

## Other responses

- `400`: Bad Request
- `403`: Not Authorized
- `409`: Conflict
- `429`: Too many requests

---

[API](https://skmtc.dev/datadog/apis/datadog-api-v2-collection.md) - [All operations](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/llms.txt) - [OpenAPI document](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/revisions/da68bf029e4c?raw)
