> For the complete documentation index, see [llms.txt](https://docs.groundcover.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/metric-pipelines-api.md).

# Metric Pipelines API

Manage metric relabeling rules through the API.

### Authentication and permissions

Use an [API key](https://docs.groundcover.com/administer/api-keys.md) in `Authorization: Bearer <YOUR_API_KEY>` and select the backend with `X-Backend-Id: <YOUR_BACKEND_ID>`. Use your own API base URL for a self-hosted deployment.

**Admin required:** creating, replacing or clearing the pipeline configuration. Reading configuration requires backend access but does not require Admin permissions.

### Endpoints

GET, POST, PUT, and DELETE use `/api/pipelines/v1/metrics/config`. **POST, PUT and DELETE require Admin permissions**; GET requires backend access.

### Request body

POST and PUT accept a JSON `rules` object. Unlike log and trace pipelines, this API does **not** use a `value` string.

| Field within `rules` | Type             | Description                                                                   |
| -------------------- | ---------------- | ----------------------------------------------------------------------------- |
| `keepRegex`          | array of strings | Keep metric names matching the configured regular expressions.                |
| `dropRegex`          | array of strings | Drop matching metric names.                                                   |
| `addLabel`           | object           | Label names mapped to string values to add.                                   |
| `removeLabel`        | array of strings | Labels to remove.                                                             |
| `raw`                | string           | Advanced relabeling rules as YAML or JSON text, embedded in the JSON request. |

These rules operate on incoming metric series. Keep/drop rules use `__name__` as their default source label. Writes replace the complete configuration; save the existing response and retain needed rules.

### Read and update

```bash
curl --request GET 'https://api.groundcover.com/api/pipelines/v1/metrics/config' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>'
```

```bash
curl --request PUT 'https://api.groundcover.com/api/pipelines/v1/metrics/config' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>' \
  --header 'Content-Type: application/json' \
  --data '{
  "rules": {
    "addLabel": {
      "pipeline": "example"
    }
  }
}'
```

A successful GET or PUT returns HTTP 200 with `uuid`, `created_by`, `created_timestamp`, and `rules`. GET returns HTTP 204 if no configuration exists. POST accepts the same body and returns HTTP 201. Invalid relabeling configuration returns HTTP 400.

### Advanced relabeling rules

For `rules.raw`, keep the relabeling list in a readable YAML file and use `jq` to embed it as a JSON string. This example requires `jq`. The outer HTTP body remains JSON; only the `raw` string is parsed as YAML or JSON.

This example sets the same `pipeline` label as the structured example above. Include any other rules you want to retain before replacing the configuration.

```bash
cat > metric-relabeling.yaml <<'YAML'
- action: replace
  target_label: pipeline
  replacement: example
YAML

jq -n --rawfile raw metric-relabeling.yaml '{rules: {raw: $raw}}' |
curl --request PUT 'https://api.groundcover.com/api/pipelines/v1/metrics/config' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>' \
  --header 'Content-Type: application/json' \
  --data-binary @-
```

To display saved raw rules with their original line breaks, append `| jq -r '.rules.raw // empty'` to the GET command.

### Delete

```bash
curl --request DELETE 'https://api.groundcover.com/api/pipelines/v1/metrics/config' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>'
```

HTTP 200 with no body indicates the dynamic configuration was cleared. This affects future ingestion; previously stored samples are not rewritten.

See also [Metrics Aggregation API](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/metrics-aggregation-api.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/metric-pipelines-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
