# Canary baselines

Per-agent normal ranges that relative canary rules compare against.

Related guide: [Canary baselines](https://provenanceauth.com/docs/trace/concepts/baselines.md)

## Endpoints

- `POST /v1/trace/baselines`: [Create canary baselines](#post-v1-trace-baselines)
- `GET /v1/trace/baselines/{id}`: [Retrieve a canary baseline](#get-v1-trace-baselines-id)
- `GET /v1/trace/baselines`: [List canary baselines](#get-v1-trace-baselines)
- `DELETE /v1/trace/baselines/{id}`: [Delete a canary baseline](#delete-v1-trace-baselines-id)
- `POST /v1/trace/baselines/{id}/relearn`: [Re-learn a canary baseline](#post-v1-trace-baselines-id-relearn)

## The trace canary baseline object

### Attributes

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | no | Unique identifier for the object. |
| `object` | enum | no | The type of object. One of `trace_canary_baseline`. |
| `agent_id` | string \| null | no | The registered agent's ID. |
| `scope` | enum | no | What the object applies to. One of `agent`, `account`. |
| `model_version` | string | no | The model version, as a registry model ID. |
| `family` | string | no | The canary family. |
| `version` | integer | no | The version number. |
| `status` | enum | no | The object's current status. One of `learning`, `ready`, `stale`, `superseded`. |
| `min_samples` | integer | no | Readings needed before the baseline is ready. |
| `n` | integer | no | The number of samples it's based on. |
| `excluded` | integer | no | Readings left out because they tripped an absolute threshold. |
| `mean` | number | no | The mean score learned. |
| `sigma` | number | no | The standard deviation learned. |
| `sigma_floor` | number | no | The smallest standard deviation used, so a quiet baseline doesn't trip on tiny changes. |
| `histogram` | array of integers | no | 100 bins over [0, 1]. |
| `started_at` | timestamp | no | When learning started. |
| `ready_at` | timestamp \| null | no | When it became ready; null while learning. |
| `stale_at` | timestamp \| null | no | When it went stale; null while current. |
| `updated_at` | timestamp | no | When it last changed. |
| `deleted` | enum | no | Always true for a deleted object. One of `true`. |

### Example

```json
{
  "id": "cbl_01M6VQC3ZTADBA4G41FR6QHPAP",
  "object": "trace_canary_baseline",
  "agent_id": null,
  "scope": "account",
  "model_version": "qwen2.5-0.5b-instruct@7ae55760",
  "family": "prompt_injection",
  "version": 1,
  "status": "learning",
  "min_samples": 20,
  "n": 0,
  "excluded": 0,
  "mean": 0,
  "sigma": 0,
  "sigma_floor": 0.01,
  "histogram": [
    0,
    0,
    0,
    "… 97 more"
  ],
  "started_at": "2026-11-07T19:22:10.298Z",
  "ready_at": null,
  "stale_at": null,
  "updated_at": "2026-11-07T19:22:10.298Z"
}
```

## Create canary baselines

`POST /v1/trace/baselines`

Starts learning a baseline per canary family for one agent, or for the whole account, from its traced readings. Relative canary rules read the baseline once it's ready.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |
| `agent_id` | body | string | no | The registered agent's ID. |
| `model_version` | body | string | yes | The model version, as a registry model ID. |
| `families` | body | array of strings | no | Canary families. |
| `min_samples` | body | integer | no | Readings needed before the baseline is ready. |

### Returns

The baselines, now learning.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`invalid_json`](https://provenanceauth.com/docs/platform/errors.md#invalid_json)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`parameter_missing`](https://provenanceauth.com/docs/platform/errors.md#parameter_missing)
- [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)
- [`trace_baseline_exists`](https://provenanceauth.com/docs/platform/errors.md#trace_baseline_exists)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X POST "$PROVENANCE_API/v1/trace/baselines" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model_version": "qwen2.5-0.5b-instruct@7ae55760",
    "families": [
      "prompt_injection"
    ],
    "min_samples": 20
  }'
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/baselines`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "model_version": "qwen2.5-0.5b-instruct@7ae55760",
    "families": [
      "prompt_injection"
    ],
    "min_samples": 20
  }),
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.post(f"{api}/v1/trace/baselines", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "model_version": "qwen2.5-0.5b-instruct@7ae55760",
    "families": [
        "prompt_injection"
    ],
    "min_samples": 20
}).json()
```

### Response 201

```json
{
  "object": "list",
  "data": [
    {
      "id": "cbl_01M6VQC3ZTADBA4G41FR6QHPAP",
      "object": "trace_canary_baseline",
      "agent_id": null,
      "scope": "account",
      "model_version": "qwen2.5-0.5b-instruct@7ae55760",
      "family": "prompt_injection",
      "version": 1,
      "status": "learning",
      "min_samples": 20,
      "n": 0,
      "excluded": 0,
      "mean": 0,
      "sigma": 0,
      "sigma_floor": 0.01,
      "histogram": [
        0,
        0,
        0,
        "… 97 more"
      ],
      "started_at": "2026-11-07T19:22:10.298Z",
      "ready_at": null,
      "stale_at": null,
      "updated_at": "2026-11-07T19:22:10.298Z"
    }
  ],
  "has_more": false,
  "next_cursor": null
}
```

## Retrieve a canary baseline

`GET /v1/trace/baselines/{id}`

Returns one baseline with its sample count, mean, spread and status.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

No parameters.

### Returns

The baseline. See [the trace canary baseline object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X POST "$PROVENANCE_API/v1/mandate/agents" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "invoice-bot" }' > step.json
export AGENT_ID=$(jq -r '.id' step.json)
curl -s -X POST "$PROVENANCE_API/v1/trace/baselines" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"agent_id\": \"$AGENT_ID\",
    \"model_version\": \"qwen2.5-0.5b-instruct@7ae55760\",
    \"families\": [
      \"prompt_injection\"
    ],
    \"min_samples\": 20
  }" > step.json
export BASELINE_ID=$(jq -r '.data[0].id' step.json)
curl "$PROVENANCE_API/v1/trace/baselines/$BASELINE_ID" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/mandate/agents`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({ "name": "invoice-bot" }),
})).json();
const agentId = step1.id;
const step2 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/baselines`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "agent_id": agentId,
    "model_version": "qwen2.5-0.5b-instruct@7ae55760",
    "families": [
      "prompt_injection"
    ],
    "min_samples": 20
  }),
})).json();
const baselineId = step2.data[0].id;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/baselines/${baselineId}`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.post(f"{api}/v1/mandate/agents", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "name": "invoice-bot"
}).json()
agent_id = step1["id"]
step2 = httpx.post(f"{api}/v1/trace/baselines", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "agent_id": agent_id,
    "model_version": "qwen2.5-0.5b-instruct@7ae55760",
    "families": [
        "prompt_injection"
    ],
    "min_samples": 20
}).json()
baseline_id = step2["data"][0]["id"]
data = httpx.get(f"{api}/v1/trace/baselines/{baseline_id}", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "id": "cbl_01M6VQC3ZVB52JSAQHN9H52SX3",
  "object": "trace_canary_baseline",
  "agent_id": "agt_01M6VQC3ZTFEAJAJ3NWH4A0FBF",
  "scope": "agent",
  "model_version": "qwen2.5-0.5b-instruct@7ae55760",
  "family": "prompt_injection",
  "version": 1,
  "status": "learning",
  "min_samples": 20,
  "n": 0,
  "excluded": 0,
  "mean": 0,
  "sigma": 0,
  "sigma_floor": 0.01,
  "histogram": [
    0,
    0,
    0,
    "… 97 more"
  ],
  "started_at": "2026-11-07T19:22:10.299Z",
  "ready_at": null,
  "stale_at": null,
  "updated_at": "2026-11-07T19:22:10.299Z"
}
```

## List canary baselines

`GET /v1/trace/baselines`

Lists your canary baselines with their status and learned statistics.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `agent_id` | query | string | no | The registered agent's ID. |
| `model_version` | query | string | no | The model version, as a registry model ID. |
| `status` | query | enum | no | The object's current status. One of `learning`, `ready`, `stale`, `superseded`. |
| `limit` | query | integer | no | The most items to return, from 1 to 100. The default is 20. |
| `cursor` | query | string | no | The `next_cursor` from the previous page. |

### Returns

The baselines, newest first.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`parameter_missing`](https://provenanceauth.com/docs/platform/errors.md#parameter_missing)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl "$PROVENANCE_API/v1/trace/baselines" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/baselines`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.get(f"{api}/v1/trace/baselines", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "list",
  "data": [],
  "has_more": false,
  "next_cursor": null
}
```

## Delete a canary baseline

`DELETE /v1/trace/baselines/{id}`

Deletes a baseline.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

No parameters.

### Returns

The deleted object. See [the trace canary baseline object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X POST "$PROVENANCE_API/v1/mandate/agents" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "invoice-bot" }' > step.json
export AGENT_ID=$(jq -r '.id' step.json)
curl -s -X POST "$PROVENANCE_API/v1/trace/baselines" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"agent_id\": \"$AGENT_ID\",
    \"model_version\": \"qwen2.5-0.5b-instruct@7ae55760\",
    \"families\": [
      \"prompt_injection\"
    ],
    \"min_samples\": 20
  }" > step.json
export BASELINE_ID=$(jq -r '.data[0].id' step.json)
curl -X DELETE "$PROVENANCE_API/v1/trace/baselines/$BASELINE_ID" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/mandate/agents`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({ "name": "invoice-bot" }),
})).json();
const agentId = step1.id;
const step2 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/baselines`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "agent_id": agentId,
    "model_version": "qwen2.5-0.5b-instruct@7ae55760",
    "families": [
      "prompt_injection"
    ],
    "min_samples": 20
  }),
})).json();
const baselineId = step2.data[0].id;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/baselines/${baselineId}`, {
  method: "DELETE",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.post(f"{api}/v1/mandate/agents", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "name": "invoice-bot"
}).json()
agent_id = step1["id"]
step2 = httpx.post(f"{api}/v1/trace/baselines", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "agent_id": agent_id,
    "model_version": "qwen2.5-0.5b-instruct@7ae55760",
    "families": [
        "prompt_injection"
    ],
    "min_samples": 20
}).json()
baseline_id = step2["data"][0]["id"]
data = httpx.delete(f"{api}/v1/trace/baselines/{baseline_id}", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "id": "cbl_01M6VQC3ZYPHVSY9AA5927SX7Z",
  "object": "trace_canary_baseline",
  "deleted": true
}
```

## Re-learn a canary baseline

`POST /v1/trace/baselines/{id}/relearn`

Starts a new version of a baseline from scratch. The current version keeps serving until the new one is ready.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |

### Returns

The new baseline version, now learning. See [the trace canary baseline object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`parameter_missing`](https://provenanceauth.com/docs/platform/errors.md#parameter_missing)
- [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)
- [`trace_baseline_exists`](https://provenanceauth.com/docs/platform/errors.md#trace_baseline_exists)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X POST "$PROVENANCE_API/v1/trace/baselines/cbl_01M5QYCNK0ZC7PTD9E04A15A7E/relearn" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/baselines/cbl_01M5QYCNK0ZC7PTD9E04A15A7E/relearn`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.post(f"{api}/v1/trace/baselines/cbl_01M5QYCNK0ZC7PTD9E04A15A7E/relearn", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 201

```json
{
  "id": "cbl_01M5R0CRN3WESNVCQYET3WP313",
  "object": "trace_canary_baseline",
  "agent_id": null,
  "scope": "account",
  "model_version": "qwen2.5-0.5b-instruct@7ae55760",
  "family": "prompt_injection",
  "version": 2,
  "status": "learning",
  "min_samples": 20,
  "n": 0,
  "excluded": 0,
  "mean": 0,
  "sigma": 0,
  "sigma_floor": 0.01,
  "histogram": [
    0,
    0,
    0,
    "… 97 more"
  ],
  "started_at": "2026-10-24T22:49:02.130Z",
  "ready_at": null,
  "stale_at": null,
  "updated_at": "2026-10-24T22:49:02.130Z"
}
```
