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

# Cancel Run

> Cancels a digital employee run that is in progress or waiting for approval.

### **Code Examples**

```http cURL theme={null}
curl --request POST \
  --url 'https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'x-workspace-id: YOUR_WORKSPACE_ID'
```

```json Node.js theme={null}
const axios = require('axios');

const config = {
  method: 'post',
  url: 'https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'x-workspace-id': 'YOUR_WORKSPACE_ID'
  }
};

try {
  const response = await axios(config);
  console.log(response.data);
} catch (error) {
  console.error(error);
}
```

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

url = "https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "x-workspace-id": "YOUR_WORKSPACE_ID"
}

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

```php PHP theme={null}
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer YOUR_API_KEY",
    "x-workspace-id: YOUR_WORKSPACE_ID"
  ]
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

```java Java theme={null}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel"))
    .header("Authorization", "Bearer YOUR_API_KEY")
    .header("x-workspace-id", "YOUR_WORKSPACE_ID")
    .POST(HttpRequest.BodyPublishers.noBody())
    .build();

HttpResponse<String> response = client.send(request,
    HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

```go Go theme={null}
package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func main() {
    client := &http.Client{}
    req, _ := http.NewRequest("POST", "https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel", nil)
    req.Header.Add("Authorization", "Bearer YOUR_API_KEY")
    req.Header.Add("x-workspace-id", "YOUR_WORKSPACE_ID")
    resp, _ := client.Do(req)
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}
```

```jsonnet .NET theme={null}
using System.Net.Http;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
client.DefaultRequestHeaders.Add("x-workspace-id", "YOUR_WORKSPACE_ID");
var response = await client.PostAsync(
    "https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel",
    null);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

```ruby Ruby theme={null}
require 'uri'
require 'net/http'

uri = URI('https://api.tess.im/digital-employees/{employeeId}/runs/{runId}/cancel')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_KEY'
request['x-workspace-id'] = 'YOUR_WORKSPACE_ID'

response = http.request(request)
puts response.read_body
```

### **Headers**

> [!NOTE]
>
> **Authorization:** Pass your API key as a Bearer token in the `Authorization` header: `Authorization: Bearer YOUR_API_KEY`.

**x-workspace-id** `integer` *required*

ID of the workspace. Required for all Digital Employees API requests.

### **Path Parameters**

**employeeId** `integer` *required*

The ID of the digital employee.

**runId** `integer` *required*

The ID of the run to cancel. The run must be `running` or `awaiting_approval`.

This cancels the run immediately. The stored status becomes `failed`, and `error_message` is `Cancelled by user.`. The employee is no longer marked as running, so another run can start. The caller must be allowed to invoke autopilots and must be the employee owner, the workspace owner, or someone with permission to manage digital employees.

### **Response**

```json theme={null}
{
  "message": "Run cancelled.",
  "data": {
    "run": {
      "id": 501,
      "digital_employee_id": 123,
      "status": "failed",
      "wake_reason": "heartbeat",
      "execution_id": 9001,
      "started_at": "2026-11-23T14:00:00Z",
      "finished_at": "2026-11-23T14:12:00Z",
      "duration_ms": 720000,
      "error_message": "Cancelled by user."
    }
  }
}
```

### **Errors**

| Status | Description |
| :- | :- |
| `403` | You cannot invoke autopilots, or you cannot cancel this run. |
| `404` | The run does not exist for this employee in this workspace. |
| `409` | The run is not `running` or `awaiting_approval`. The body includes `message` `This run is not in a cancellable state.` and `data.run` with `id`, `status`, and `finished_at`. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.