> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runtype.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runtype.com/_mcp/server.

# Cancel a delegate task

POST https://api.runtype.com/v1/delegate-tasks/{id}/cancel

Stop the task after its current tool round. API keys need `DELEGATE_TASKS:WRITE`.

Reference: https://docs.runtype.com/api-reference/runtype-api/delegate-tasks/cancel-a-delegate-task

## Authentication

- `Authorization` header (bearer token, required) — API key or Clerk session token

## Servers

- `https://api.runtype.com` (Production, default)
- `https://api.runtype-staging.com` (Staging)

## Request

### Path parameters

- `id` (string, required) — The task id (`dlg_…`).

## Response

### 202

Cancellation requested

- `accepted` (boolean, required)
- `task` (V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTask, required)

## Errors

### 401 Unauthorized Error

Unauthorized

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 403 Forbidden Error

Missing API key scope

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 404 Not Found Error

Feature disabled, or no such task in this organization

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 409 Conflict Error

The task has already settled

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 503 Service Unavailable Error

The operator agent is not available on this deployment

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

## Types

### V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTask

- `apiKeyId` (string, required, nullable)
- `clientName` (string, required, nullable)
- `clientVersion` (string, required, nullable)
- `completedAt` (string, required, nullable)
- `createdAt` (string, required)
- `error` (string, required, nullable)
- `id` (string, required)
- `instruction` (string, required)
- `lastEventSeq` (integer, required)
- `modelRoundCount` (integer, required)
- `organizationId` (string, required)
- `question` (string, required, nullable)
- `result` (V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskResult, required, nullable)
- `startedAt` (string, required, nullable)
- `status` (enum, required)
  - Allowed values: `queued`, `running`, `input_required`, `completed`, `failed`, `cancelled`
- `summary` (string, required, nullable)
- `toolCallCount` (integer, required)
- `totalCost` (double, required, nullable)
- `touchedEntities` (list of V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskTouchedEntitiesItems, required)
- `updatedAt` (string, required)
- `userId` (string, required)
- `context` (any, optional)

### ErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

### V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskResult

- `links` (list of V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskResultLinksItems, required)
- `modelRoundCount` (integer, required)
- `summary` (string, required)
- `toolCallCount` (integer, required)
- `touchedEntities` (list of V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskResultTouchedEntitiesItems, required)
- `totalCost` (double, optional)
- `warnings` (list of string, optional)

### V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskTouchedEntitiesItems

- `action` (enum, required)
  - Allowed values: `created`, `updated`, `deleted`, `executed`, `read`
- `id` (string, required)
- `kind` (string, required)
- `name` (string, optional)

### V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskResultLinksItems

- `label` (string, required)
- `url` (string, required)

### V1DelegateTasksIdCancelPostResponsesContentApplicationJsonSchemaTaskResultTouchedEntitiesItems

- `action` (enum, required)
  - Allowed values: `created`, `updated`, `deleted`, `executed`, `read`
- `id` (string, required)
- `kind` (string, required)
- `name` (string, optional)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "accepted": true,
  "task": {
    "apiKeyId": "key_01jh1234567890abcdef000001",
    "clientName": "runtype-sdk-python",
    "clientVersion": "1.4.2",
    "completedAt": null,
    "createdAt": "2025-01-15T10:22:00Z",
    "error": null,
    "id": "dlg_01jh0000000000000000000000",
    "instruction": "Analyze the latest sales report and generate a summary with key insights",
    "lastEventSeq": 14,
    "modelRoundCount": 3,
    "organizationId": "org_01jh9876543210abcdef000001",
    "question": null,
    "result": {
      "links": [
        {
          "label": "Sales Report Q4 2024",
          "url": "https://app.runtype.com/reports/sales-q4-2024"
        }
      ],
      "modelRoundCount": 3,
      "summary": "Task was cancelled after 3 model rounds. Partial analysis completed before cancellation.",
      "toolCallCount": 7,
      "touchedEntities": [
        {
          "action": "read",
          "id": "report_01jh1111111111111111111111",
          "kind": "Report",
          "name": "Sales Report Q4 2024"
        }
      ],
      "totalCost": 0.0342,
      "warnings": [
        "Task was cancelled before completion; results may be incomplete."
      ]
    },
    "startedAt": "2025-01-15T10:22:05Z",
    "status": "cancelled",
    "summary": "Partial sales analysis completed before cancellation was requested.",
    "toolCallCount": 7,
    "totalCost": 0.0342,
    "touchedEntities": [
      {
        "action": "read",
        "id": "report_01jh1111111111111111111111",
        "kind": "Report",
        "name": "Sales Report Q4 2024"
      }
    ],
    "updatedAt": "2025-01-15T10:23:47Z",
    "userId": "usr_01jh5555555555555555555555"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel"

payload = {}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"

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

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/delegate-tasks/dlg_01jh0000000000000000000000/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```