# Cancel a tool run Cancel execution, preserve partial output and verify teardown. `POST /v1/tool-runs/{run_id}/cancel` ## Stop a run you no longer need Send POST with a new cancellation key, then retrieve the run until it reaches a terminal state. ## What to do next Check cleanup\_status and keep any useful partial output. [Read the step-by-step guide →](https://www.security.run/docs/troubleshooting.html) Send an `Idempotency-Key`. Keep the same key and body when retrying this operation. ### Parameters #### `run_id` · `path · string` · required #### `authorization` · `header · string | null` · required #### `idempotency-key` · `header · string | null` · required ### Responses - `200` Successful Response - `422` Validation Error ## Request ```bash curl -X POST "$SECURITY_RUN_URL/v1/tool-runs/toolrun_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/cancel" \ -H "Authorization: Bearer $SECURITY_RUN_API_KEY" \ -H "Idempotency-Key: unique-request-key" ``` ## Request ```python import os, httpx headers = {'Idempotency-Key': 'unique-request-key'} headers["Authorization"] = "Bearer " + os.environ["SECURITY_RUN_API_KEY"] response = httpx.request('POST', os.environ["SECURITY_RUN_URL"].rstrip("/") + '/v1/tool-runs/toolrun_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/cancel', headers=headers) response.raise_for_status() print(response.text) ``` ## Request ```javascript const base = process.env.SECURITY_RUN_URL.replace(/\/$/, ""); const headers = { "Idempotency-Key": "unique-request-key" }; headers.Authorization = `Bearer ${process.env.SECURITY_RUN_API_KEY}`; const response = await fetch(base + "/v1/tool-runs/toolrun_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/cancel", { method: "POST", headers }); if (!response.ok) throw new Error(`HTTP ${response.status}`); console.log(await response.text()); ```