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

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Query metrics

> Runs MPL against an OpenTelemetry metrics dataset and returns Axiom's metrics-v2 response.

`axiom.queryMetrics` runs MPL against an OpenTelemetry metrics dataset and returns Axiom's metrics-v2 response. Discover metric names and tags first; the time window defaults to the previous 30 minutes.

```ts automations/axiom-query-metrics.automation.ts theme={null}
import { automation, onHttpRequest } from "automate.ax"
import { axiom } from "automate.ax/axiom"

export default automation("Query metrics", () => {
  onHttpRequest({ scope: "automation" })
  axiom.queryMetrics({
    mpl: "metrics:http.server.duration | align to 1m using avg",
    startTime: "now-15m",
    endTime: "now",
  })
})
```

## Inputs

| Input       | Required | Default                                 | Description                                                  |
| ----------- | -------- | --------------------------------------- | ------------------------------------------------------------ |
| `mpl`       | Yes      | —                                       | Non-empty MPL query.                                         |
| `startTime` | No       | `"now-30m"`                             | Query-window start as an Axiom time expression or timestamp. |
| `endTime`   | No       | `"now"`                                 | Query-window end.                                            |
| `edgeUrl`   | No       | `"https://us-east-1.aws.edge.axiom.co"` | Axiom query edge or an HTTPS `*.edge.axiom.co` origin.       |

## Output

Returns Axiom's metrics-v2 result as a JSON object. Its keys and series shape depend on the MPL query.

## Permission and failures

The API token needs the dataset-level `query|read` capability for every metrics dataset referenced by the MPL query. Axiom rejects invalid MPL, inaccessible datasets, and invalid time windows. Request-rate limits return `429`, while exhausted query-cost limits return `430`. Automate.ax uses Axiom's reset timing when available.
