> ## 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.

# Create saved query

> Creates a reusable APL query.

`axiom.createSavedQuery` creates a reusable APL query. Include its owner, string metadata, and complete query request; returns the saved query with ID.

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

export default automation("Create saved query", () => {
  onHttpRequest({ scope: "automation" })
  axiom.createSavedQuery({
    kind: "apl",
    name: "Recent errors",
    metadata: {},
    who: "user-id",
    query: {
      apl: "['production'] | where severity == 'error'",
      startTime: "now-30m",
      endTime: "now",
    },
  })
})
```

## Inputs

`kind` must be `"apl"`; `name`, `who`, `metadata`, and `query` are required. The query requires non-empty `apl`; `startTime` defaults to `"now-30m"` and `endTime` to `"now"`. Optional query fields configure cursor inclusion, default limits and ordering, libraries, variables, and query display or execution options. `dataset` is an optional dataset hint.

## Output

Returns the saved query with its Axiom `id` and complete stored configuration.

## Permission and failures

The API token needs the dataset-level `starredQueries|create` capability for the relevant dataset. Axiom rejects invalid APL, inaccessible dataset references, invalid time expressions, and unsupported query options. This mutation is not retried automatically after an ambiguous provider response.
