await_run
Poll an accepted run until it finishes or needs approval. For Brave submissions, the helper returns at submitted or failed.
Signature
async def await_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=asyncio.sleep,
clock=time.monotonic) -> Mapping[str, Any]Parameters
client- An open AsyncAeoClient.
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.statusissubmitted(Brave accepted the URL) orfailed. To poll while the status isin_progressyourself, use the Brave polling example. - Collection and other jobs
- Check
data.stateforcompleted,partial,failedorcancelled. Managed runs usedata.status. - Jobs that need approval
- By default the helper returns at
awaiting_approvalso you can request a decision. It also returns atrejectedorstale_approval. - Retrieval simulations
- A successful run returns
data.statusofsucceeded. Stop onfailedorcancelledas well. - Accuracy checks and cited-page runs
- Both report
in_progressuntildata.statusreachescompleted. A cited-page sweep or labelling run can also end atcancelled. - Saved checks
- Pass the brand ID as
brand_id. The helper checksdata.check.stateand returns the fulldataobject, includingcheckand the page of recorded prompts. - Analyst reports
- The helper returns when
data.report_idis 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 asyncio
import os
from aeo_sdk import AsyncAeoClient, await_run
async def main():
async with AsyncAeoClient(os.environ["AEO_API_KEY"], base_url=os.environ["AEO_API_BASE_URL"]) as client:
run = await await_run(client, os.environ["AEO_RUN_ID"], timeout=120)
print(run.get("state", run.get("status")))
asyncio.run(main())See Python client setup for the environment variables, response properties and retry settings.