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

# Agent

> Run an Agent API task on a schedule and read new, relevant updates through the API.

An Agent monitor runs a task with the [Agent API](https://docs.perplexity.ai/docs/agent-api/quickstart.md) on a schedule and saves relevant updates with their sources. Use an Agent monitor when you need a written answer, not a list of results. Use [Search monitoring](https://docs.perplexity.ai/docs/monitors/search-monitoring.md) to find URLs for a query. Use [Page monitoring](https://docs.perplexity.ai/docs/monitors/page-monitoring.md) to track later edits at known URLs.

## Create an Agent monitor

Set `PERPLEXITY_API_KEY` to your [API key](https://docs.perplexity.ai/docs/admin/api-key-management.md). The Python and TypeScript examples use the [Perplexity SDKs](https://docs.perplexity.ai/docs/sdk/overview.md). The cURL examples use jq. When you create a monitor, its first run is due immediately. The service schedules later runs while the monitor is active. To stop the runs, [pause or delete the monitor](https://docs.perplexity.ai/docs/monitors/overview.md#pause-and-resume). See [Cost](#cost).

`perplexityai` 0.49.0 and `@perplexity-ai/perplexity_ai` 0.44.0 do not have types for the Agent target. The examples send each request with `client.post`, `client.get`, or `client.patch`.

```python Python theme={null}
import httpx
from perplexity import Perplexity

client = Perplexity()

response = client.post(
    "/v1/monitors",
    cast_to=httpx.Response,
    body={
        "name": "Go releases",
        "targets": [
            {
                "type": "agent",
                "input": "Find the latest stable release of Go. Report the version number, the release date, and the main changes.",
                "effort": "low",
            }
        ],
        "schedule": {"type": "interval", "interval": "1d"},
    },
)
monitor = response.json()

print(monitor["id"], monitor["status"])
```

```typescript Typescript theme={null}
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity();

const monitor = await client.post<Perplexity.Monitor>('/v1/monitors', {
  body: {
    name: 'Go releases',
    targets: [
      {
        type: 'agent',
        input: 'Find the latest stable release of Go. Report the version number, the release date, and the main changes.',
        effort: 'low',
      },
    ],
    schedule: { type: 'interval', interval: '1d' },
  },
});

console.log(monitor.id, monitor.status);
```

```bash cURL theme={null}
curl --request POST https://api.perplexity.ai/v1/monitors \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "Go releases",
    "targets": [
      {
        "type": "agent",
        "input": "Find the latest stable release of Go. Report the version number, the release date, and the main changes.",
        "effort": "low"
      }
    ],
    "schedule": {"type": "interval", "interval": "1d"}
  }' | jq
```

The `200` response is a monitor, not a completed run. Set `MONITOR_ID` to its `id` for the requests below.

Use an [idempotency key](https://docs.perplexity.ai/api-reference/monitors-create-post.md#webhook-secrets-and-retries) if your application retries creation.

> [!NOTE]
>
> This example reads results through the API without a webhook. Use [webhooks](https://docs.perplexity.ai/docs/monitors/overview.md#webhook-notifications) to receive change notifications without polling for results.

## Read the results

A run is one execution of a monitor. Its `changes` array contains the updates that the run kept. Get the latest run with `MONITOR_ID`. The first run starts asynchronously after you create the monitor. Do not send another `/run` request for the first run.

The two responses below show the same run. Use the IDs that your own requests return.

```python Python theme={null}
import os

import httpx
from perplexity import Perplexity

client = Perplexity()
monitor_id = os.environ["MONITOR_ID"]

runs = client.get(
    f"/v1/monitors/{monitor_id}/runs",
    cast_to=httpx.Response,
    options={"params": {"limit": 1}},
).json()

for run in runs["data"]:
    print(run["id"], run["status"])
```

```typescript Typescript theme={null}
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity();
const monitorId = process.env.MONITOR_ID!;

type AgentRun = { id: string; status: string };
const runs = await client.get<{ data: AgentRun[] }>(`/v1/monitors/${monitorId}/runs`, {
  query: { limit: 1 },
});

for (const run of runs.data) {
  console.log(run.id, run.status);
}
```

```bash cURL theme={null}
curl "https://api.perplexity.ai/v1/monitors/$MONITOR_ID/runs?limit=1" \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" | jq
```

> [accordion] List runs response
>
> ```json theme={null}
> {
>   "data": [
>     {
>       "changes": [
>         {
>           "confidence": 0.95163422173055,
>           "id": "chg_6faee76cdc245e98bcda5cf249e12be1",
>           "sources": [
>             {
>               "title": "Release History",
>               "url": "https://go.dev/doc/devel/release"
>             },
>             {
>               "title": "Go 1.27 Release Notes",
>               "url": "https://go.dev/doc/go1.27"
>             },
>             {
>               "published_at": "2026-11-10T00:00:00Z",
>               "title": "Go Turns 17",
>               "url": "https://go.dev/blog/17years"
>             }
>           ],
>           "text": "The latest stable Go release is **Go 1.27.4**, released **November 10, 2026**. Its major-line highlights include generic methods, the generally available `encoding/json/v2` and `encoding/json/jsontext` packages, a standard-library UUID package, goroutine-leak profiling, faster small-object allocations, and ML-DSA post-quantum cryptography; 1.27.4 itself includes security and bug fixes across the toolchain, runtime, networking, and crypto packages.",
>           "title": "Go 1.27.4 — released November 10, 2026",
>           "type": "agent_update",
>           "url": "https://go.dev/doc/devel/release"
>         }
>       ],
>       "counts": {
>         "candidates": 1,
>         "changes": 1,
>         "errors": 0
>       },
>       "created_at": "2026-11-23T13:26:38Z",
>       "finished_at": "2026-11-23T13:26:56Z",
>       "id": "run_01M849CKR5ZCTQFV6J5QM3TE3C",
>       "monitor_id": "mon_01M849CDHBYCP9NW23GQ69999Y",
>       "object": "monitor.run",
>       "status": "succeeded",
>       "target_errors": [],
>       "trigger": "schedule",
>       "usage": {
>         "cost": {
>           "currency": "USD",
>           "total_cost": 0.00785
>         },
>         "fetched_urls": 0
>       },
>       "window": {
>         "from": "2026-11-22T13:26:31Z",
>         "to": "2026-11-23T13:26:38Z"
>       }
>     }
>   ],
>   "has_more": false,
>   "object": "list"
> }
> ```

If the list is empty, read it again later. If the status is `queued`, `running`, or an unknown status, poll with a bounded retry policy. If the status is `failed` or `skipped`, check `error`.

When the status is `succeeded`, set `RUN_ID` to the ID of the run in `data[0].id`. Then get that run. The service keeps run history for 90 days.

```python Python theme={null}
import os

import httpx
from perplexity import Perplexity

client = Perplexity()
monitor_id = os.environ["MONITOR_ID"]
run_id = os.environ["RUN_ID"]

run = client.get(
    f"/v1/monitors/{monitor_id}/runs/{run_id}",
    cast_to=httpx.Response,
).json()

for update in run["changes"]:
    print(update["title"], update["text"])
    for source in update["sources"]:
        print(source["url"])
```

```typescript Typescript theme={null}
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity();
const monitorId = process.env.MONITOR_ID!;
const runId = process.env.RUN_ID!;

type AgentUpdate = { title: string; text: string; sources: { url: string }[] };
type AgentRun = { changes: AgentUpdate[] };
const run = await client.get<AgentRun>(`/v1/monitors/${monitorId}/runs/${runId}`);

for (const update of run.changes) {
  console.log(update.title, update.text);
  for (const source of update.sources) {
    console.log(source.url);
  }
}
```

```bash cURL theme={null}
curl "https://api.perplexity.ai/v1/monitors/$MONITOR_ID/runs/$RUN_ID" \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" | jq
```

> [accordion] Get run response
>
> ```json theme={null}
> {
>   "changes": [
>     {
>       "confidence": 0.95163422173055,
>       "id": "chg_6faee76cdc245e98bcda5cf249e12be1",
>       "sources": [
>         {
>           "title": "Release History",
>           "url": "https://go.dev/doc/devel/release"
>         },
>         {
>           "title": "Go 1.27 Release Notes",
>           "url": "https://go.dev/doc/go1.27"
>         },
>         {
>           "published_at": "2026-11-10T00:00:00Z",
>           "title": "Go Turns 17",
>           "url": "https://go.dev/blog/17years"
>         }
>       ],
>       "text": "The latest stable Go release is **Go 1.27.4**, released **November 10, 2026**. Its major-line highlights include generic methods, the generally available `encoding/json/v2` and `encoding/json/jsontext` packages, a standard-library UUID package, goroutine-leak profiling, faster small-object allocations, and ML-DSA post-quantum cryptography; 1.27.4 itself includes security and bug fixes across the toolchain, runtime, networking, and crypto packages.",
>       "title": "Go 1.27.4 — released November 10, 2026",
>       "type": "agent_update",
>       "url": "https://go.dev/doc/devel/release"
>     }
>   ],
>   "counts": {
>     "candidates": 1,
>     "changes": 1,
>     "errors": 0
>   },
>   "created_at": "2026-11-23T13:26:38Z",
>   "finished_at": "2026-11-23T13:26:56Z",
>   "id": "run_01M849CKR5ZCTQFV6J5QM3TE3C",
>   "monitor_id": "mon_01M849CDHBYCP9NW23GQ69999Y",
>   "object": "monitor.run",
>   "status": "succeeded",
>   "target_errors": [],
>   "trigger": "schedule",
>   "usage": {
>     "cost": {
>       "currency": "USD",
>       "total_cost": 0.00785
>     },
>     "fetched_urls": 0
>   },
>   "window": {
>     "from": "2026-11-22T13:26:31Z",
>     "to": "2026-11-23T13:26:38Z"
>   }
> }
> ```

Each update in `changes` has type `agent_update`. A `succeeded` run can have an empty `changes` array.

| Field | Meaning |
| - | - |
| `id` | The ID of the update. |
| `title` | A short title for the update, up to 200 characters. |
| `text` | The content of the update, up to 1,000 characters. The text can contain Markdown. |
| `confidence` | A score from 0 to 1. See [Task and goal](#task-and-goal). |
| `url` | The URL of the first source. The service omits this field if there are no sources. |
| `sources` | Up to five sources. Each source has a `url`. The `title` and `published_at` fields are optional. |

## Configure your agent

Put one target with `type: "agent"` in `targets`. Do not combine it with another target.

| Parameter | Type | Default | Constraints |
| - | - | - | - |
| `targets[0].input` | string | None | Required. Use 1 to 4,000 characters after the service removes leading and trailing whitespace. |
| `targets[0].effort` | string | `low` if you do not set a profile | Use `low`, `medium`, or `high`. A suffix can select a version. Maximum length: 64 bytes. |
| `targets[0].profile` | object | None | Set `type` to `custom`. Set an `id` of 1 to 128 characters. Optional `version`: up to 128 bytes. Do not set `effort`. |
| `targets[0].filters.freshness` | array of strings | `["published", "updated"]` | Use `published`, `updated`, or both. An empty array uses the default. |
| `targets[0].filters.include_domains` | array of strings | `[]` | Up to 20 bare host names to include. |
| `targets[0].filters.exclude_domains` | array of strings | `[]` | Up to 20 bare host names to exclude. |

### Task and goal

The task in `input` tells the agent what to do in each run. Set an optional top-level [`goal`](https://docs.perplexity.ai/docs/monitors/overview#goals-and-judging) on the monitor to describe which updates to keep:

```json theme={null}
{"goal": "Tell me when a new stable Go version is released."}
```

Judging runs automatically. An update must pass each check that applies to appear in `changes`:

* **Relevance**: Checks if the update reports something that you asked for. The judge reads the task in `input` and, if you set one, the goal. This check runs with or without a goal.
* **Novelty**: Checks if the update adds new information. This check does not apply to a first check.

A run with no [saved state](#saved-state) is a first check. A first check can save at most one update. This update describes the current state. Later runs use the saved state to find what is new. Each later run can save at most five updates. `confidence` is the product of the judging scores that apply.

### Effort

Choose the [effort level](https://docs.perplexity.ai/docs/agent-api/effort.md) for the task. Use `low` or `low@latest` for the active version of `low`. To [pin a version](https://docs.perplexity.ai/docs/agent-api/effort.md#pinning-an-effort-level-version), use a value such as `low@<version>`.

The service does not check that the version exists when you create the monitor. If the version does not exist, the run fails with `error.code: "source_failed"`.

### Profiles

Set `profile` to `{"type": "custom", "id": "YOUR_PROFILE_ID"}` to use a saved [Agent API profile](https://docs.perplexity.ai/docs/agent-api/profiles.md). Omit `effort` when you set `profile`. The service does not check that the profile exists when you create the monitor. If the Agent API cannot find or access the profile, the run fails with `error.code: "source_failed"`.

Do not use a profile that enables the [sandbox tool](https://docs.perplexity.ai/docs/agent-api/tools/sandbox.md). The service does not accept sandbox results as sources, and it drops an update that has no other source. If you also set a domain filter or only one `freshness` value, the run fails with `error.code: "source_failed"`.

### Filters

Set `freshness` to `["published"]` or `["updated"]` to filter the agent's web search by publication date or last-updated date. The filter date is the UTC date of `window.from` in the run. See [how the service sets the run window](https://docs.perplexity.ai/docs/monitors/search-monitoring.md#freshness). If you select both values, the monitor applies no date filter.

In `include_domains` and `exclude_domains`, use bare host names such as `go.dev`, without a scheme, path, or port. Each entry also covers its subdomains. Do not put the same domain in both lists. With a domain filter, `sources` contains only the sources that pass the filter. The service keeps an update only if it has at least one of these sources.

### Saved state

The monitor keeps saved state between runs. Later runs use this saved state to find what is new. The next run is a first check when one of these values differs from the saved state:

* The task in `input`
* The top-level `goal`
* The profile `id` or `version`
* The `freshness` filter
* The domains in either domain list

An equivalent value does not reset the saved state. For example, the order of the values in a list has no effect.

A change to one of these fields keeps the saved state:

* `effort`
* `name`
* `schedule`
* `webhook`
* `metadata`

### Update your agent

Send a `PATCH` request with `targets` to replace the whole target. Repeat `input` and any nondefault settings that you want to keep. If you omit `effort` and `profile`, the service uses `low`. If you omit `filters`, the service resets `freshness` to `["published", "updated"]` and clears both domain lists. If you omit one filter, the service resets that filter to its default.

This example sets `effort` to `medium` and limits sources to `go.dev`. Because the domain list changes, the next run is a first check. The update does not start a run. The next run starts at `next_run_at`. To start a run before that time, [request a manual run](https://docs.perplexity.ai/docs/monitors/overview.md#run-now).

```python Python theme={null}
import os

import httpx
from perplexity import Perplexity

client = Perplexity()
monitor_id = os.environ["MONITOR_ID"]

monitor = client.patch(
    f"/v1/monitors/{monitor_id}",
    cast_to=httpx.Response,
    body={
        "targets": [
            {
                "type": "agent",
                "input": "Find the latest stable release of Go. Report the version number, the release date, and the main changes.",
                "effort": "medium",
                "filters": {"include_domains": ["go.dev"]},
            }
        ]
    },
).json()

print(monitor["targets"])
```

```typescript Typescript theme={null}
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity();
const monitorId = process.env.MONITOR_ID!;

const monitor = await client.patch<Perplexity.Monitor>(`/v1/monitors/${monitorId}`, {
  body: {
    targets: [
      {
        type: 'agent',
        input: 'Find the latest stable release of Go. Report the version number, the release date, and the main changes.',
        effort: 'medium',
        filters: { include_domains: ['go.dev'] },
      },
    ],
  },
});

console.log(monitor.targets);
```

```bash cURL theme={null}
curl --request PATCH "https://api.perplexity.ai/v1/monitors/$MONITOR_ID" \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "targets": [
      {
        "type": "agent",
        "input": "Find the latest stable release of Go. Report the version number, the release date, and the main changes.",
        "effort": "medium",
        "filters": {"include_domains": ["go.dev"]}
      }
    ]
  }' | jq
```

## Cost

Perplexity bills an Agent run as [Agent API usage](https://docs.perplexity.ai/docs/getting-started/pricing.md#agent-api-pricing). Perplexity does not charge a separate Monitor API fee for an Agent run.

Each run reports its list cost in `usage.cost.total_cost`. A `succeeded` run with no updates can also have a cost. A `failed` run can have a cost. For an Agent run, `usage.fetched_urls` is always `0`.

## Run failures

A run fails with `error.code: "source_failed"` in conditions such as these:

* The effort version does not exist.
* The Agent API cannot find or access the profile.
* The agent cannot retrieve information that is relevant to the task.
* The service cannot read the answer from the agent.

Other failures can have a different [`error.code`](https://docs.perplexity.ai/api-reference/monitors-run-get). Use `error.code` in your application logic. Read `error.message` for the reason. Do not parse `error.message`.

After three source failures without a successful run between them, the service [pauses the monitor automatically](https://docs.perplexity.ai/docs/monitors/overview.md#automatic-pausing).

## Next steps

[Pause the monitor](https://docs.perplexity.ai/docs/monitors/overview.md#pause-and-resume) when you finish your test. You can also [change its schedule](https://docs.perplexity.ai/docs/monitors/overview.md#schedules), [add webhooks](https://docs.perplexity.ai/docs/monitors/overview.md#webhook-notifications), or check the [API reference](https://docs.perplexity.ai/api-reference/monitors-create-post.md) for the full contract.
