---
title: "wait_for_run | Python SDK | AEO API"
description: "Poll an accepted run until it finishes or needs approval. For Brave submissions, the helper returns at submitted or failed."
url: "https://aeoapi.dev/docs/sdks/python/wait-for-run"
canonical: "https://aeoapi.dev/docs/sdks/python/wait-for-run"
last_updated: "2026-11-30"
---

# wait_for_run

Poll an accepted run until it finishes or needs approval. For Brave submissions, the helper returns at submitted or failed.

## Signature

```
def wait_for_run(client, target, *, brand_id: str | None = None,
    timeout=600.0, initial_interval=1.0, max_interval=30.0, factor=1.6,
    stop_on_action=True, sleep=time.sleep,
    clock=time.monotonic) -> Mapping[str, Any]
```

## Parameters

**`client`**

An open AeoClient.

**`target`**

Qualified run ID or its poll URL on the configured API origin. For a poll URL with a query string, use the qualified run ID and pass the brand ID separately. Read estimates directly.

**`brand_id`**

Required for a saved check. Sent as brand_id on each poll request.

**`timeout`**

Total polling deadline in seconds. The helper reads the run once before checking the deadline.

**`initial_interval, max_interval, factor`**

First delay and maximum delay in seconds, and the factor applied between polls.

**`stop_on_action`**

Defaults to True, so awaiting_approval returns control to your application.

**`sleep, clock`**

Optional delay function and monotonic clock for testing. The async helper awaits its delay function.

## Return value

The run record from response.data. Check its state or status before using the result. A failed run returns its record.

## When to stop polling

**Brave submissions**

The helper returns when `data.status` is `submitted` (Brave accepted the URL) or `failed`. To poll while the status is `in_progress` yourself, use the [Brave polling example](https://aeoapi.dev/docs/guides/submit-to-brave#3-check-the-outcome).

**Collection and other jobs**

Check `data.state` for `completed`, `partial`, `failed` or `cancelled`. Managed runs use `data.status`.

**Jobs that need approval**

By default the helper returns at `awaiting_approval` so you can request a decision. It also returns at `rejected` or `stale_approval`.

**Retrieval simulations**

A successful run returns `data.status` of `succeeded`. Stop on `failed` or `cancelled` as well.

**Accuracy checks and cited-page runs**

Both report `in_progress` until `data.status` reaches `completed`. A cited-page sweep or labelling run can also end at `cancelled`.

**Saved checks**

Pass the brand ID as `brand_id`. The helper checks `data.check.state` and returns the full `data` object, including `check` and the page of recorded prompts.

**Analyst reports**

The helper returns when `data.report_id` is present.

**Estimates**

Read the estimate directly. It has an expiry time and requires no polling.

## Errors

- RunTimeoutError.run holds the last observed run if the next polling delay would exceed the deadline. Polling stops locally and the remote run can continue.
- ValueError means the target is not a supported run ID or poll URL. The helper also passes through errors from the read request.

## Python example

```
import os
from aeo_sdk import AeoClient, wait_for_run

with AeoClient(os.environ["AEO_API_KEY"], base_url=os.environ["AEO_API_BASE_URL"]) as client:
    run = wait_for_run(client, os.environ["AEO_RUN_ID"], timeout=120)
    print(run.get("state", run.get("status")))
```

See [Python client setup](https://aeoapi.dev/docs/sdks/python) for the environment variables, response properties and retry settings.
