# Cancel Workflow Run

`POST /workflows/{wflId}/runs/{wfrId}/cancel` · Core · Compute & Automation

Cancels a workflow run that is in `pending` or `running` status, halting execution at the current step. Requires the `PROJECT_AUTHOR` role. Returns `K9O_WORKFLOW_RUN_NOT_CANCELLABLE` (409) if the run has already reached a terminal status (`succeeded`, `failed`, or `cancelled`).

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `wflId` | path | yes | The workflow id (`wfl_...`). Example: `"wfl_demo00000001"`. |
| `wfrId` | path | yes | The run id (`wfr_...`), from the runs list or the response that started the run. Example: `"wfr_demo00000001"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The run that was cancelled. |
| `data.id` | string | yes | The cancelled run (`wfr_...`). |
| `data.status` | enum ("cancelled") | yes | Always `cancelled`. A step already in flight finishes, but no further step starts. |
| `meta` | object | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_INVALID_CREDENTIALS` | The request was made without a valid session or bearer token. |
| 401 | `K9O_SESSION_EXPIRED` | Your session has expired; re-authenticate and retry. |
| 403 | `K9O_ACCESS_DENIED` | Cancelling a workflow run requires the PROJECT_AUTHOR role; your current role does not grant it. |
| 404 | `K9O_WORKFLOW_NOT_FOUND` | No workflow with the supplied workflow ID exists in this project. |
| 404 | `K9O_WORKFLOW_RUN_NOT_FOUND` | No run with the supplied run ID exists for this workflow, or it is not within your project scope. |
| 409 | `K9O_WORKFLOW_RUN_NOT_CANCELLABLE` | The run has already completed — only runs in a pending or running state can be cancelled. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/workflows/wfl_demo00000001/runs/<wfrId>/cancel' \
  -H 'Authorization: Bearer $K9O_TOKEN'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/workflows/wfl_demo00000001/runs/<wfrId>/cancel', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`
  },
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.studio.workflows.runs.cancel('wfl_demo00000001', 'wfr_demo00000001')
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.studio.workflows.runs.cancel("wfl_demo00000001", "wfr_demo00000001")
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Studio.Workflows.Runs.Cancel(ctx, "wfl_demo00000001", "wfr_demo00000001")
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.studio.workflows.runs.cancel("wfl_demo00000001", "wfr_demo00000001").await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.studio().workflows().runs().cancel("wfl_demo00000001", "wfr_demo00000001")
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Studio.Workflows.Runs.CancelAsync("wfl_demo00000001", "wfr_demo00000001")
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.studio.workflows.runs.cancel("wfl_demo00000001", "wfr_demo00000001")
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->studio->workflows->runs->cancel('wfl_demo00000001', 'wfr_demo00000001')
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/cancel-workflow-run
