# Supported Alert Metrics

These instructions apply to the current Admin Console.

{% hint style="info" %}
Alerts are in early access and may not be available in your account. [Contact Contextual support](mailto:help@contextual.io) to request that Alerts be enabled for your tenant.
{% endhint %}

Choose a supported metric or render a template before authoring a custom rule. Alerts accepts a narrower query contract than the general Solution Metrics API. Passing a general query directly into a rule can fail validation or select different semantics than you intended.

For supported agent and AI Gateway charts, use [Create an alert from a chart](https://docs.contextual.io/operate/alerts/create-alerts-from-charts.md). Chart thresholds use displayed units. API bodies use each metric's raw units. The [alertable metric catalog](https://docs.contextual.io/tenants/tenant-apis/alerts-api/configuration.md#alertable-metric-catalog) describes available platform and AI mappings. Use API templates and constrained queries for Native Object and attachment rules.

## Platform Metrics

The following metrics support an untargeted query with one series per agent. Use a supported template where available.

| Metric | Observed value | Missing-data behavior |
| --- | --- | --- |
| `agent.terminated.count` | Count of starting-to-terminated transitions in the window. | Previously active count series can be zero-filled after a successful observation. |
| `agent.scheduled.count` | Scheduled count in the window. | Previously active count series can be zero-filled after a successful observation. |
| `pulsar_subscription_back_log` | Latest backlog, summed across partitions for the agent. Unit: messages. | Missing gauges are not zero. |
| `http.agent.request.count` | Latest bucket value for the agent. | Do not interpret it as the total across the whole authored window. |

Omit `seriesFilter` to include all returned agents. Use `seriesFilter: { "agentIds": ["AGENT_ID"] }` for a selected set of up to 100 unique IDs. This filter applies to supported grouped platform metrics; it cannot be combined with `target.agentId` or used for AI metrics.

Other supported platform metrics may require a single `target.agentId` and a specific output. Validation determines the accepted metric/target/output combination. Do not infer support from a metric's presence on a dashboard. Container restart rules use window deltas, while backlog is a gauge; their thresholds are not interchangeable.

## AI Metrics

AI metric names begin with `ai.` and require `target.service`. The built-in templates use `ai-gateway-api`. To narrow attempts or requests, set `routeId`, `agentId`, or `nodeId` in `target`. The request metrics `ai.failed-requests` and `ai.fallback-rate` reject the attempt filters `provider`, `modelId`, `status`, and `finishReason`.

Use `target.status: "failed"` to select attempts with an error status, a finish reason of `content-filter` or `error`, or a structured answer cut off at the token limit. Use `"ok"` for the remaining attempts. The older `"error"` and `"success"` values filter by the provider status code alone.

| Metric names | Units or meaning | Grouping |
| --- | --- | --- |
| `ai.attempt-count` | Model attempts in the window | Supported |
| `ai.input-tokens`, `ai.output-tokens`, `ai.cache-read-tokens`, `ai.cache-write-tokens` | Token counts | Supported |
| `ai.attempt-failure-rate` | Share of attempts that meet the failure definition above. A value of `0.05` means 5%. | Supported |
| `ai.failed-requests` | Count of requests whose last attempt failed | `route`, `agent`, `node`, or `failure-type` |
| `ai.fallback-rate` | Share of requests that used more than one trace, including requests that ultimately succeeded | `route`, `agent`, or `node` |
| `ai.cache-hit-ratio` | Ratio from 0 to 1 | Supported |
| `ai.latency` | p95 latency in milliseconds | Supported |
| `ai.total-cost` | Estimated cost in USD | Supported |
| `ai.ttft` | Average time to first token in milliseconds | Ungrouped only |
| `ai.input-cost`, `ai.output-cost`, `ai.uncached-input-cost`, `ai.cache-read-cost`, `ai.cache-write-cost`, `ai.reasoning-cost` | Estimated cost in USD | Ungrouped only |

Set at most one dimension in `groupBy` to create independent series. Groupable attempt metrics support `provider-model`, `route`, `agent`, `node`, and `finish-reason`. `ai.attempt-count` also supports `failure-type`. The retired names `ai.error-rate` and `ai.request-count` have no aliases in Alerts. Use `ai.attempt-failure-rate` and `ai.attempt-count`, respectively. `ai.reasoning-tokens` has no supported Alerts output.

AI rules require both `native-object:agent:read` and `native-object:ai-route:read`. Narrowing a target does not remove these requirements. Missing ratios, averages, and quantiles are not zero. For example, no streaming requests can leave time-to-first-token without an observation.

### Failure Types

Each failed attempt has one failure type. The type suggests who owns the fix. A request's type is the type of its last attempt.

| Type and Admin Console label | Meaning | What to do |
| --- | --- | --- |
| `truncated`: Truncated (schema) | A structured-output attempt stopped at the token limit, so its JSON is incomplete. | Raise the max tokens, or simplify the schema. |
| `content_filter`: Content filtered | The provider's content filter stopped the answer. | Review the prompt and the input that triggered the filter. |
| `cancelled`: Cancelled by caller | The caller stopped waiting before AI Gateway answered. AI Gateway stops the attempt and does not try fallbacks. | Usually the caller's own timeout is shorter than the model's normal latency. Raise the timeout. |
| `timeout`: Timed out | The provider, or the connection to it, timed out. | Usually provider-side. Fallbacks help. |
| `auth_billing`: Auth or billing | The provider rejected the API key, or the account is out of credits or budget. | Check the provider key and credits on the [AI Connection](https://docs.contextual.io/connect/connections/types-of-connections/ai-connections.md). |
| `rate_limited`: Rate limited | The provider returned a rate-limit or quota error. | Provider-side. Fallbacks help. |
| `model_not_found`: Model not found | The provider does not know the model, or the key cannot use it. | Check the model ID and that the model is available in that provider project or region. |
| `unavailable`: Provider unavailable | The provider returned a server error, was overloaded, or could not be reached. | Provider-side. Fallbacks help. |
| `bad_response`: Bad response | The provider returned something unusable, such as invalid JSON or a malformed tool call. | Usually provider-side. A fallback model can help. |
| `too_large`: Input too large | The input is more than the model accepts, such as too many prompt tokens or PDF pages. | Split the input, or use a model with a larger context. |
| `invalid_request`: Invalid request | The provider rejected the request or its schema as invalid. | Fix the node configuration or the schema. |
| `other`: Other | A failure that matches none of the types above. | Read the error message in [AI Failure Details](https://docs.contextual.io/operate/metrics.md#ai-failure-details). |

Types are assigned from the provider's error message and finish reason. If a provider changes its wording, an attempt can move to `other`. It still counts as failed. An attempt that did not fail has the type `""`, which the Admin Console shows as **Not failed**.

### Alert on a Failure Type

Only `ai.attempt-count` and `ai.failed-requests` accept `target.failureType` and `groupBy: ["failure-type"]`. Every other AI metric rejects both, including `ai.attempt-failure-rate`: filtered or grouped by type, its value would be 1 for every series with failures. Validation also rejects a type that is not in the table.

* `ai.attempt-count` with `target.failureType` counts every attempt of that type, including attempts that a fallback recovered. To count failed attempts per type, set `target.status` to `"failed"` and use `groupBy: ["failure-type"]`. Without the status filter, successful attempts form a `""` series.
* `ai.failed-requests` uses the type of each request's last attempt.

This fragment fires when any attempt failed on a provider key or billing problem in the last hour:

```json
{
  "metric": "ai.attempt-count",
  "target": { "service": "ai-gateway-api", "failureType": "auth_billing" },
  "comparator": "gte",
  "threshold": 1,
  "window": "1h"
}
```

## Native Object and Attachment Queries

> **Early access:** Native Object state, audit activity, and attachment-size alerts require Solution Metrics alerting to be enabled for your tenant. See [Monitor Native Object values and activity](https://docs.contextual.io/operate/alerts/solution-metrics-alerts.md) for the state-versus-activity comparison, complete rules, prerequisites, and verification walkthroughs.

| Source | Collection | Supported alert semantics |
| --- | --- | --- |
| Current object state | `native-object:TYPE_ID` | Latest applicable state per object, or an explicitly pinned object population. The first aggregate is `latest` or `earliest`; validate the full query. |
| Audit activity | `contextual:native-object-instances-history` | Activity within the authored window, restricted by exact `data.typeId`. Requires audit history on that type. |
| Attachment state | `contextual:files` | Latest active attachment size for one exact Native Object type. Use the attachment template's constrained query. |

Permissions follow the exact subject type, such as `native-object:invoice:read`. History rules check the type's audit-history prerequisite during authoring using the caller's access. Keep audit history enabled afterward; the authoring check is not a continuous guarantee.

Current-state queries deduplicate object history and evaluate state through the cutoff. They do not count only newly created objects inside the rule window. Group by `$document_key` or use a supported explicit equality/`IN` object population. Missing current state is not zero.

The attachment template uses `latest` on numeric `data.meta.size`, `dedup: true`, and exactly `group_by: [{ "path": "$document_key" }]`. Its filters select `ref.namespace: native-object`, the exact `ref.typeId`, active attachments with `data.meta.deleted != "true"`, and a size candidate condition compatible with the threshold. The comparator must be `gt` or `gte`. Preserve this complete shape when changing the size limit.

See the [stored query shape reference](https://docs.contextual.io/tenants/tenant-apis/alerts-api/configuration.md#stored-query-shape) for accepted query fields and limits.
