---
title: "Create Metric"
method: POST
path: "/api/v1/sdk/metrics/{asset_id}"
tags: ["public-api", "public-metrics"]
---

# Create Metric

`POST /api/v1/sdk/metrics/{asset_id}`

## Request

- Base URL: `http://localhost:8000`
- URL: `http://localhost:8000/api/v1/sdk/metrics/{asset_id}`
- Auth: none declared

Create a new metric.

Requires read-write or admin scope.
Accepts asset UUID, qualified name (e.g., "postgresql.mydb"), or asset name.

**SDK Usage:**
```python
from anomalyarmor import Client
client = Client()
metric = client.metrics.create(
    "asset-uuid",
    metric_type="null_percent",
    table_path="catalog.schema.table",
    column_name="email",
)
```

## Path parameters

- `asset_id` string, required

## Headers

- `Authorization` string

## Request body

- MetricDefinitionCreate: Request schema for creating a metric definition. TECH-689: Includes percentile_value for PERCENTILE metric type. Note: asset_id is extracted from the URL path, not the request body.
  - `table_path` string, required: Fully qualified table path
  - `column_name` string, nullable: Column name (NULL for table-level metrics)
  - `time_column` string, nullable: Column containing timestamp/date for time-windowed queries. When set, metric queries filter by this column using capture_interval bounds.
  - `metric_type` 'distinct_count' | 'null_percentage' | 'mean' | 'sum' | 'min' | 'max' | 'duplicate_count' | 'duplicate_percent' | 'percentile', required: Types of metrics that can be tracked. Statistical metrics compute aggregate values over time with ML-based anomaly detection.
  - `capture_interval` string, required: Capture interval (hourly, daily, weekly, or cron)
  - `group_by_columns` string[], nullable: Optional dimensional grouping columns
  - `sensitivity` integer: Stddev multiplier for anomaly detection (1-5)
  - `percentile_value` union: For PERCENTILE metric type: the percentile to track (0.0-1.0)
    - number
    - string
  - `operating_period_mode` 'off' | 'auto' | 'schedule': Operating-period awareness (TECH-984): 'off' pools all history, 'schedule' segments by operating_schedule_id, 'auto' learns a calendar from history
  - `operating_schedule_id` string, uuid, nullable: Public UUID of the operating schedule (required for 'schedule' mode)

## Response `201`

Successful Response

- StandardResponse: Standard API response wrapper.
  - `success` boolean, required
  - `data` unknown
  - `message` string, nullable
  - `error` string, nullable
  - `meta` object, nullable

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/anomalyarmor/apis/anomalyarmor-api.md) · [All operations](https://skmtc.dev/anomalyarmor/apis/anomalyarmor-api/llms.txt) · [OpenAPI document](https://skmtc.dev/anomalyarmor/apis/anomalyarmor-api/revisions/51c755fb5d0b?raw)
