---
title: "Create Metric"
method: POST
path: "/metrics"
tags: ["Metric"]
---

# Create Metric

`POST /metrics`

## Request

- Base URL: `https://oneuptime.com/api`
- URL: `https://oneuptime.com/api/metrics`
- Auth: API key in header `APIKey`
- TypeScript: <https://skmtc.dev/oneuptime/apis/oneuptime-openapi-specification/docs/metrics/post.ts> (a function with typed inputs; its response is checked against the schema)

Endpoint to create a new Metric

## Request body

- object
  - `data` MetricItemV3CreateSchema, required: Create schema for MetricItemV3
    - `projectId` string, uuid: ID of project
    - `primaryEntityId` string, uuid, required: ID of the Service which created the Metric
    - `primaryEntityType` string: Type of the service that this telemetry belongs to
    - `name` string, required: Name of the Metric
    - `aggregationTemporality` string: Aggregation Temporality of this Metric
    - `metricPointType` string: Metric Point Type of this Metric
    - `time` string, date-time, required: When did the Metric happen?
    - `startTime` string, date-time: When did the Metric happen?
    - `timeUnixNano` union, required: When did the Metric happen?
      - number
      - string
    - `startTimeUnixNano` union: When did the Metric happen?
      - number
      - string
    - `attributes` object: Attributes
    - `attributeKeys` string[]: Attribute keys extracted from attributes
    - `entityKeys` string[]: Stable keys of every OpenTelemetry entity (service, host, k8s.pod, container, ...) this signal belongs to. A superset that includes the primary entity. Enables cross-cutting membership queries via has(entityKeys, :key).
    - `serviceEntityKey` string: Scalar entity key for this entity type (see entityKeys); '' when the resource has no entity of this type.
    - `hostEntityKey` string: Scalar entity key for this entity type (see entityKeys); '' when the resource has no entity of this type.
    - `k8sPodEntityKey` string: Scalar entity key for this entity type (see entityKeys); '' when the resource has no entity of this type.
    - `k8sNodeEntityKey` string: Scalar entity key for this entity type (see entityKeys); '' when the resource has no entity of this type.
    - `k8sClusterEntityKey` string: Scalar entity key for this entity type (see entityKeys); '' when the resource has no entity of this type.
    - `containerEntityKey` string: Scalar entity key for this entity type (see entityKeys); '' when the resource has no entity of this type.
    - `isMonotonic` boolean: Is Monotonic
    - `count` number: Count
    - `sum` number: Sum
    - `value` number: Value
    - `min` number: Min
    - `max` number: Max
    - `bucketCounts` number[]: Bucket Counts
    - `explicitBounds` number[]: Upper bounds (exclusive of the +inf overflow bucket) for each explicit-bucket histogram bucket. Stored as Float64 so sub-integer boundaries (e.g. 0.005, 0.01) survive ingest — the previous Array(Int64) representation silently truncated those to 0.
    - `scale` number: ExponentialHistogram resolution. base = 2^(2^-scale); bucket index `i` covers (base^i, base^(i+1)].
    - `zeroCount` number: ExponentialHistogram count of values within the zero region (|v| <= zeroThreshold).
    - `positiveOffset` number: Bucket index of the first entry in positiveBucketCounts (ExponentialHistogram).
    - `positiveBucketCounts` number[]: Counts for the positive range of an ExponentialHistogram, indexed from positiveOffset.
    - `negativeOffset` number: Bucket index of the first entry in negativeBucketCounts (ExponentialHistogram).
    - `negativeBucketCounts` number[]: Counts for the negative range of an ExponentialHistogram, indexed from negativeOffset.
    - `summaryQuantiles` number[]: Quantile percentages in [0,1] for a Summary metric (parallel to summaryValues).
    - `summaryValues` number[]: Values corresponding to each quantile in summaryQuantiles for a Summary metric.
    - `traceId` string: Trace ID from an exemplar associated with this metric data point
    - `spanId` string: Span ID from an exemplar associated with this metric data point

## Response `201`

Created successfully

- object
  - `data` MetricItemV3ReadSchema
    - `projectId` string, required: Project ID
    - `primaryEntityId` string, required: Service ID
    - `primaryEntityType` string: Service Type
    - `name` string, required: Name
    - `aggregationTemporality` string: Aggregation Temporality
    - `metricPointType` string: Metric Point Type
    - `time` string: Time
    - `startTime` string: Start Time
    - `timeUnixNano` string: Time (in Unix Nano)
    - `startTimeUnixNano` string: Start Time (in Unix Nano)
    - `attributes` string: Attributes
    - `attributeKeys` string[]: Attribute Keys
    - `entityKeys` string[]: Entity Keys
    - `serviceEntityKey` string: Service Entity Key
    - `hostEntityKey` string: Host Entity Key
    - `k8sPodEntityKey` string: Kubernetes Pod Entity Key
    - `k8sNodeEntityKey` string: Kubernetes Node Entity Key
    - `k8sClusterEntityKey` string: Kubernetes Cluster Entity Key
    - `containerEntityKey` string: Container Entity Key
    - `isMonotonic` boolean: Is Monotonic
    - `count` string: Count
    - `sum` number: Sum
    - `value` number: Value
    - `min` number: Min
    - `max` number: Max
    - `bucketCounts` string: Bucket Counts
    - `explicitBounds` string: Explicit Bounds
    - `scale` number: Scale
    - `zeroCount` string: Zero Count
    - `positiveOffset` number: Positive Bucket Offset
    - `positiveBucketCounts` string: Positive Bucket Counts
    - `negativeOffset` number: Negative Bucket Offset
    - `negativeBucketCounts` string: Negative Bucket Counts
    - `summaryQuantiles` string: Summary Quantiles
    - `summaryValues` string: Summary Values
    - `traceId` string: Trace ID
    - `spanId` string: Span ID

## Other responses

- `400`: Bad request. This response indicates that the request was malformed or contained invalid data.
- `401`: Unauthorized. This response indicates that the request requires user authentication.
- `402`: Payment Required. This response indicates that the request requires payment or a valid subscription.
- `403`: Forbidden. This response indicates that the server understood the request, but refuses to authorize it.
- `405`: Project not found. This response indicates that the requested project does not exist or is not accessible.
- `408`: Request Timeout. This response indicates that the server timed out waiting for the request.
- `415`: Unable to reach server. This response indicates that the server is currently unreachable or down.
- `422`: Not authorized. This response indicates that the user does not have permission to access the requested resource.
- `500`: Internal Server Error. This response indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

---

[API](https://skmtc.dev/oneuptime/apis/oneuptime-openapi-specification.md) - [All operations](https://skmtc.dev/oneuptime/apis/oneuptime-openapi-specification/llms.txt) - [OpenAPI document](https://skmtc.dev/oneuptime/apis/oneuptime-openapi-specification/revisions/ba3307d00304?raw)
