# Cancel a run

**POST** `/api/runs/{id}/cancel`

Asks a queued, running or held run to stop.

Needs [an API token](https://docs.gorunner.io/api/authentication#scopes) with the **Cancel and delete** permission for runs (`run:manage`).

## Parameters

### Path

- `id` · Required · UUID: The run’s ID.

## Read the answer

| status | cancelled | What happened |
| --- | --- | --- |
| `cancelling` | `true` | Asked. A running step finishes unwinding, then the run is `cancelled`. Ask Get a run until it is. |
| `cancelled` | `true` | A held run, settled at once. |
| Its finished status | `false` | It had already finished. Nothing was done; don’t retry. |

A queued run is settled at once, even though the answer says `cancelling`. It takes no body.

## Responses

- 200 OK

  Always 200. Read `status` and `cancelled` to see what happened.

- 400 `VALIDATION_ERROR`

  `id` isn’t a UUID.

- 403 `FORBIDDEN`

  The token lacks the **Cancel and delete** permission for runs.

- 404 `NOT_FOUND`

  No run with this ID in the token’s workspace.

- 500 `INTERNAL_ERROR`

  The stop couldn’t be signalled, or a held run couldn’t be settled. Try again.

- 503 `UNAVAILABLE`

  This installation has no Redis, so a cancel can’t be signalled.

Any call can also answer: [`401 UNAUTHORIZED`](https://docs.gorunner.io/errors#UNAUTHORIZED) · [`401 TOKEN_ENDED`](https://docs.gorunner.io/errors#TOKEN_ENDED) · [`403 TOKEN_SURFACE_OFF`](https://docs.gorunner.io/errors#TOKEN_SURFACE_OFF) · [`403 FEATURE_OFF`](https://docs.gorunner.io/errors#FEATURE_OFF) · [`403 EMBED_NOT_ALLOWED`](https://docs.gorunner.io/errors#EMBED_NOT_ALLOWED) · [`403 EMBED_NOT_AVAILABLE`](https://docs.gorunner.io/errors#EMBED_NOT_AVAILABLE) · [`403 ACCOUNT_SUSPENDED`](https://docs.gorunner.io/errors#ACCOUNT_SUSPENDED) · [`413 PAYLOAD_TOO_LARGE`](https://docs.gorunner.io/errors#PAYLOAD_TOO_LARGE) · [`415 INVALID_CONTENT_TYPE`](https://docs.gorunner.io/errors#INVALID_CONTENT_TYPE) · [`429 RATE_LIMITED`](https://docs.gorunner.io/errors#RATE_LIMITED) · [`503 BUSY`](https://docs.gorunner.io/errors#BUSY) · [`503 PAUSED`](https://docs.gorunner.io/errors#PAUSED) · [`503 SERVICE_UNAVAILABLE`](https://docs.gorunner.io/errors#SERVICE_UNAVAILABLE). See [Errors](https://docs.gorunner.io/api/errors#by-status).

Request

**curl**

```bash
GORUNNER="https://api.gorunner.io"
GORUNNER_TOKEN="grt_…"  # needs Cancel and delete for runs
RUN_ID="your-run-id"

curl -X POST "$GORUNNER/api/runs/$RUN_ID/cancel" \
  -H "Authorization: Bearer $GORUNNER_TOKEN"
```

**JavaScript**

```js
const GORUNNER = "https://api.gorunner.io";
const TOKEN = process.env.GORUNNER_TOKEN;
const RUN_ID = process.env.RUN_ID;

const res = await fetch(
  `${GORUNNER}/api/runs/${RUN_ID}/cancel`,
  {
    method: "POST",
    headers: { Authorization: `Bearer ${TOKEN}` },
  },
);
const { data } = await res.json();
```

**Python**

```python
import os, requests

GORUNNER = "https://api.gorunner.io"
TOKEN = os.environ["GORUNNER_TOKEN"]
RUN_ID = os.environ["RUN_ID"]

res = requests.post(
    f"{GORUNNER}/api/runs/{RUN_ID}/cancel",
    headers={"Authorization": f"Bearer {TOKEN}"},
)
data = res.json()["data"]
```

Response · 200 OK

```json
{
  "data": {
    "id": "8f0c41d2-6b7e-4c1a-9d3f-2a5b7c9e1f04",
    "status": "cancelling",
    "cancelled": true
  }
}
```

**Every field**

It takes no body.

### Response · 200 OK

- `data` · object: The outcome of a cancel request. `cancelled: false` means nothing was done because the run had already settled.
  - `id` · UUID: The run id.
  - `status` · string: `cancelling` = the request was signalled to the executor and the run is NOT yet terminal (poll `GET /api/runs/{id}`). `cancelled` = a paused run was settled here and now. Any other value is the status the run had ALREADY settled at, returned with `cancelled: false`. One of `cancelling`, `cancelled`, `completed`, `failed`, `pending`, `running`, `paused`.
  - `cancelled` · boolean: `true` when a cancellation was requested or performed; `false` when the run was already terminal and nothing happened.

Related: [Cancel many runs](https://docs.gorunner.io/api/runs/cancel-runs-bulk) · [Cancel waiting runs](https://docs.gorunner.io/api/runs/cancel-waiting-runs) · [Get a run](https://docs.gorunner.io/api/runs/get-run)

Source: https://docs.gorunner.io/api/runs/cancel-run
