Setup
Create a client and thread:- Python
- Javascript
- CURL
Cancel a single run
The following examples create a run, cancel it with different options, and print the run to show what you get in each case. You can cancel runs inpending or running status. Trying to cancel a run that is not in pending or running status will result in an error.
Cancel with interrupt (default)
interrupt stops the worker executing the run and marks the run asinterrupted. Nothing is deleted:
- The run record remains (with status
interrupted). You can fetch it, inspect inputs/outputs, and see the execution history. - All checkpoints for that run remain stored. The thread state at the last completed step is preserved.
- You can later resume from a checkpoint (for example, with time travel) or inspect the partial state.
- Python
- Javascript
- CURL
Cancel with rollback
rollback stops the run and then removes it and its checkpoints from storage:- The run record is deleted. The run no longer appears in run lists or history for that thread.
- All checkpoints created by that run are deleted. The thread’s state is reverted to what it was before the run started (as if the run had never been executed).
- You cannot resume or inspect the run after a rollback.
- Python
- Javascript
- CURL
Cancel with wait
By default, the cancel request returns after the cancellation is requested and the run is cancelled asynchronously.wait=True makes the cancel request block until the run has been fully cancelled. This is useful when you want to know the final state of the run after it has been cancelled (e.g., what checkpoints were created, what the final output was).
- Python
- Javascript
- CURL
Cancel multiple runs
Use the bulk cancel endpoint to cancel multiple runs in one request. Both the interrupt and rollback actions are supported.Cancel by thread ID and run IDs
Cancel specific runs by passing their IDs.- Python
- Javascript
- CURL
Cancel by status
Cancel all runs that match a status across all threads in a deployment. Valid status options arepending, running, or all.
- Python
- Javascript
- CURL
Cancel on disconnect
When starting a run with streaming or when waiting on a run, you can seton_disconnect="cancel" so that the run is cancelled if the client disconnects. This avoids leaving runs in progress when a user closes the app or loses connection.
- Python
- Javascript
- CURL
Common scenarios
- Human-in-the-loop and interrupts: Agents can pause at interrupts for human input. Cancelling a run stops execution; it is different from an interrupt, where the run is paused and can be resumed with new input.
- Time travel: After cancelling with action
interrupt, the run and checkpoints are still available. You can resume from a checkpoint (time travel) to replay or branch execution. - Double-texting: When a user sends new input while a run is in progress, the multitask strategy (enqueue, reject, interrupt, rollback) determines whether the existing run is interrupted or rolled back and how the new run is handled. To cancel runs explicitly from your application, use the cancel API described on this page.
- Studio: In Studio, use the Cancel button in the run UI to cancel the current run.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

