create_and_wait / createAndWait hide from you, and the manual poll a
plain REST caller has to do instead.
1. Start a run
create_and_wait / createAndWait call
create, then poll until the run
finishes, and hand back the completed envelope. cURL has no waiter, so the
same request only starts the run. This example also sets
effort to "high" for deeper research
than the default medium:
pending state.
output is
present but its fields stay unset until the run reaches a terminal state:
2. Poll for the result
Retrieve the run by theid the create call returned. In Python and
TypeScript, create_and_wait / createAndWait already did this polling for
you above, so run there is already the finished envelope;
get is the single check it repeats under
the hood, useful on its own when you want to look a run up independently
instead of holding onto the object create returned. Over cURL, this is the
only way to find out whether the run is done:
wait’s options.
Check status before
reading anything from output. A run that hasn’t finished yet comes back as
running (or pending), not an error, and output’s fields stay unset,
the same status as right after the run is created:
started_at
distinguishes running from pending: it is null while
a run waits for a worker, and set the moment one picks up the run. Keep polling
until status is completed, failed, or cancelled, or use wait /
createAndWait, which does exactly this loop for you. Once the status is completed, a
completed run’s output.text
is a cited Markdown report, with inline [n] markers pointing at
output.sources:
3. Read the result
In Python and TypeScript,create_and_wait / createAndWait already
returned this same envelope, so there is no separate call. Read
run.output.text and walk run.output.sources for the citation list:
Example output
Next steps
- Structured output: requesting a JSON result instead of Markdown
- List runs: paging this org’s runs, newest first
- Poll for completion: managing the wait yourself
- Cancel a run: best-effort cancellation, and why it can lose the race to completion
- Handle errors: rejected requests versus failed runs
- Reference: endpoints, fields, limits and errors
- Agent API Reference: full REST request and response specification