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

# client.cancel

Cancel one or more workflow runs. You can pass IDs directly, use filters, or cancel all at once.

## Arguments

The `cancel` method accepts one of the following:

### By ID

Pass a single workflow run ID or an array of IDs directly:

```ts theme={"system"}
await client.cancel("<WORKFLOW_RUN_ID>");
await client.cancel(["<ID_1>", "<ID_2>"]);
```

### By filters

Pass an object with a `filter` field containing one or more filter criteria:

<ParamField body="filter" type="object">
  <Expandable defaultOpen>
    <ParamField body="workflowUrl" type="string" optional>
      Cancel workflows matching this exact URL. Cannot be combined with `workflowUrlStartingWith`.
    </ParamField>

    <ParamField body="workflowUrlStartingWith" type="string" optional>
      Cancel workflows whose URL starts with this prefix. Cannot be combined with `workflowUrl`.
    </ParamField>

    <ParamField body="label" type="string" optional>
      Cancel workflows with this label.
    </ParamField>

    <ParamField body="fromDate" type="Date | number" optional>
      Cancel workflows created after this date. Accepts `Date` objects or Unix timestamps (ms).
    </ParamField>

    <ParamField body="toDate" type="Date | number" optional>
      Cancel workflows created before this date. Accepts `Date` objects or Unix timestamps (ms).
    </ParamField>

    <ParamField body="callerIp" type="string" optional>
      Cancel workflows triggered by this IP address.
    </ParamField>

    <ParamField body="flowControlKey" type="string" optional>
      Cancel workflows with this flow control key.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="count" type="number" optional>
  Maximum number of workflow runs to cancel per call. Defaults to `100`.
</ParamField>

### Cancel all

<ParamField body="all" type="boolean">
  Set to `true` to cancel all pending and active workflow runs.
</ParamField>

## Response

<ResponseField name="cancelled" type="number">
  The number of workflow runs that were cancelled.
</ResponseField>

## Usage

### Cancel by ID

```ts theme={"system"}
// cancel a single workflow
await client.cancel("<WORKFLOW_RUN_ID>");

// cancel a set of workflow runs
await client.cancel(["<WORKFLOW_RUN_ID_1>", "<WORKFLOW_RUN_ID_2>"]);
```

### Cancel with URL filter

Cancel all workflow runs on a specific endpoint using a URL prefix:

```ts theme={"system"}
await client.cancel({
  filter: { workflowUrlStartingWith: "https://your-endpoint.com" }
});
```

For an exact URL match:

```ts theme={"system"}
await client.cancel({
  filter: { workflowUrl: "https://your-endpoint.com/api/workflow" }
});
```

### Cancel with filters

You can combine multiple filter parameters:

```ts theme={"system"}
// cancel by label
await client.cancel({ filter: { label: "my-label" } });

// cancel by label and date range
await client.cancel({
  filter: {
    label: "my-label",
    fromDate: 1640995200000,
  }
});

// cancel by URL and date range
await client.cancel({
  filter: {
    workflowUrl: "https://your-endpoint.com/api/workflow",
    fromDate: new Date("2024-01-01"),
    toDate: new Date("2024-06-01"),
  }
});
```

### Cancel *all* workflows

```ts theme={"system"}
let cancelled: number;
do {
  const result = await client.cancel({ all: true });
  cancelled = result.cancelled;
} while (cancelled > 0);
```
