> ## Documentation Index
> Fetch the complete documentation index at: https://developer.onetrust.com/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /metric

Record a metrics event. Metrics are used to track classification activity, redaction actions, agent response times, and user sessions in OneTrust AI Governance.

## Endpoint

```
POST /metric
```

## Authentication

Requires `Authorization: Bearer <token>` header. Returns `401 Unauthorized` with a `WWW-Authenticate` header if the token is missing or invalid.

## Request Body

```json
{
  "attributes": {
    "agent_id": "example-agent-001",
    "platform": "AMAZON_BEDROCK",
    "new_session": "true"
  },
  "meter": {
    "name": "ai_guard.user",
    "value": "1"
  }
}
```

### Request Fields

| Field         | Type     | Required | Description                                                       |
| ------------- | -------- | -------- | ----------------------------------------------------------------- |
| `attributes`  | `object` | Yes      | Key-value pairs of metric attributes (all values must be strings) |
| `meter`       | `object` | Yes      | The meter definition                                              |
| `meter.name`  | `string` | Yes      | Meter name (see supported meters below)                           |
| `meter.value` | `string` | Yes      | Meter value as a string                                           |

### Required Attributes

All metric events must include these attributes:

| Attribute  | Description                                                                                       |
| ---------- | ------------------------------------------------------------------------------------------------- |
| `agent_id` | Unique identifier for the calling agent                                                           |
| `platform` | AI platform: `AMAZON_BEDROCK`, `AMAZON_SAGEMAKER`, `AZURE_FOUNDRY`, `DATABRICKS`, or `GCP_VERTEX` |

> 📘 SDK Note
>
> When using the Python SDK, `agent_id` and `platform` are injected automatically by the client. You only need to specify additional attributes.

## Supported Meters

### `ai_guard.agent` — Agent Response Time

Records LLM agent response time as a histogram.

```json
{
  "attributes": { "agent_id": "my-agent", "platform": "AMAZON_BEDROCK" },
  "meter": { "name": "ai_guard.agent", "value": "1234" }
}
```

| Value         | Format                        | Description                                        |
| ------------- | ----------------------------- | -------------------------------------------------- |
| Response time | Integer string (milliseconds) | Time taken by the LLM agent to generate a response |

### `ai_guard.user` — User Session

Records a user interaction or session event as a counter.

```json
{
  "attributes": { "agent_id": "my-agent", "platform": "AMAZON_BEDROCK", "new_session": "true" },
  "meter": { "name": "ai_guard.user", "value": "1" }
}
```

| Additional Attribute | Required | Values                | Description                             |
| -------------------- | -------- | --------------------- | --------------------------------------- |
| `new_session`        | Yes      | `"true"` or `"false"` | Whether this event starts a new session |

### `ai_guard.redact` — Redaction Event

Records a redaction or block action as a counter.

```json
{
  "attributes": { "agent_id": "my-agent", "platform": "AMAZON_BEDROCK", "action": "redact", "actor": "user" },
  "meter": { "name": "ai_guard.redact", "value": "1" }
}
```

| Additional Attribute | Required | Values                  | Description                        |
| -------------------- | -------- | ----------------------- | ---------------------------------- |
| `action`             | Yes      | `"redact"` or `"block"` | The type of redaction action taken |
| `actor`              | Yes      | `"user"` or `"agent"`   | Source of the classified text      |

## Response

### 200 OK

Returns an empty body on success.

### Error Responses

#### 400 Bad Request

Returned if metrics are not enabled on the server or the request is malformed:

```json
{
  "code": 400,
  "message": "Metrics not permitted"
}
```

#### 401 Unauthorized

```json
{
  "code": 401,
  "message": "Invalid or missing bearer token"
}
```

## curl Example

```bash
curl -X POST https://localhost:4443/metric \
  --pinnedpubkey "sha256//x48Lk2iu3R3nAhSiz07bExGHTusDRjHqBx9ArK3cFGE=" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "attributes": { "agent_id": "my-agent", "platform": "AMAZON_BEDROCK", "new_session": "true" },
    "meter": {
      "name": "ai_guard.user",
      "value": "1"
    }
  }'
```

## SDK Usage

For Python SDK usage, see [Observability & Metrics](https://developer.onetrust.com/onetrust/docs/ai-guard-metrics).