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

# Cancel a Run

> Stop an in-progress generation run

Stop an in-progress generation run. This stops the AI agents from doing any further work on the run.

Requires the **Workflow: Full** permission in the workflow's workspace.

<Note>
  Work already applied to the workflow is kept. Cancelling stops future work — it doesn't roll anything back.
</Note>

## Path Parameters

<ParamField path="workflowId" type="string" required>
  The ID of the workflow whose run you want to cancel. This is the `workflowId` returned from [Generate a Workflow](/api-reference/workflow-generation/generate-headless).
</ParamField>

## Body Parameters

<ParamField body="runId" type="string">
  The specific run to cancel. Defaults to the workflow's active run.
</ParamField>

## Response

<ResponseField name="cancelled" type="boolean" required>
  Whether the run was successfully cancelled.
</ResponseField>

<ResponseField name="run_id" type="string" required>
  The ID of the cancelled run.
</ResponseField>

<ResponseField name="workflow_id" type="string" required>
  The workflow ID.
</ResponseField>

## Errors

<ResponseField name="400" type="Bad Request">
  `workflowId` is not a valid UUID, or `runId` is present but malformed.
</ResponseField>

<ResponseField name="401" type="Unauthorized">
  Missing, invalid, or expired API key, or the key's user is no longer a member of the organization.
</ResponseField>

<ResponseField name="403" type="Forbidden">
  The user does not have access to this workflow, or lacks the **Workflow: Full** permission in its workspace.
</ResponseField>

<ResponseField name="404" type="Not Found">
  No active room or run for this workflow.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://operator.opus.com/api/v1/workflow/{YOUR_WORKFLOW_ID}/run/cancel \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer {YOUR_API_KEY}' \
    --data '{
      "runId": "{YOUR_RUN_ID}"
    }'
  ```

  ```python Python theme={null}
  import requests

  workflow_id = "{YOUR_WORKFLOW_ID}"
  url = f"https://operator.opus.com/api/v1/workflow/{workflow_id}/run/cancel"
  headers = {
      "Content-Type": "application/json",
      "Authorization": "Bearer {YOUR_API_KEY}"
  }
  payload = {"runId": "{YOUR_RUN_ID}"}  # optional — defaults to the active run

  response = requests.post(url, json=payload, headers=headers)
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const workflowId = "{YOUR_WORKFLOW_ID}";
  const response = await fetch(
    `https://operator.opus.com/api/v1/workflow/${workflowId}/run/cancel`,
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer {YOUR_API_KEY}",
      },
      body: JSON.stringify({
        runId: "{YOUR_RUN_ID}",
      }),
    }
  );

  const data = await response.json();
  console.log(data);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Response theme={null}
  {
    "cancelled": true,
    "run_id": "{RUN_ID}",
    "workflow_id": "{WORKFLOW_ID}"
  }
  ```
</ResponseExample>
