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

# Cancel a run

> Best-effort cancellation via the Seltz Agent API, and why it can lose the race to completion

To stop a run you no longer need results from, cancel it, keeping in mind
that cancellation is best-effort and can lose the race to a run that is
about to finish anyway.

[`cancel`](/api-reference/agent/cancel-run) requests that a run stop. See
[Concepts](/agent/concepts#cancellation-is-best-effort) for why a run can
still complete after you cancel it. It never errors on a run that has already
ended, so it is safe to call speculatively and to retry.

<CodeGroup>
  ```python Python theme={null}
  cancelled = client.agent.cancel(run_id)
  print(cancelled.status)  # may already be "completed" if the run won the race
  ```

  ```typescript TypeScript theme={null}
  const cancelled = await client.agent.cancel(runId);
  console.log(cancelled.status); // may already be "completed" if the run won the race
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.seltz.ai/v1/agent/runs/$RUN_ID/cancel" \
    -H "x-api-key: $SELTZ_API_KEY"
  ```
</CodeGroup>

When cancellation actually takes effect, the run has no output:
[`status`](/api-reference/agent/cancel-run#response-status) is `cancelled`,
[`stop_reason`](/api-reference/agent/cancel-run#response-stop-reason-one-of-1)
is `cancelled`, and `output`'s fields stay unset.

## Next steps

* [List runs](/agent/guides/list-runs): paging this org's runs, newest first
* [Poll for completion](/agent/guides/poll-for-completion): managing the wait yourself
* [Reference](/agent/reference): endpoints, fields, limits and errors
* [Agent API Reference](/api-reference/agent/cancel-run): full REST request and response specification
